Finalizing PolytomousKeyListEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / handler / DeleteNodeHandler.java
index f67fdbb092c3d94ea1e8b50b35993e66230800b1..2926c7d1adbbe904c7c3d1dc98923905d9d5f298 100644 (file)
@@ -1,18 +1,30 @@
 // $Id$
 /**
-* Copyright (C) 2007 EDIT
-* 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.
-*/
+ * Copyright (C) 2007 EDIT
+ * 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.
+ */
 
 package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
 
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.DeleteNodeOperation;
+import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 
 /**
  * @author n.hoffmann
@@ -21,12 +33,42 @@ import org.eclipse.core.commands.ExecutionException;
  */
 public class DeleteNodeHandler extends AbstractHandler {
 
-       /* (non-Javadoc)
-        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
+        * ExecutionEvent)
         */
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               // TODO Auto-generated method stub
+               IEditorPart editor = HandlerUtil.getActiveEditor(event);
+
+               if (editor instanceof KeyEditor) {
+                       IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+                                       .getActiveEditor();
+
+                       IStructuredSelection selection = (IStructuredSelection) HandlerUtil
+                                       .getActiveMenuSelection(event);
+
+                       if (selection.getFirstElement() instanceof PolytomousKeyNode) {
+                               try {
+                                       String label = event.getCommand().getName();
+                                       IUndoContext undoContext = EditorUtil.getUndoContext();
+
+                                       PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
+                                                       .getFirstElement();
+
+                                       AbstractPostOperation operation = new DeleteNodeOperation(
+                                                       label, undoContext, keyNode, editorPage);
+                                       EditorUtil.executeOperation(operation);
+                               } catch (NotDefinedException e) {
+                                       EditorUtil.warn(getClass(), "Command name not set.");
+                               }
+
+                       }
+               }
+
                return null;
        }