1
|
package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
|
2
|
|
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;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
14
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
15
|
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
|
16
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
|
17
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
|
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.AbstractUtility;
|
21
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
22
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
23
|
|
24
|
/**
|
25
|
* Handler responsible for creating sibling nodes of Polytomous Key Nodes
|
26
|
* @author c.mathew
|
27
|
*
|
28
|
*/
|
29
|
|
30
|
public class CreateSiblingNodeHandler extends AbstractHandler {
|
31
|
|
32
|
/*
|
33
|
* (non-Javadoc)
|
34
|
*
|
35
|
* @see
|
36
|
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
|
37
|
* ExecutionEvent)
|
38
|
*/
|
39
|
@Override
|
40
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
41
|
|
42
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
43
|
|
44
|
if (editor instanceof KeyEditor) {
|
45
|
IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
|
46
|
.getActiveEditor();
|
47
|
|
48
|
if (editorPage instanceof PolytomousKeyListEditor) {
|
49
|
|
50
|
IStructuredSelection selection = (IStructuredSelection) HandlerUtil
|
51
|
.getCurrentSelection(event);
|
52
|
|
53
|
if (selection.getFirstElement() instanceof PolytomousKeyNode) {
|
54
|
try {
|
55
|
String label = event.getCommand().getName();
|
56
|
IUndoContext undoContext = EditorUtil.getUndoContext();
|
57
|
|
58
|
PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
|
59
|
.getFirstElement();
|
60
|
|
61
|
AbstractPostOperation operation = new CreateNodeOperation(
|
62
|
label, undoContext, keyNode.getParent(), editorPage);
|
63
|
} catch (NotDefinedException e) {
|
64
|
MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
|
65
|
}
|
66
|
} else {
|
67
|
MessageDialog.openInformation(
|
68
|
AbstractUtility.getShell(),
|
69
|
PolytomousKeyEditorLabels.NO_KEY_NODE_SELECTED,
|
70
|
PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_INSERT_NODE_SELECTED_MESSAGE
|
71
|
);
|
72
|
}
|
73
|
}
|
74
|
}
|
75
|
|
76
|
return null;
|
77
|
}
|
78
|
|
79
|
}
|
80
|
|