public static final String CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL = "Create Child Polytomous Key Node";
public static final String CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL = "Create Sibling Polytomous Key Node";
public static final String INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL = "Insert Node Polytomous Key Node";
+ public static final String DELETE_NODE_POLYTOMOUS_KEY_NODE_LABEL = "Insert Node Polytomous Key Node";
public static final String NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new child key node.";
public static final String NO_KEY_NODE_FOR_SIBLING_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new sibling key node.";
}
viewer.refresh();
- viewer.setSelection(new StructuredSelection(element));
+
}
/* (non-Javadoc)
--- /dev/null
+/**
+* Copyright (C) 2016 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 eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+
+/**
+ * @author k.luther
+ * @date 24.11.2016
+ *
+ */
+public abstract class AbstractPolytomousKeyNodeHandler extends RemotingCdmHandler {
+
+
+ IPolytomousKeyEditorPage editorPage;
+
+ /**
+ * @param label
+ */
+ public AbstractPolytomousKeyNodeHandler(String label) {
+ super(label);
+ // TODO Auto-generated constructor stub
+ }
+
+
+
+
+}
// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * 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.AbstractOperation;
import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
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.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
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.PolytomousKeyEditorLabels;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.DeleteNodeOperation;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* @author n.hoffmann
* @created Dec 6, 2010
* @version 1.0
*/
-public class DeleteNodeHandler extends AbstractHandler {
+public class DeleteNodeHandler extends AbstractPolytomousKeyNodeHandler {
+
+
+ PolytomousKeyNode nodeToBeDeleted;
+ /**
+ * @param label
+ */
+ public DeleteNodeHandler(String label) {
+ super(label);
+
+ }
+
+
+
+ public DeleteNodeHandler() {
+ super(PolytomousKeyEditorLabels.DELETE_NODE_POLYTOMOUS_KEY_NODE_LABEL);
+ }
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
for (Object element : selection.toArray()) {
PolytomousKeyNode keyNode = HibernateProxyHelper.deproxy(element, PolytomousKeyNode.class);
-
+
AbstractPostOperation operation = new DeleteNodeOperation(
label, undoContext, keyNode, editorPage);
EditorUtil.executeOperation(operation);
MessageDialog.openInformation(
EditorUtil.getShell(),
"No Key Node Selected",
- "Please right-click on a specific key node to delete a key node.");
- }
+ "Please right-click on a specific key node to delete a key node.");
+ }
}
return null;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IStatus allowOperations(ExecutionEvent event) {
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+
+ if (editor instanceof KeyEditor) {
+ editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+ .getActiveEditor();
+
+ if (editorPage instanceof PolytomousKeyListEditor) {
+ PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
+ if (selection.getFirstElement() instanceof PolytomousKeyNode) {
+ nodeToBeDeleted = (PolytomousKeyNode) selection.getFirstElement();
+ } else {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE);
+ }
+ }
+
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public AbstractOperation prepareOperation(ExecutionEvent event) {
+ IUndoContext undoContext = EditorUtil.getUndoContext();
+ String label = "";
+ try {
+ label = event.getCommand().getName();
+ } catch (NotDefinedException e) {
+ MessagingUtils.warn(getClass(), "Command name not set.");
+ }
+ return new DeleteNodeOperation(label, undoContext, nodeToBeDeleted, editorPage);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onComplete() {
+ // TODO Auto-generated method stub
+
+ }
+
}
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.InsertPolytomousKeyNodeOperation;
-import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
/**
* @author k.luther
* @date 17.11.2016
*
*/
-public class InsertNewNodeHandler extends RemotingCdmHandler{
+public class InsertNewNodeHandler extends AbstractPolytomousKeyNodeHandler{
private PolytomousKeyNode parentNode ;
+
public InsertNewNodeHandler() {
super(PolytomousKeyEditorLabels.INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL);
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof KeyEditor) {
- IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+ editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
.getActiveEditor();
if (editorPage instanceof PolytomousKeyListEditor) {
*/
@Override
public AbstractOperation prepareOperation(ExecutionEvent event) {
- return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
+ return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
}
/**
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RemotingCreatePolytomousKeyNodeOperation;
-import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
/**
* @author cmathew
* @date 21 Jul 2015
*
*/
-public class RemotingCreateChildPolytomousKeyNodeHandler extends RemotingCdmHandler {
+public class RemotingCreateChildPolytomousKeyNodeHandler extends AbstractPolytomousKeyNodeHandler {
private PolytomousKeyNode parentNode;
+ IPolytomousKeyEditorPage editorPage;
+
public RemotingCreateChildPolytomousKeyNodeHandler() {
super(PolytomousKeyEditorLabels.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof KeyEditor) {
- IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+ editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
.getActiveEditor();
if (editorPage instanceof PolytomousKeyListEditor) {
*/
@Override
public AbstractOperation prepareOperation(ExecutionEvent event) {
- return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
+ return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
}
/* (non-Javadoc)
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
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.key.KeyEditor;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RemotingCreatePolytomousKeyNodeOperation;
-import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
/**
* @author cmathew
* @date 21 Jul 2015
*
*/
-public class RemotingCreateSiblingPolytomousKeyNodeHandler extends RemotingCdmHandler {
+public class RemotingCreateSiblingPolytomousKeyNodeHandler extends AbstractPolytomousKeyNodeHandler {
private PolytomousKeyNode parentNode;
+
public RemotingCreateSiblingPolytomousKeyNodeHandler() {
super(PolytomousKeyEditorLabels.CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL);
}
*/
@Override
public IStatus allowOperations(ExecutionEvent event) {
-
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
-
+ editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+ .getActiveEditor();
if (selection.getFirstElement() instanceof PolytomousKeyNode) {
parentNode = (PolytomousKeyNode) selection.getFirstElement();
} else {
*/
@Override
public AbstractOperation prepareOperation(ExecutionEvent event) {
- return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode.getParent());
+ return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode.getParent(), editorPage);
}
/* (non-Javadoc)
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
+import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.store.CdmStore;
* @author n.hoffmann
*
*/
-public class DeleteNodeOperation extends AbstractPostTaxonOperation {
+public class DeleteNodeOperation extends AbstractPostOperation<PolytomousKeyNode> {
private final PolytomousKeyNode parent;
private final PolytomousKeyNode node;
+
public DeleteNodeOperation(String label, IUndoContext undoContext,
PolytomousKeyNode node, IPostOperationEnabled postOperationEnabled) {
- super(label, undoContext, postOperationEnabled);
+ super(label, undoContext, node, postOperationEnabled);
this.node = node;
this.parent = node.getParent();
}
} else{
result = service.delete(node.getUuid(), true);
}
-
+
if (!result.isOk() || result.getExceptions().size() > 0){
Exception t = new Exception();
if (result.getExceptions().size() >1){
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.operation.RemotingCdmDefaultOperation;
/**
private final static String LABEL = "Insert new polytomous key node";
+ /**
+ *
+ */
+ protected IPostOperationEnabled postOperationEnabled;
+
/**
* @param label
* @param action
*/
public InsertPolytomousKeyNodeOperation(Object source,
boolean async,
- PolytomousKeyNode parentNode) {
+ PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled) {
super(LABEL, Action.Create, source, async);
this.parentNode = parentNode;
+ this.postOperationEnabled = postOperationEnabled;
}
/**
for (PolytomousKeyNode node: copy){
childNode.addChild(node);
}
-
+ this.postOperationEnabled.postOperation(childNode);
return childNode;
}
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.operation.RemotingCdmDefaultOperation;
/**
private final PolytomousKeyNode parentNode;
private PolytomousKeyNode childNode;
+ /**
+ *
+ */
+ protected IPostOperationEnabled postOperationEnabled;
public PolytomousKeyNode getChildNode() {
return childNode;
public RemotingCreatePolytomousKeyNodeOperation(Object source,
boolean async,
- PolytomousKeyNode parentNode){
+ PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled){
super(LABEL, Action.Create, source, async);
this.parentNode = parentNode;
+ this.postOperationEnabled = postOperationEnabled;
}
/* (non-Javadoc)
protected CdmBase doSimpleExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
childNode = PolytomousKeyNode.NewInstance();
parentNode.addChild(childNode);
- return childNode;
+ if (postOperationEnabled.postOperation(childNode)){
+ return childNode;
+ }else {
+ return null;
+ }
}
+
+
+
+
+
}