From ca4feec7234467e4545ca6c3ec8372f13c99b5bf Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Thu, 21 Jan 2010 13:19:25 +0000 Subject: [PATCH] Fixes #1412 --- taxeditor-editor/plugin.xml | 786 +++++++++--------- .../taxeditor/editor/EditorUtil.java | 16 +- .../handler/DeleteHandler.java | 57 +- .../name/handler/DeleteTaxonBaseHandler.java | 14 +- .../handler/DeleteTaxonNodeHandler.java | 1 - 5 files changed, 450 insertions(+), 424 deletions(-) diff --git a/taxeditor-editor/plugin.xml b/taxeditor-editor/plugin.xml index 88b743a04..72a626e69 100644 --- a/taxeditor-editor/plugin.xml +++ b/taxeditor-editor/plugin.xml @@ -10,6 +10,16 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -274,50 +543,6 @@ style="push"> - - - - - - - - - - - - - - - - - - - @@ -376,93 +601,6 @@ name="Save All"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -551,243 +689,100 @@ defaultHandler="eu.etaxonomy.taxeditor.editor.name.handler.RemoveBasionymHandler" id="eu.etaxonomy.taxeditor.editor.name.removeBasionym" name="Remove Basionym / Original Combination"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + point="org.eclipse.core.expressions.definitions"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + variable="selection"> - - - - - - - - - - - - - diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java index 7221836b0..03627cf63 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java @@ -16,6 +16,7 @@ import java.util.UUID; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -23,8 +24,8 @@ import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; -import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.model.AbstractUtility; /** @@ -159,6 +160,19 @@ public class EditorUtil extends AbstractUtility{ return editor.getPage(page); } + + /** + * Returns the selection of the currently active taxon editor + * + * @return + */ + public static ISelection getCurrentSelection(){ + if(getActiveEditor() == null){ + return null; + }else{ + return getActiveEditor().getSite().getSelectionProvider().getSelection(); + } + } public static IUndoContext getUndoContext(MultiPageTaxonEditor editor){ return editor.getUndoContext(); diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteHandler.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteHandler.java index 6aade5e9a..2c0181eef 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteHandler.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteHandler.java @@ -48,43 +48,56 @@ public class DeleteHandler extends AbstractHandler { */ public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); + if (editor instanceof FormEditor) { editor = ((FormEditor) editor).getActiveEditor(); } + IEditorInput input = editor.getEditorInput(); + if (input instanceof TaxonEditorInput) { Taxon taxon = ((TaxonEditorInput) input).getTaxon(); - ISelection selection = HandlerUtil.getCurrentSelection(event); + + ISelection selection = EditorUtil.getCurrentSelection(); Object deleteElement = ((TreeSelection) selection).getFirstElement(); IUndoableOperation operation = null; + String commandName = null; + try { + commandName = event.getCommand().getName(); + } catch (NotDefinedException e) { + logger.error(e); + throw new RuntimeException(e); + } + + // TODO use undo context specific to editor + if (deleteElement instanceof DescriptionElementBase) { + DescriptionElementBase descriptionElement = (DescriptionElementBase) deleteElement; - if (deleteElement instanceof DescriptionElementBase) { - DescriptionElementBase descriptionElement = (DescriptionElementBase) deleteElement; - // TODO use undo context specific to editor - operation = new DeleteDescriptionElementOperation(event.getCommand().getName(), - EditorUtil.getUndoContext(), taxon, descriptionElement, (IPostOperationEnabled) editor); - }else if (deleteElement instanceof ImageFile) { - ImageFile imageFile = (ImageFile) deleteElement; - TreePath[] paths = ((TreeSelection) selection).getPaths(); - TaxonDescription description = (TaxonDescription) (paths[0]).getFirstSegment(); - operation = new DeleteImageOperation(event.getCommand().getName(), - EditorUtil.getUndoContext(), taxon, description, imageFile, (IPostOperationEnabled) editor); - }else if(deleteElement instanceof TaxonDescription){ - - TaxonDescription description = (TaxonDescription) deleteElement; - // TODO use undo context specific to editor - operation = new DeleteTaxonDescriptionOperation(event.getCommand().getName(), - EditorUtil.getUndoContext(), taxon, description, (IPostOperationEnabled) editor); - EditorUtil.executeOperation(operation); - } + operation = new DeleteDescriptionElementOperation(commandName, + EditorUtil.getUndoContext(), taxon, descriptionElement, (IPostOperationEnabled) editor); + } + else if (deleteElement instanceof ImageFile) { + ImageFile imageFile = (ImageFile) deleteElement; + TreePath[] paths = ((TreeSelection) selection).getPaths(); + TaxonDescription description = (TaxonDescription) (paths[0]).getFirstSegment(); + operation = new DeleteImageOperation(commandName, + EditorUtil.getUndoContext(), taxon, description, imageFile, (IPostOperationEnabled) editor); + } + else if(deleteElement instanceof TaxonDescription){ + + TaxonDescription description = (TaxonDescription) deleteElement; + + operation = new DeleteTaxonDescriptionOperation(commandName, + EditorUtil.getUndoContext(), taxon, description, (IPostOperationEnabled) editor); EditorUtil.executeOperation(operation); - } catch (NotDefinedException e) { - logger.warn("Command name not set"); } + + EditorUtil.executeOperation(operation); + } return null; } diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java index 6dcc4fa74..f4aa375fe 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java @@ -45,21 +45,23 @@ public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { - TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage( - Page.NAME); - ISelection menuSelection = editor.getSite().getSelectionProvider().getSelection(); + TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME); + ISelection menuSelection = EditorUtil.getCurrentSelection(); TaxonBasePropertySource taxonBasePropertySource = (TaxonBasePropertySource) ((StructuredSelection) menuSelection).getFirstElement(); IUndoableOperation operation = null; String commandName = null; - try{ + + try { commandName = event.getCommand().getName(); - }catch (NotDefinedException e) { - logger.warn("Command name not set"); + } catch (NotDefinedException e) { + logger.error(e); + throw new RuntimeException(e); } + // synonym if(taxonBasePropertySource instanceof SynonymPropertySource){ Synonym synonym = (Synonym) taxonBasePropertySource.getTaxonBase(); diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java index f1387e346..641075e15 100644 --- a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java +++ b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTaxonNodeHandler.java @@ -25,7 +25,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IWorkbenchPage; -- 2.34.1