3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.navigation
.handler
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.IHandler
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.jface
.viewers
.TreeSelection
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.IEditorReference
;
25 import org
.eclipse
.ui
.IWorkbenchPage
;
26 import org
.eclipse
.ui
.PartInitException
;
27 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
31 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigator
;
34 import eu
.etaxonomy
.taxeditor
.operations
.DeleteTaxonNodeOperation
;
35 import eu
.etaxonomy
.taxeditor
.operations
.DeleteTaxonomicTreeOperation
;
42 public class DeleteTaxonNodeHandler
extends AbstractHandler
implements IHandler
{
43 private static final Logger logger
= Logger
44 .getLogger(DeleteTaxonNodeHandler
.class);
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
48 TaxonNavigator taxonNavigator
;
50 taxonNavigator
= (TaxonNavigator
) NavigationUtil
.getView(TaxonNavigator
.ID
);
51 } catch (PartInitException e
) {
53 throw new RuntimeException(e
);
56 // TODO handle delete on multiple nodes
58 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
59 Object treeOrNode
= selection
.getFirstElement();
61 IUndoableOperation operation
= null;
63 if(treeOrNode
instanceof TaxonomicTree
){
64 operation
= new DeleteTaxonomicTreeOperation(event
.getCommand().getName(),
65 NavigationUtil
.getUndoContext(), (TaxonomicTree
) treeOrNode
, taxonNavigator
, taxonNavigator
);
66 }else if(treeOrNode
instanceof TaxonNode
){
68 operation
= new DeleteTaxonNodeOperation(event
.getCommand().getName(),
69 NavigationUtil
.getUndoContext(), (TaxonNode
) treeOrNode
, taxonNavigator
, taxonNavigator
);
72 IStatus status
= NavigationUtil
.executeOperation(operation
);
74 // Close any open taxon node editors
75 if (status
== Status
.OK_STATUS
&& treeOrNode
instanceof TaxonNode
) {
76 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
77 for (IEditorReference ref
: activePage
.getEditorReferences()) {
79 IEditorInput input
= ref
.getEditorInput();
80 if (input
instanceof TaxonEditorInput
) {
81 TaxonNode node
= ((TaxonEditorInput
) input
).getTaxonNode();
82 if (treeOrNode
.equals(node
)) {
83 activePage
.closeEditor(ref
.getEditor(false), false);
86 } catch (PartInitException e
) {
91 } catch (NotDefinedException e
) {
92 logger
.warn("Command name not set");