all polytomouskey related handler are now extended from RemotingCdmHandler
authorKatja Luther <k.luther@bgbm.org>
Thu, 24 Nov 2016 08:52:40 +0000 (09:52 +0100)
committerKatja Luther <k.luther@bgbm.org>
Thu, 24 Nov 2016 08:52:40 +0000 (09:52 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyEditorLabels.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/AbstractPolytomousKeyNodeHandler.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/DeleteNodeHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/InsertNewNodeHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/RemotingCreateChildPolytomousKeyNodeHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/RemotingCreateSiblingPolytomousKeyNodeHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/InsertPolytomousKeyNodeOperation.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/RemotingCreatePolytomousKeyNodeOperation.java

index 1a7036b7e625d6a8c5c4c20d4bbcbb41b9bc87bb..74b47bf18625d8b516fa56df0bd86b56dfae7586 100644 (file)
@@ -19,6 +19,7 @@ public interface PolytomousKeyEditorLabels {
     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.";
index 91680a0c85800ab8756e74ec461155494103dadd..8dcc87f8cf4002be16902a83686079ec249c7b17 100644 (file)
@@ -344,7 +344,7 @@ public class PolytomousKeyListEditor extends EditorPart implements
         }
 
         viewer.refresh();
-        viewer.setSelection(new StructuredSelection(element));
+
        }
 
     /* (non-Javadoc)
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/AbstractPolytomousKeyNodeHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/AbstractPolytomousKeyNodeHandler.java
new file mode 100755 (executable)
index 0000000..4fa94a0
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+* 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
+    }
+
+
+
+
+}
index 4fc42da010535d14387ff4b3c0c0812b3b5c9ac7..2e5e72fff281c56b2e96991487b3ce64d18389ba 100644 (file)
@@ -1,47 +1,64 @@
 // $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)
@@ -73,7 +90,7 @@ public class DeleteNodeHandler extends AbstractHandler {
 
                                        for (Object element : selection.toArray()) {
                                                PolytomousKeyNode keyNode = HibernateProxyHelper.deproxy(element, PolytomousKeyNode.class);
-                                               
+
                                                AbstractPostOperation operation = new DeleteNodeOperation(
                                                                label, undoContext, keyNode, editorPage);
                                                EditorUtil.executeOperation(operation);
@@ -86,11 +103,62 @@ public class DeleteNodeHandler extends AbstractHandler {
                        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
+
+    }
+
 }
index 67328f06aac8ec910ab248b859c4a63d5cf0a495..62fce56baa3866eabbc9ecb1b554e8087daa520e 100755 (executable)
@@ -23,17 +23,17 @@ 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.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);
     }
@@ -47,7 +47,7 @@ public class InsertNewNodeHandler extends RemotingCdmHandler{
         IEditorPart editor = HandlerUtil.getActiveEditor(event);
 
         if (editor instanceof KeyEditor) {
-            IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+            editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
                     .getActiveEditor();
 
             if (editorPage instanceof PolytomousKeyListEditor) {
@@ -76,7 +76,7 @@ public class InsertNewNodeHandler extends RemotingCdmHandler{
      */
     @Override
     public AbstractOperation prepareOperation(ExecutionEvent event) {
-        return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
+        return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
     }
 
     /**
index 2746a7f77207fe38328aeadd4304dfe2090e1295..a182ce650677c745e1caba17700648c937a075f6 100644 (file)
@@ -24,16 +24,17 @@ 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.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);
@@ -46,7 +47,7 @@ public class RemotingCreateChildPolytomousKeyNodeHandler extends RemotingCdmHand
         IEditorPart editor = HandlerUtil.getActiveEditor(event);
 
         if (editor instanceof KeyEditor) {
-            IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+            editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
                     .getActiveEditor();
 
             if (editorPage instanceof PolytomousKeyListEditor) {
@@ -75,7 +76,7 @@ public class RemotingCreateChildPolytomousKeyNodeHandler extends RemotingCdmHand
      */
     @Override
     public AbstractOperation prepareOperation(ExecutionEvent event) {
-        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
+        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
     }
 
     /* (non-Javadoc)
index 7f726a8cb50d3684ce9aab52e442d6c98e461515..0cb48e65116bfb66e73570e729b4c1baf0dd4e38 100644 (file)
@@ -14,22 +14,25 @@ import org.eclipse.core.commands.operations.AbstractOperation;
 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);
     }
@@ -38,9 +41,10 @@ public class RemotingCreateSiblingPolytomousKeyNodeHandler extends RemotingCdmHa
      */
     @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 {
@@ -57,7 +61,7 @@ public class RemotingCreateSiblingPolytomousKeyNodeHandler extends RemotingCdmHa
      */
     @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)
index 684d8eebd7ea30f60d6c3356ae05b1d9ebb62371..e4a406696629e64b63e13891af174446c06b3478 100644 (file)
@@ -16,7 +16,7 @@ import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
 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;
 
@@ -24,14 +24,15 @@ 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();
        }
@@ -63,7 +64,7 @@ public class DeleteNodeOperation extends AbstractPostTaxonOperation {
                } else{
                        result = service.delete(node.getUuid(), true);
                }
-               
+
                if (!result.isOk() || result.getExceptions().size() > 0){
                        Exception t = new Exception();
                        if (result.getExceptions().size() >1){
index e2e00c2873b6e29a8ffb3a9bab1a1d42bc5920eb..5a95d4ef44a40ce7873baf671ef58c52b584338b 100755 (executable)
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 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;
 
 /**
@@ -30,6 +31,11 @@ public class InsertPolytomousKeyNodeOperation extends RemotingCdmDefaultOperatio
 
     private final static String LABEL = "Insert new polytomous key node";
 
+    /**
+    *
+    */
+   protected IPostOperationEnabled postOperationEnabled;
+
     /**
      * @param label
      * @param action
@@ -38,9 +44,10 @@ public class InsertPolytomousKeyNodeOperation extends RemotingCdmDefaultOperatio
      */
     public InsertPolytomousKeyNodeOperation(Object source,
             boolean async,
-            PolytomousKeyNode parentNode) {
+            PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled) {
         super(LABEL, Action.Create, source, async);
         this.parentNode = parentNode;
+        this.postOperationEnabled = postOperationEnabled;
     }
 
     /**
@@ -58,7 +65,7 @@ public class InsertPolytomousKeyNodeOperation extends RemotingCdmDefaultOperatio
         for (PolytomousKeyNode node: copy){
            childNode.addChild(node);
         }
-
+        this.postOperationEnabled.postOperation(childNode);
         return childNode;
     }
 
index 4674f28c0b53308655c5fffb1e73a7643540ba3a..57a44bd9cc7e0d24885f2966398709f4fc5560d0 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 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;
 
 /**
@@ -26,6 +27,10 @@ public class RemotingCreatePolytomousKeyNodeOperation extends RemotingCdmDefault
 
     private final PolytomousKeyNode parentNode;
     private PolytomousKeyNode childNode;
+    /**
+    *
+    */
+   protected IPostOperationEnabled postOperationEnabled;
 
     public PolytomousKeyNode getChildNode() {
         return childNode;
@@ -35,9 +40,10 @@ public class RemotingCreatePolytomousKeyNodeOperation extends RemotingCdmDefault
 
     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)
@@ -47,7 +53,16 @@ public class RemotingCreatePolytomousKeyNodeOperation extends RemotingCdmDefault
     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;
+      }
     }
 
+
+
+
+
+
 }