/** * 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; }
/** {@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; }