import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
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.PolytomousKeyListEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.CreateNodeOperation;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- IEditorPart editor = HandlerUtil.getActiveEditor(event);
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
- if (editor instanceof KeyEditor) {
- IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
- .getActiveEditor();
+ if (editor instanceof KeyEditor) {
+ IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+ .getActiveEditor();
- IStructuredSelection selection = (IStructuredSelection) HandlerUtil
- .getCurrentSelection(event);
+ if (editorPage instanceof PolytomousKeyListEditor) {
+ PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
+ if(klEditor.getTableItemCount() == 0) {
+ PolytomousKey pk = (PolytomousKey)klEditor.getViewerInputKey();
+ try {
+ String label = event.getCommand().getName();
+ IUndoContext undoContext = EditorUtil.getUndoContext();
- if (selection.getFirstElement() instanceof PolytomousKeyNode) {
- try {
- String label = event.getCommand().getName();
- IUndoContext undoContext = EditorUtil.getUndoContext();
- PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
- .getFirstElement();
+ AbstractPostOperation operation = new CreateNodeOperation(
+ label, undoContext, pk.getRoot(), editorPage);
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ EditorUtil.warn(getClass(), "Command name not set.");
+ }
+ } else {
- AbstractPostOperation operation = new CreateNodeOperation(
- label, undoContext, keyNode, editorPage);
- EditorUtil.executeOperation(operation);
- } catch (NotDefinedException e) {
- EditorUtil.warn(getClass(), "Command name not set.");
- }
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil
+ .getCurrentSelection(event);
- }
- }
+ if (selection.getFirstElement() instanceof PolytomousKeyNode) {
+ try {
+ String label = event.getCommand().getName();
+ IUndoContext undoContext = EditorUtil.getUndoContext();
+
+ PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
+ .getFirstElement();
+
+ AbstractPostOperation operation = new CreateNodeOperation(
+ label, undoContext, keyNode, editorPage);
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ EditorUtil.warn(getClass(), "Command name not set.");
+ }
+ } else {
+ MessageDialog.openInformation(
+ EditorUtil.getShell(),
+ "No Key Node Selected",
+ "Please right-click on a specific key node to create a new child key node.");
+ }
+ }
+ }
+ }
return null;
}