1 package eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.handler
;
3 import org
.eclipse
.core
.commands
.AbstractHandler
;
4 import org
.eclipse
.core
.commands
.ExecutionEvent
;
5 import org
.eclipse
.core
.commands
.ExecutionException
;
6 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
7 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
8 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
9 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
10 import org
.eclipse
.ui
.IEditorPart
;
11 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
13 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
14 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
15 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
16 import eu
.etaxonomy
.taxeditor
.editor
.key
.KeyEditor
;
17 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.IPolytomousKeyEditorPage
;
18 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
19 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.operation
.CreateNodeOperation
;
20 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
21 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
24 * Handler responsible for creating sibling nodes of Polytomous Key Nodes
29 public class CreateSiblingNodeHandler
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
) {
49 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
50 .getCurrentSelection(event
);
52 if (selection
.getFirstElement() instanceof PolytomousKeyNode
) {
54 String label
= event
.getCommand().getName();
55 IUndoContext undoContext
= EditorUtil
.getUndoContext();
57 PolytomousKeyNode keyNode
= (PolytomousKeyNode
) selection
60 AbstractPostOperation operation
= new CreateNodeOperation(
61 label
, undoContext
, keyNode
.getParent(), editorPage
);
62 EditorUtil
.executeOperation(operation
);
63 } catch (NotDefinedException e
) {
64 MessagingUtils
.warn(getClass(), "Command name not set.");
67 MessageDialog
.openInformation(
68 EditorUtil
.getShell(),
69 "No Key Node Selected",
70 "Please right-click on a specific key node to create a new sibling key node.");