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