/**
   * Checks, if the deleted node was the current category to map into. <br>
   * If <code>true</code>, set category to "unassigned".
   *
   * @param editor The editor in which the delete occured.
   */
  private void checkCategoryToMapInto(ObjectMappingMultiPageEditor editor) {

    ISelection sel = null;
    IObjectMappingCategoryPO categoryToMapInto = editor.getOmEditorBP().getCategoryToCreateIn();
    if (categoryToMapInto != null) {
      editor.getTreeViewer().setSelection(new StructuredSelection(categoryToMapInto));
      sel = editor.getTreeViewer().getSelection();
    }
    if (sel == null || sel.isEmpty()) {
      editor.getOmEditorBP().setCategoryToCreateIn(null);
      ObjectMappingModeSourceProvider omsp =
          (ObjectMappingModeSourceProvider)
              AbstractJBSourceProvider.getSourceProviderInstance(
                  null, ObjectMappingModeSourceProvider.ID);
      if (editor.getAut().equals(TestExecution.getInstance().getConnectedAut())
          && omsp != null
          && omsp.isRunning()) {
        String message =
            NLS.bind(
                Messages.TestExecutionContributorAUTStartedMapping,
                Messages.TestExecutionContributorCatUnassigned);
        int icon = Constants.MAPPING;
        Plugin.showStatusLine(icon, message);
      }
    }
  }
 /**
  * @param editor The editor containing the viewer to refresh
  * @param newSelection The elemented that should be selected after the refresh.
  */
 private void refreshViewer(ObjectMappingMultiPageEditor editor, Object newSelection) {
   editor.getTreeViewer().refresh();
   if (newSelection != null) {
     checkCategoryToMapInto(editor);
     editor.getTreeViewer().setSelection(new StructuredSelection(newSelection));
   }
 }
 /** {@inheritDoc} */
 public void run(IMarker marker) {
   List<ITestSuitePO> tsList = TestSuiteBP.getListOfTestSuites();
   for (ITestSuitePO ts : tsList) {
     if (ts.getAut().getName().equals(m_autName)) {
       ObjectMappingMultiPageEditor editor =
           (ObjectMappingMultiPageEditor) AbstractOpenHandler.openEditor(ts.getAut());
       editor.getSite().getPage().activate(editor);
       break;
     }
   }
 }
  /** {@inheritDoc} */
  public Object executeImpl(ExecutionEvent event) {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (!(activePart instanceof ObjectMappingMultiPageEditor)) {
      return null;
    }

    final ObjectMappingMultiPageEditor editor = (ObjectMappingMultiPageEditor) activePart;
    editor
        .getEditorHelper()
        .doEditorOperation(
            new IEditorOperation() {
              public void run(IPersistentObject workingPo) {
                IStructuredSelection selection = getSelection();
                Class classType = null;
                for (Object obj : selection.toArray()) {
                  // selectionitems must be same type
                  if (classType == null) {
                    classType = obj.getClass();
                  }
                  if (obj.getClass() != classType) {
                    return;
                  }
                }
                Object lastParent = null;
                if (selection.size() == 1) {
                  lastParent = deleteSingleElement(selection.getFirstElement(), editor);
                } else if (selection.size() > 1) {
                  boolean delete = false;
                  delete =
                      MessageDialog.openConfirm(
                          getActiveShell(),
                          Messages.DeleteTreeItemActionOMEditorOMTitle,
                          Messages.DeleteTreeItemActionOMEditorOMText3);
                  if (delete) {
                    lastParent = deleteMultipleElements(selection.toArray(), editor);
                  }
                }

                if (lastParent != null) {
                  refreshViewer(editor, lastParent);
                }
              }
            });

    return null;
  }
 /**
  * @param toDelete The items to delete.
  * @param editor The editor in which the delete is taking place.
  * @return the parent of one of the given elements before its deletion, or <code>null</code> if no
  *     elements are deleted.
  */
 public static Object deleteMultipleElements(
     Object[] toDelete, ObjectMappingMultiPageEditor editor) {
   IObjectMappingCategoryPO lastParent = null;
   for (Object node : toDelete) {
     if (node instanceof IComponentNamePO) {
       lastParent = editor.getOmEditorBP().deleteCompName((IComponentNamePO) node);
     } else if (node instanceof IObjectMappingAssoziationPO) {
       lastParent = editor.getOmEditorBP().deleteAssociation((IObjectMappingAssoziationPO) node);
     } else if (node instanceof IObjectMappingCategoryPO) {
       if (!willAncestorBeDeleted((IObjectMappingCategoryPO) node, toDelete)) {
         lastParent = editor.getOmEditorBP().deleteCategory((IObjectMappingCategoryPO) node);
       }
     }
   }
   if (toDelete.length > 0) {
     editor.getEditorHelper().setDirty(true);
   }
   return lastParent;
 }
  /**
   * Prompts the user if they really want to delete the given item. If the user consents, the item
   * is deleted. Otherwise, no action is taken.
   *
   * @param toDelete The item to delete.
   * @param editor The editor in which the delete is taking place.
   * @return the parent of the element before its deletion, or <code>null</code> if no element is
   *     deleted.
   */
  private Object deleteSingleElement(Object toDelete, ObjectMappingMultiPageEditor editor) {

    boolean delete = false;
    Object lastParent = null;
    if (toDelete instanceof IObjectMappingAssoziationPO) {
      delete =
          MessageDialog.openConfirm(
              getActiveShell(),
              Messages.DeleteTreeItemActionOMEditorOMTitle,
              Messages.DeleteTreeItemActionOMEditorOMText1);
      if (delete) {
        lastParent =
            editor.getOmEditorBP().deleteAssociation((IObjectMappingAssoziationPO) toDelete);
        editor.getEditorHelper().setDirty(true);
      }
    } else if (toDelete instanceof IComponentNamePO) {
      delete =
          MessageDialog.openConfirm(
              getActiveShell(),
              Messages.DeleteTreeItemActionOMEditorOMTitle,
              Messages.DeleteTreeItemActionOMEditorOMText2);
      if (delete) {
        lastParent = editor.getOmEditorBP().deleteCompName((IComponentNamePO) toDelete);
        editor.getEditorHelper().setDirty(true);
      }
    } else if (toDelete instanceof IObjectMappingCategoryPO) {
      delete =
          MessageDialog.openConfirm(
              getActiveShell(),
              Messages.DeleteTreeItemActionOMEditorOMTitle,
              Messages.DeleteTreeItemActionOMEditorOMText4);
      if (delete) {
        lastParent = editor.getOmEditorBP().deleteCategory((IObjectMappingCategoryPO) toDelete);
        editor.getEditorHelper().setDirty(true);
      }
    }
    return lastParent;
  }