smaller changes for drag & dop with natural order in taxonnavigator
authorKatja Luther <k.luther@bgbm.org>
Fri, 22 Apr 2016 09:48:07 +0000 (11:48 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 22 Apr 2016 09:48:07 +0000 (11:48 +0200)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveTaxonNodeHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java

index bdf2eb9..d01a593 100644 (file)
@@ -66,6 +66,10 @@ public class TreeNodeDropAdapter extends ViewerDropAdapter implements IPostOpera
 
        private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
 
+       public enum MovingType{
+           CHILD, PREVIOUS, BEHIND
+       }
+
 
 
        /* (non-Javadoc)
@@ -206,14 +210,14 @@ public class TreeNodeDropAdapter extends ViewerDropAdapter implements IPostOpera
                        }
 
                        AbstractPostOperation operation = new MoveTaxonOperation
-                                       ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
+                                       ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
                        NavigationUtil.executeOperation(operation);
 
                        logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
                        return true;
                }else{
-                       String[] buttonLables = {"Parent", "Predecessor", "Cancel"};
-                       MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
+                       String[] buttonLables = {"Child", "Behind","Cancel"};
+                       MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to move the Taxonnode as child or behind the target node.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
                        dialog.open();
                        int returnCode = dialog.getReturnCode();
                        if (returnCode == 0){
@@ -224,7 +228,7 @@ public class TreeNodeDropAdapter extends ViewerDropAdapter implements IPostOpera
                                }
 
                                AbstractPostOperation operation = new MoveTaxonOperation
-                                               ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
+                                               ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
                                NavigationUtil.executeOperation(operation);
 
                                logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
@@ -238,12 +242,28 @@ public class TreeNodeDropAdapter extends ViewerDropAdapter implements IPostOpera
                                TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
 
                                AbstractPostOperation operation = new MoveTaxonOperation
-                                               ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, false);
+                                               ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
                                NavigationUtil.executeOperation(operation);
 
                                logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
                                return true;
-                       } else{
+                       }
+//                     } else if (returnCode == 2){
+//                IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+//                if (workspaceUndoContext == null) {
+//                    logger.error("Workspace undo context is null. DND operation cancelled");
+//                    return false;
+//                }
+//                TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+//
+//                AbstractPostOperation operation = new MoveTaxonOperation
+//                        ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.BEHIND);
+//                NavigationUtil.executeOperation(operation);
+//
+//                logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+//                return true;
+//            }
+                               else{
                                return false;
                        }
 
index 0f16d0e..33c0be7 100644 (file)
@@ -37,6 +37,7 @@ import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
@@ -198,19 +199,19 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
                        }
 
                        if(CdmStore.getCurrentSessionManager().isRemoting()) {
-                           AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, true);
+                           AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
                            NavigationUtil.executeOperation(operation, null);
                        } else {
                            AbstractPostOperation operation = new MoveTaxonOperation
-                                   ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
+                                   ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
                            NavigationUtil.executeOperation(operation);
             }
 
                        logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
                        return Status.OK_STATUS;
                }else{
-                       String[] buttonLables = {"Parent", "Predecessor", "Cancel"};
-                       MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
+                       String[] buttonLables = {"Child", "Behind", "Cancel"};
+                       MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to move the taxon as child, before or behind the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
                        dialog.open();
                        int returnCode = dialog.getReturnCode();
                        if (returnCode == 0){
@@ -221,11 +222,11 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
                                }
 
                                if(CdmStore.getCurrentSessionManager().isRemoting()) {
-                                   AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, true);
+                                   AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
                                    NavigationUtil.executeOperation(operation, null);
                                } else {
                                    AbstractPostOperation operation = new MoveTaxonOperation
-                                           ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
+                                           ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
                                    NavigationUtil.executeOperation(operation);
                                }
 
@@ -240,16 +241,34 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
                                TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
 
                                if(CdmStore.getCurrentSessionManager().isRemoting()) {
-                                   AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, false);
+                                   AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.BEHIND);
                                    NavigationUtil.executeOperation(operation, null);
                                } else {
                                    AbstractPostOperation operation = new MoveTaxonOperation
-                                           ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, false);
+                                           ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.BEHIND);
                                    NavigationUtil.executeOperation(operation);
                                }
                                logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
                                return Status.OK_STATUS;
-                       } else{
+//                     }else if (returnCode == 2){
+//                IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+//                if (workspaceUndoContext == null) {
+//                    logger.error("Workspace undo context is null. DND operation cancelled");
+//                    return Status.CANCEL_STATUS;
+//                }
+//                TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+//
+//                if(CdmStore.getCurrentSessionManager().isRemoting()) {
+//                    AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.PREVIOUS);
+//                    NavigationUtil.executeOperation(operation, null);
+//                } else {
+//                    AbstractPostOperation operation = new MoveTaxonOperation
+//                            ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
+//                    NavigationUtil.executeOperation(operation);
+//                }
+//                logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+//                return Status.OK_STATUS;
+            } else{
                                return Status.CANCEL_STATUS;
                        }
 
index 9cc52f1..30f7ab5 100644 (file)
@@ -30,6 +30,7 @@ import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@@ -86,10 +87,10 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE
 //             TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
                if (taxonNodes.size() >= 1){
                    Classification classification = taxonNodes.iterator().next().getClassification();
-                       boolean moveToNewParent = true;
+                       MovingType moveToNewParent = MovingType.CHILD;
                        if (PreferencesUtil.getSortNodesNaturally()){
                                if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
-                                       moveToNewParent = false;
+                                       moveToNewParent = MovingType.BEHIND;
                                }
                                parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa, null, classification);
                        }else{
@@ -102,6 +103,7 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE
                                        return null;
                                }
 
+
                                AbstractPostOperation operation = new MoveTaxonOperation
                                                ("Move taxon to new parent", NavigationUtil.getUndoContext(),
                                                                taxonNodeUUIDs, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$
index 3458faa..ac23192 100644 (file)
@@ -26,6 +26,7 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
@@ -87,18 +88,26 @@ public class RemotingMoveTaxonNodeHandler extends RemotingCdmHandler {
         List<UUID> excludeTaxa = new ArrayList<UUID>();
         excludeTaxa.add(oldTaxonNode.getTaxon().getUuid());
 
-        boolean moveToNewParent = true;
+        MovingType moveToNewParent = MovingType.CHILD;
 
         if (PreferencesUtil.getSortNodesNaturally()){
-            if(!MessageDialog.openQuestion(activeShell, "Target node", "Should the choosen target node be the parent of this taxon node?")){
-                moveToNewParent = false;
-            }
+
+
             parentTaxonNode = TaxonNodeSelectionDialog.select(activeShell,
                     new ConversationHolderMock(),
                     "Choose the taxon above the moved taxon.",
                     excludeTaxa,
                     null,
                     oldTaxonNode.getClassification());
+            String[] buttonLables = {"Child", "Behind","Cancel"};
+            MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to move the Taxonnode as child or behind the target node.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
+            dialog.open();
+            int returnCode = dialog.getReturnCode();
+            if (returnCode == 0){
+                moveToNewParent = MovingType.CHILD;
+            } else if (returnCode == 1){
+                moveToNewParent = MovingType.BEHIND;
+            }
         } else {
             parentTaxonNode = TaxonNodeSelectionDialog.select(activeShell,
                     new ConversationHolderMock(),
index eef8af1..ecd062b 100644 (file)
@@ -24,6 +24,7 @@ import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -47,7 +48,7 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation {
        //private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
 
        private final Set<UUID> taxonNodesUuid;
-       private final boolean moveToParentNode;
+       private final MovingType moveToParentNode;
        /**
         * <p>Constructor for MoveTaxonOperation.</p>
         *
@@ -59,7 +60,7 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation {
         * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
         */
        public MoveTaxonOperation(String label, IUndoContext undoContext,
-                       Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, boolean moveToParentNode) {
+                       Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, MovingType moveToParentNode) {
                super(label, undoContext, postOperationEnabled, conversationEnabled);
 
                this.taxonNodesUuid = taxonNodesUUIDToMove;
@@ -83,8 +84,16 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation {
                        throws ExecutionException {
                bind();
                monitor.worked(20);
+               UpdateResult result;
+               switch(this.moveToParentNode){
+               case CHILD:
+                   result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 0);
+               case PREVIOUS:
+                   result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 1);
+               case BEHIND:
+                   result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 2);
+               }
 
-               UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), moveToParentNode);
 //             try {
 //                     for (TaxonNode taxonNode : taxonNodes){
 //                             TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
