4 package eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.handler
;
6 import org
.eclipse
.core
.commands
.AbstractHandler
;
7 import org
.eclipse
.core
.commands
.ExecutionEvent
;
8 import org
.eclipse
.core
.commands
.ExecutionException
;
9 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
10 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
11 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
12 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
13 import org
.eclipse
.ui
.IEditorPart
;
14 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
16 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
17 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
18 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
19 import eu
.etaxonomy
.taxeditor
.editor
.key
.KeyEditor
;
20 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.IPolytomousKeyEditorPage
;
21 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
22 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.operation
.CreateNodeOperation
;
23 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
29 public class CreateChildNodeHandler
extends AbstractHandler
{
35 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
39 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
43 if (editor
instanceof KeyEditor
) {
44 IPolytomousKeyEditorPage editorPage
= (IPolytomousKeyEditorPage
) ((KeyEditor
) editor
)
47 if (editorPage
instanceof PolytomousKeyListEditor
) {
48 PolytomousKeyListEditor klEditor
= (PolytomousKeyListEditor
) editorPage
;
49 if(klEditor
.getTableItemCount() == 0) {
50 PolytomousKey pk
= (PolytomousKey
)klEditor
.getViewerInputKey();
52 String label
= event
.getCommand().getName();
53 IUndoContext undoContext
= EditorUtil
.getUndoContext();
56 AbstractPostOperation operation
= new CreateNodeOperation(
57 label
, undoContext
, pk
.getRoot(), editorPage
);
58 EditorUtil
.executeOperation(operation
);
59 } catch (NotDefinedException e
) {
60 EditorUtil
.warn(getClass(), "Command name not set.");
64 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
65 .getCurrentSelection(event
);
67 if (selection
.getFirstElement() instanceof PolytomousKeyNode
) {
69 String label
= event
.getCommand().getName();
70 IUndoContext undoContext
= EditorUtil
.getUndoContext();
72 PolytomousKeyNode keyNode
= (PolytomousKeyNode
) selection
75 AbstractPostOperation operation
= new CreateNodeOperation(
76 label
, undoContext
, keyNode
, editorPage
);
77 EditorUtil
.executeOperation(operation
);
78 } catch (NotDefinedException e
) {
79 EditorUtil
.warn(getClass(), "Command name not set.");
82 MessageDialog
.openInformation(
83 EditorUtil
.getShell(),
84 "No Key Node Selected",
85 "Please right-click on a specific key node to create a new child key node.");