public void handleEvent()

in uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/ParameterSection.java [326:483]


  public void handleEvent(Event event) {
    cpd = getAnalysisEngineMetaData().getConfigurationParameterDeclarations();

    if (event.type == SWT.MouseHover) {
      showDescriptionAsToolTip(event);
    } else if (event.widget == usingGroupsButton) {
      if (usingGroupsButton.getSelection()) {
      } else {
        if (Window.CANCEL == Utility.popOkCancel("Confirm Remove Groups",
                "This action will delete any group information that may be present in this descriptor.  Proceed?",
                MessageDialog.WARNING)) {
          usingGroupsButton.setSelection(true);
          return;
        }
        // remove all top level items (groups) except the 1st one,
        // which is NOT_IN_ANY_GROUP
        TreeItem[] items = tree.getItems();
        TreeItem[] removeItems = new TreeItem[items.length - 1];
        System.arraycopy(items, 1, removeItems, 0, removeItems.length);
        removeItems(removeItems, !GIVE_WARNING_MESSAGE);
        cpd.setCommonParameters(AbstractSection.configurationParameterArray0);
        cpd.setConfigurationGroups(AbstractSection.configurationGroupArray0);
      }
      setFileDirty(); // maybe slightly overkill
      refresh();
    } else if (event.widget == searchStrategy) {
      valueChanged = false;
      cpd.setSearchStrategy(setValueChanged(searchStrategy.getText(), cpd.getSearchStrategy()));
      if (valueChanged)
        setFileDirty();
    } else if (event.widget == defaultGroup) {
      valueChanged = false;
      cpd.setDefaultGroupName(setValueChanged(defaultGroup.getText(), cpd.getDefaultGroupName()));
      if (valueChanged)
        setFileDirty();
    } else if (event.widget == addGroupButton) {
      CommonInputDialog dialog = new CommonInputDialog(this, "Add Group",
              "Specify one or more unique group names, separated by 1 space character, and press OK",
              CommonInputDialog.GROUP_NAMES);

      for (;;) { // stay in loop until get "true" return from add below
        // used for looping while group name set is duplicate
        if (dialog.open() == Window.CANCEL)
          return;
        if (addNewOrEditExistingGroup(dialog.getValue(), null))
          break;
      }
      commonActionFinish();
    } else if (event.widget == addButton) { // add parameter or add override action

      boolean valid = tree.getSelectionCount() == 1;
      if (isPrimitive())
        valid = valid && (isGroupSelection() || isParmSelection());
      else
        valid = valid && (isParmSelection() || isOverrideSelection());

      if (!valid) {
        if (isPrimitive())
          Utility.popMessage("Wrong item selected",
                  "Please first select the group under which to add a parameter",
                  MessageDialog.ERROR);
        else
          Utility.popMessage("Wrong item selected",
                  "Please first select the parameter under which to add an override",
                  MessageDialog.ERROR);
        return;
      }

      if (isPrimitive()) { // adding a parameter
        TreeItem parentGroup = tree.getSelection()[0];
        if (isParmSelection())
          parentGroup = parentGroup.getParentItem();

        AddParameterDialog dialog = new AddParameterDialog(this,
                getCorrespondingModelGroup(parentGroup));
        // getName(parentGroup));
        if (dialog.open() == Window.CANCEL)
          return;

        addNewConfigurationParameter(dialog, parentGroup);

        if (null != parentGroup)
          parentGroup.setExpanded(true);
        commonActionFinish();
      } else { // is aggregate - add an override
        TreeItem parentParm = tree.getSelection()[0];
        if (isOverride(parentParm))
          parentParm = parentParm.getParentItem();
        addOrEditOverride(parentParm, -1);
      }
    } else if ((event.widget == editButton) || (event.type == SWT.MouseDoubleClick)) {

      TreeItem editItem = tree.getSelection()[0];
      if (isParameter(editItem) && isPrimitive()) {
        AddParameterDialog dialog = new AddParameterDialog(this,
                getCorrespondingModelParm(editItem));
        if (dialog.open() == Window.CANCEL)
          return;

        // update the existing item
        alterExistingConfigurationParameter(dialog, editItem);
        // TODO consequences of changes in rest of model?
        commonActionFinishDirtyIfChange();
      } else if (isParameter(editItem) && isAggregate()) {
        // can edit name and description, but not Type (set from override)
        ConfigurationParameter existingCP = getCorrespondingModelParm(editItem);

        AddParameterDialog dialog = new AddParameterDialog(this, existingCP);
        if (dialog.open() == Window.CANCEL)
          return;
        alterExistingConfigurationParameter(dialog, editItem);
        // TODO consequences of changes in rest of model?
        commonActionFinishDirtyIfChange();

      } else if (isOverride(editItem)) {
        TreeItem parent = editItem.getParentItem();
        int overrideIndex = getItemIndex(parent, editItem);
        addOrEditOverride(parent, overrideIndex);
      } else if (isGroup(editItem)) {
        String groupNames = getName(editItem.getText());
        if (groupNames.equals(COMMON_GROUP) || groupNames.equals(NOT_IN_ANY_GROUP))
          return; // can't change the name of these groups

        CommonInputDialog dialog = new CommonInputDialog(this, "Edit group",
                "Specify one or more unique group names, separated by 1 space character, and press OK",
                CommonInputDialog.GROUP_NAMES, groupNames);

        for (;;) {
          if (dialog.open() == Window.CANCEL)
            return;

          if (addNewOrEditExistingGroup(dialog.getValue(), editItem))
            break;
        }
        commonActionFinishDirtyIfChange();
      }
    } else if ((event.widget == removeButton)
            || (event.widget == tree && event.type == SWT.KeyUp && event.character == SWT.DEL)) {

      // handle remove - of all selected items
      // if a group is selected, removing the group also removes all the parms in the group
      // Because this is dangerous, we issue an "are you sure?" prompt.

      // Other side effects: Any parameter settings for the removed
      // parameters are also removed.

      valueChanged = removeItems(tree.getSelection(), GIVE_WARNING_MESSAGE);
      commonActionFinishDirtyIfChange();

      // TODO remove settings for any parameters removed
    } // end of remove action

    // handle selection changes
    else if (event.widget == tree && event.type == SWT.Selection) {

    }
    enable();
  }