index fca68db..907ffe2 100644 (file)
@@ -21,6 +21,7 @@ import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
 import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
 
 /**
@@ -34,13 +35,13 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
 
     private final Set<UUID> taxonNodesToMoveUuid;
     private final UUID newParentTreeNodeUuid;
-    private final boolean moveToParentNode;
+    private final MovingType moveToParentNode;
 
     public RemotingMoveTaxonOperation(Object source,
             boolean async,
             UUID taxonNodeToMoveUuid,
             UUID newParentTreeNodeUuid,
-            boolean moveToParentNode) {
+            MovingType moveToParentNode) {
         super(LABEL, Action.Update, source,async);
         taxonNodesToMoveUuid = new HashSet<UUID>();
         taxonNodesToMoveUuid.add(taxonNodeToMoveUuid);
@@ -52,7 +53,7 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
             boolean async,
             TaxonNode taxonNodeToMove,
             TaxonNode newParentTreeNode,
-            boolean moveToParentNode) {
+            MovingType moveToParentNode) {
         super(LABEL, Action.Update, source,async);
         taxonNodesToMoveUuid = new HashSet<UUID>();
         taxonNodesToMoveUuid.add(taxonNodeToMove.getUuid());
@@ -64,7 +65,7 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
             boolean async,
             Set<UUID> taxonNodesToMoveUuid,
             TaxonNode newParentTreeNode,
-            boolean moveToParentNode) {
+            MovingType moveToParentNode) {
         super(LABEL, Action.Update, source,async);
         this.taxonNodesToMoveUuid = taxonNodesToMoveUuid;
         this.newParentTreeNodeUuid = newParentTreeNode.getUuid();
@@ -76,8 +77,19 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
      */
     @Override
     protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
-        return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid,
-                newParentTreeNodeUuid, moveToParentNode);
+        switch (this.moveToParentNode) {
+            case CHILD:
+                return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid,
+                        newParentTreeNodeUuid, 0);
+            case BEHIND:
+                return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid,
+                newParentTreeNodeUuid, 2);
+             default:
+                    UpdateResult result = new UpdateResult();
+                    result.setAbort();
+                    result.addException(new Exception("The moving type is invalid."));
+                    return result;
+        }
     }
 
 }