merged model adaptions to cdmlib 3.2.4 from campanula branch
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / DeleteHandler.java
index 86ed939b6b85cb6cd286eaed0706a8e671025d51..a1a4425b55e1db569150557e442d51257c639d67 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -29,7 +29,7 @@ import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
-import eu.etaxonomy.cdm.model.taxon.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
@@ -50,57 +50,59 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
        private TaxonNavigator taxonNavigator;
 
        /** {@inheritDoc} */
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               
+       @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
                activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
-               
+
                taxonNavigator = NavigationUtil.showNavigator();
-                               
+
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
-               
+
                String plural = selection.size() > 1 ? "s" : "";
                // Prompt user for confirmation
                if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected node" + plural +"?")){
                        return null;
                }
-               
+
                Iterator selectionIterator = selection.iterator();
-               Set<ITreeNode> treeNodes = new HashSet<ITreeNode>();
-               
+               Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
+
                while (selectionIterator.hasNext()){
                        Object object = selectionIterator.next();
-                       if(object instanceof ITreeNode)
-                               treeNodes.add((ITreeNode) object);
+                       if(object instanceof ITaxonTreeNode) {
+                treeNodes.add((ITaxonTreeNode) object);
+            }
                }
-                       
+
                AbstractPostOperation operation = null;
                try {
                        operation = new DeleteOperation(
-                                       event.getCommand().getName(), NavigationUtil.getUndoContext(), 
+                                       event.getCommand().getName(), NavigationUtil.getUndoContext(),
                                        treeNodes, taxonNavigator, taxonNavigator);
-                       
+
                        IStatus status = NavigationUtil.executeOperation(operation);
-                       
-                       
+
+
                        // FIXME is there a better place for this code?
                        if (status == Status.OK_STATUS){
-                               for (ITreeNode treeNode : treeNodes){
+                               for (ITaxonTreeNode treeNode : treeNodes){
                                        if(treeNode instanceof TaxonNode) {
                                                closeObsoleteEditor((TaxonNode) treeNode);
                                        }
                                }
                        }
-               
+
                } catch (NotDefinedException e) {
                        NavigationUtil.warn(getClass(), "Command name not set");
                }
                return null;
        }
-       
+
        private void closeObsoleteEditor(TaxonNode taxonNode){
                for (IEditorReference ref : activePage.getEditorReferences()) {
                        try {
-                               IEditorInput input = ref.getEditorInput(); 
+                               IEditorInput input = ref.getEditorInput();
                                if (input instanceof TaxonEditorInput) {
                                        TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
                                        if (taxonNode.equals(node)) {