TaxonNavigator : added refresh of navigator on data change
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 19 Jun 2015 13:20:14 +0000 (15:20 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 19 Jun 2015 13:20:14 +0000 (15:20 +0200)
TaxonNavigatorLabels : new interface with label strings used by taxon navigator handlers
RemotingChangeAcceptedTaxonToSynonymHandler : using TaxonNavigatorLabels
RemotingMoveFactualDataHandler : remoting version of move factual data handler
RemotingMoveFactualDataOperation : remoting version of move factual data operation
RemotingMoveTaxonHandler : remoting version of move taxon handler
RemotingMoveTaxonOperation : remoting version of move taxon operation
RemotingChangeAcceptedTaxonToSynonymOperation : replaced constructor input cdm entities to their uuids
RemotingCdmHandler : updated to handle other status severities and to handle warning status in post operation
RemotingCdmUpdateOperation : updated for warning status
TaxonNavigatorTest : added move taxon and move factual data tests

12 files changed:
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorLabels.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingChangeAcceptedTaxonToSynonymHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveFactualDataHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveTaxonHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveFactualDataOperation.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNavigatorTest.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/MockSessionOwner.java

index 663a163cac4f1978ce88e44b19798ccbca574a1b..94a0571f17180092ec9ab35a91d0a0d834f2c7b4 100644 (file)
@@ -37,6 +37,7 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonComparatorSearch;
 import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.DataChangeBridge;
 import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
@@ -171,7 +172,6 @@ public class TaxonNavigator extends CommonNavigator implements
      * Refresh this navigators viewer
      */
     public void refresh(Set objects) {
-
         for(Object obj : objects) {
             getCommonViewer().refresh(obj);
         }
@@ -519,7 +519,11 @@ public class TaxonNavigator extends CommonNavigator implements
      */
     @Override
     public void onChange(CdmChangeEvent event) {
-        // TODO Auto-generated method stub
+        for(CdmBase cb : event.getChangedObjects()) {
+            if(cb instanceof TaxonNode) {
+                getCommonViewer().refresh(cb);
+            }
+        }
 
     }
 }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorLabels.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorLabels.java
new file mode 100644 (file)
index 0000000..bbf1e49
--- /dev/null
@@ -0,0 +1,35 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.navigation.navigator;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public interface TaxonNavigatorLabels {
+
+    public static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
+    public static final String MOVE_TAXON_LABEL = "Move Taxon";
+    public static final String MOVE_FACTUAL_DATA_LABEL = "Move Factual Data";
+
+    public static final String NO_TAXON_SELECTION_MESSAGE = "No taxon tree node selected for operation.";
+    public static final String SINGLE_TAXON_SELECTION_MESSAGE = "The chosen operation is available only for a single taxon.";
+    public static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The chosen taxon must not have any childen. You need to move all childen to " +
+            "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
+            "taxon into a synonym.";
+    public static final String RELATED_EDITOR_NOT_CLOSED_MESSAGE = "Could not close related taxon name editor. " +
+            "Please close it manually and try again.";
+    public static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = "Selected object is not a taxon tree node";
+    public static final String UNSAVED_CHANGES_MESSAGE = "There are unsaved changes in the source taxon. Please save first.";
+
+
+
+}
index 9e43acdeb7d4693dc2ff4ea8cc7966422fd2e94b..a42c6dfb066a615ef639bff23fb4bb3c24b4de75 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
 import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
@@ -34,15 +35,6 @@ public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHand
     private static final Logger logger = Logger
             .getLogger(RemotingChangeAcceptedTaxonToSynonymHandler.class);
 
-    private static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
-    private static final String NO_TAXON_SELECTION_MESSAGE = "No taxon tree node selected for operation.";
-    private static final String SINGLE_TAXON_SELECTION_MESSAGE = "The operation move accepted taxon to synonymy is available only for a single taxon.";
-    private static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The accepted taxon must not have any childen. You need to move all childen to " +
-            "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
-            "taxon into a synonym.";
-    private static final String RELATED_EDITOR_NOT_CLOSED_MESSAGE = "Could not close related taxon name editor " +
-            "Please close it manually and try again.";
-    private static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = "Selected object is not a taxon tree node";
 
     private ITaxonTreeNode oldTaxonNode;
 
@@ -50,7 +42,7 @@ public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHand
      * @param label
      */
     public RemotingChangeAcceptedTaxonToSynonymHandler() {
-        super(CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
+        super(TaxonNavigatorLabels.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
     }
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
@@ -62,14 +54,14 @@ public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHand
         if(selection.size() > 1) {
             return new Status(IStatus.ERROR,
                     "unknown",
-                    SINGLE_TAXON_SELECTION_MESSAGE);
+                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
         }
 
         // check for no taxon tree node selected
         if(selection.size() == 0) {
             return new Status(IStatus.ERROR,
                     "unknown",
-                    NO_TAXON_SELECTION_MESSAGE);
+                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
         }
 
         // check that selected object is a taxon node
@@ -79,13 +71,13 @@ public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHand
         } else {
             return new Status(IStatus.ERROR,
                     "unknown",
-                    SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
         }
         // check that the source taxon node does not have children
         if(((TaxonNode)oldTaxonNode).getCountChildren() > 0) {
             return new Status(IStatus.ERROR,
                     "unknown",
-                    SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
+                    TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
 
         }
 
@@ -94,7 +86,7 @@ public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHand
         if(editorClosed != true) {
             return new Status(IStatus.ERROR,
                     "unknown",
-                    RELATED_EDITOR_NOT_CLOSED_MESSAGE);
+                    TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
         }
 
         return Status.OK_STATUS;
@@ -120,8 +112,8 @@ public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHand
         RemotingChangeAcceptedTaxonToSynonymOperation rcattso =
                 new RemotingChangeAcceptedTaxonToSynonymOperation(event.getTrigger(),
                         false,
-                        oldTaxonNode,
-                        newAcceptedTaxonNode);
+                        oldTaxonNode.getUuid(),
+                        newAcceptedTaxonNode.getUuid());
 
         return rcattso;
     }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveFactualDataHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveFactualDataHandler.java
new file mode 100644 (file)
index 0000000..f0fa3d9
--- /dev/null
@@ -0,0 +1,155 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.navigation.navigator.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveFactualDataHandler extends RemotingCdmHandler {
+
+
+    private TaxonNode sourceTaxonNode;
+    private TaxonNode targetTaxonNode;
+    /**
+     * @param label
+     */
+    public RemotingMoveFactualDataHandler() {
+        super(TaxonNavigatorLabels.MOVE_FACTUAL_DATA_LABEL);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public IStatus allowOperations(ExecutionEvent event) {
+        TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
+        // check that only a single taxon tree node has been selected
+        if(selection.size() > 1) {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
+        }
+
+        // check for no taxon tree node selected
+        if(selection.size() == 0) {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
+        }
+
+        // check that selected object is a taxon node
+        Object obj = selection.iterator().next();
+        if(obj instanceof ITaxonTreeNode) {
+            sourceTaxonNode = (TaxonNode)obj;
+        } else {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+        }
+
+        if(NavigationUtil.isDirty(sourceTaxonNode)) {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
+        }
+
+        List<UUID> excludeTaxa = new ArrayList<UUID>();
+        excludeTaxa.add(sourceTaxonNode.getTaxon().getUuid());
+
+        targetTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+                new ConversationHolderMock(),
+                "Choose the accepted taxon",
+                excludeTaxa,
+                null,
+                null);
+
+        if(targetTaxonNode == null) {
+            return new Status(IStatus.CANCEL,
+                    "unknown",
+                    "");
+        }
+        if(NavigationUtil.isDirty(targetTaxonNode)){
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
+        }
+        return Status.OK_STATUS;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public AbstractOperation prepareOperation(ExecutionEvent event) {
+        return new RemotingMoveFactualDataOperation(event.getTrigger(),
+                false,
+                sourceTaxonNode.getTaxon().getUuid(),
+                targetTaxonNode.getTaxon().getUuid());
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
+     */
+    @Override
+    public void onComplete() {
+        Display.getDefault().asyncExec(new Runnable(){
+            @Override
+            public void run() {
+                try {
+                    //close and re-open to refresh factual data view
+                    MultiPageTaxonEditor sourceEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(sourceTaxonNode.getUuid());
+                    MultiPageTaxonEditor targetEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(targetTaxonNode.getUuid());
+                    if(targetEditor != null){
+                        AbstractUtility.close(sourceEditor);
+                        AbstractUtility.close(targetEditor);
+                    }
+                    EditorUtil.openTaxonNode(sourceTaxonNode.getUuid());
+                    EditorUtil.openTaxonNode(targetTaxonNode.getUuid());
+                } catch (PartInitException e) {
+                    MessagingUtils.error(this.getClass(), e);
+                    throw new RuntimeException(e);
+                } catch (Exception e) {
+                    MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage());
+                }
+            }
+
+        });
+
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveTaxonHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveTaxonHandler.java
new file mode 100644 (file)
index 0000000..405cb65
--- /dev/null
@@ -0,0 +1,134 @@
+// $Id$
+/**
+ * Copyright (C) 2015 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.navigation.navigator.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+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.operation.RemotingMoveTaxonOperation;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveTaxonHandler extends RemotingCdmHandler {
+
+    private TaxonNode oldTaxonNode;
+
+    public RemotingMoveTaxonHandler() {
+        super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public IStatus allowOperations(ExecutionEvent event) {
+        TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
+        // check that only a single taxon tree node has been selected
+        if(selection.size() > 1) {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
+        }
+
+        // check for no taxon tree node selected
+        if(selection.size() == 0) {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
+        }
+        // check that selected object is a taxon node
+        Object obj = selection.iterator().next();
+        if(obj instanceof TaxonNode) {
+            oldTaxonNode = (TaxonNode)obj;
+        } else {
+            return new Status(IStatus.ERROR,
+                    "unknown",
+                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+        }
+        return Status.OK_STATUS;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public AbstractOperation prepareOperation(ExecutionEvent event) {
+        TaxonNode parentTaxonNode;
+
+        List<UUID> excludeTaxa = new ArrayList<UUID>();
+        excludeTaxa.add(oldTaxonNode.getUuid());
+
+        boolean moveToNewParent = true;
+
+        if (PreferencesUtil.getSortNodesNaturally()){
+            if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
+                moveToNewParent = false;
+            }
+            parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+                    new ConversationHolderMock(),
+                    "Choose the taxon above the moved taxon.",
+                    excludeTaxa,
+                    null,
+                    null);
+        } else {
+            parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+                    new ConversationHolderMock(),
+                    "Choose new parent",
+                    excludeTaxa,
+                    null,
+                    null);
+        }
+        if(parentTaxonNode != null){
+            if(NavigationUtil.isDirty(parentTaxonNode)){
+                MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
+                        "Unsaved Parent Taxon",
+                        "There are unsaved changes in the parent taxon. Please save first.");
+                return null;
+            }
+
+            return new RemotingMoveTaxonOperation(event.getTrigger(),
+                    false,
+                    oldTaxonNode.getUuid(),
+                    parentTaxonNode.getUuid(),
+                    moveToNewParent);
+        }
+
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
+     */
+    @Override
+    public void onComplete() {
+        // TODO Auto-generated method stub
+
+    }
+
+}
index 4eb9b3805a63196d3a5cdb39bf4b68a1974bb8a4..ac34629dc2cc7df08344fe2408ad1091c726378c 100644 (file)
@@ -9,6 +9,8 @@
 */
 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
 
+import java.util.UUID;
+
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 
@@ -16,8 +18,6 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 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.ITaxonTreeNode;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
 
 
@@ -28,21 +28,22 @@ import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
  */
 public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUpdateOperation {
 
-    private final TaxonNode newAcceptedTaxonNode;
-    private final ITaxonTreeNode oldTaxonNode;
+    private final UUID oldTaxonNodeUuid;
+    private final UUID newAcceptedTaxonNodeUuid;
+
 
-    private final static String LABEL = "ChangeAcceptedTaxonToSynonymOperation";
+    private final static String LABEL = "Change Accepted Taxon to Synonym operation";
 
     /**
      * @param label
      */
     public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
             boolean async,
-            ITaxonTreeNode oldTaxonNode,
-            TaxonNode newAcceptedTaxonNode) {
+            UUID oldTaxonNodeUuid,
+            UUID newAcceptedTaxonNodeUuid) {
         super(LABEL, Action.Update, source, async);
-        this.oldTaxonNode = oldTaxonNode;
-        this.newAcceptedTaxonNode = newAcceptedTaxonNode;
+        this.oldTaxonNodeUuid = oldTaxonNodeUuid;
+        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
     }
 
     /* (non-Javadoc)
@@ -50,7 +51,11 @@ public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUp
      */
     @Override
     protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
-        return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNode.getUuid(), newAcceptedTaxonNode.getUuid(), null, null, null);
+        return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuid,
+                newAcceptedTaxonNodeUuid,
+                null,
+                null,
+                null);
     }
 
 }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveFactualDataOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveFactualDataOperation.java
new file mode 100644 (file)
index 0000000..15351e9
--- /dev/null
@@ -0,0 +1,59 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.navigation.navigator.operation;
+
+import java.util.UUID;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
+import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveFactualDataOperation extends RemotingCdmUpdateOperation {
+
+    private final static String LABEL = "Move Factual Data operation";
+
+    private final UUID sourceTaxonUuid;
+    private final UUID targetParentTaxonUuid;
+
+    /**
+     * @param label
+     * @param action
+     * @param source
+     * @param async
+     */
+    public RemotingMoveFactualDataOperation(Object source,
+            boolean async,
+            UUID sourceTaxonUuid,
+            UUID targetParentTaxonUuid) {
+        super(LABEL, Action.Update, source, async);
+        this.sourceTaxonUuid = sourceTaxonUuid;
+        this.targetParentTaxonUuid = targetParentTaxonUuid;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+        return CdmApplicationState.getService(IDescriptionService.class).moveTaxonDescriptions(sourceTaxonUuid,
+                targetParentTaxonUuid);
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java
new file mode 100644 (file)
index 0000000..86f2dbf
--- /dev/null
@@ -0,0 +1,57 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.navigation.navigator.operation;
+
+import java.util.UUID;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+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.taxeditor.operation.RemotingCdmUpdateOperation;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
+
+    private final static String LABEL = "Move Taxon operation";
+
+    private final UUID taxonNodeToMoveUuid;
+    private final UUID newParentTreeNodeUuid;
+    private final boolean moveToParentNode;
+
+    public RemotingMoveTaxonOperation(Object source,
+            boolean async,
+            UUID taxonNodeToMoveUuid,
+            UUID newParentTreeNodeUuid,
+            boolean moveToParentNode) {
+        super(LABEL, Action.Update, source,async);
+        this.taxonNodeToMoveUuid = taxonNodeToMoveUuid;
+        this.newParentTreeNodeUuid = newParentTreeNodeUuid;
+        this.moveToParentNode = moveToParentNode;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+        return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNode(taxonNodeToMoveUuid,
+                newParentTreeNodeUuid,
+                moveToParentNode);
+    }
+
+}
index ac906cf9b789b3097bfdd87d0f65769633e7256f..a367512fb5b5a6ac02f9d1469832ace26b3618e6 100644 (file)
@@ -43,16 +43,26 @@ public abstract class RemotingCdmHandler extends AbstractHandler {
             if(op != null) {
                 AbstractUtility.executeOperation(op, this);
             }
-        } else {
+        } else if(allowStatus.getSeverity() == IStatus.ERROR ||
+                allowStatus.getSeverity() == IStatus.WARNING ||
+                allowStatus.getSeverity() == IStatus.INFO) {
             MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
         }
         return null;
     }
 
     public void postOperation(IStatus status) {
-        if(!status.isOK() && status.getException() != null) {
-            ErrorDialog.openError(null, "Error executing " + label, null, status);
+
+        switch(status.getSeverity()) {
+        case IStatus.WARNING:
+            MessagingUtils.warningDialog("Operation successful but with warnings", null, status);
+            break;
+        case IStatus.ERROR:
+            ErrorDialog.openError(null, "Error executing operation", null, status);
+            break;
+        default:
         }
+
         onComplete();
     }
 
index fb177fa00cc22cff20a029f74eaa4e2a547a9bb4..c0b0b828f85868de94aa2463cb2d58e9151c7029 100644 (file)
@@ -10,6 +10,8 @@
 package eu.etaxonomy.taxeditor.operation;
 
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -69,27 +71,41 @@ public abstract class RemotingCdmUpdateOperation extends RemotingCdmOperation {
     protected IStatus onComplete(boolean success) {
 
         if(updateResult != null) {
+            int statusFlag = IStatus.OK;
+
             Collection<Exception> exceptions = updateResult.getExceptions();
-            if(success && exceptions.isEmpty()) {
-                return Status.OK_STATUS;
+            if(success && updateResult.isOk()) {
+                if(exceptions.isEmpty()) {
+                    return Status.OK_STATUS;
+                } else {
+                    statusFlag = IStatus.WARNING;
+                }
+            } else {
+                statusFlag = IStatus.ERROR;
             }
 
             Status[] childStatus = new Status[exceptions.size()];
             int count = 0;
+            Set<String> messages = new HashSet<String>();
             for(Exception ex : exceptions) {
-                Status status = new Status(IStatus.ERROR,
+                Status status = new Status(statusFlag,
                         "unknown",
-                        IStatus.ERROR,
+                        statusFlag,
                         ex.getLocalizedMessage(),
                         ex);
+                messages.add(ex.getLocalizedMessage());
                 childStatus[count] = status;
                 count++;
             }
-
+            StringBuffer statusMsg = new StringBuffer();
+            for(String message : messages) {
+                statusMsg.append(message);
+                statusMsg.append(System.lineSeparator());
+            }
             MultiStatus multiStatus = new MultiStatus("unknown",
-                    IStatus.ERROR,
+                    statusFlag,
                     childStatus,
-                    getLabel() + " is in error",
+                    statusMsg.toString(),
                     null);
             return multiStatus;
         }
index 82c36e0e203f9157a0741acc63844f2eaa57b11a..6c73b008ff1f50d71c18923e8f7ac65bb3df2ea6 100644 (file)
@@ -9,6 +9,8 @@
  */
 package eu.etaxonomy.cdm.model;
 
+import java.util.HashSet;
+import java.util.Set;
 import java.util.UUID;
 
 import org.apache.log4j.Logger;
@@ -20,10 +22,15 @@ import org.unitils.dbunit.annotation.DataSet;
 import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
 import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
 
 /**
@@ -45,7 +52,7 @@ public class TaxonNavigatorTest extends BaseOperationTest {
 
 
     @Test
-    public void changeAcceptedTaxonToSynonymTest() throws ExecutionException {
+    public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
 
 
         UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
@@ -53,29 +60,74 @@ public class TaxonNavigatorTest extends BaseOperationTest {
 
         TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
         TaxonNameBase name = oldTaxonNode.getTaxon().getName();
+
+
         TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
-        sessionOwner.addUpdatedObject(oldTaxonNode.getParent());
+        int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
+        sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
+
 
-        Assert.assertEquals(0,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
         operation =  new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
                 false,
-                oldTaxonNode,
-                newAcceptedTaxonNode);
+                oldTaxonNode.getUuid(),
+                newAcceptedTaxonNode.getUuid());
         operation.execute(monitor, info);
         newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
-        sessionOwner.addUpdatedObject(newAcceptedTaxonNode);
+        sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
 
         oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
         Assert.assertNull(oldTaxonNode);
-        Assert.assertEquals(1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
+        Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
         Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
 
 
     }
 
     @Test
-    public void moveTaxonTest() {
+    public void testMoveTaxon() throws ExecutionException {
+
+        UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
+        UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
+        boolean moveToParentNode = true;
+
+        TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
+        TaxonNode oldParent = taxonNodeToMove.getParent();
+        sessionOwner.addExpectedUpdatedObject(oldParent);
+        int childCount = oldParent.getCountChildren();
+        TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
+        sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
+        operation = new RemotingMoveTaxonOperation(sessionOwner,
+                false,
+                taxonNodeToMove.getUuid(),
+                newParentTreeNode.getUuid(),
+                moveToParentNode);
+        operation.execute(monitor, info);
+        Assert.assertEquals(childCount-1, oldParent.getCountChildren());
+        Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
+        Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
+    }
+
+    @Test
+    public void testMoveFactualData() throws ExecutionException {
+        UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
+        UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
+
+        Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
+        Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
+        sessionOwner.addExpectedUpdatedObject(sourceTaxon);
 
+        Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
+        int countTargetDescriptions = targetTaxon.getDescriptions().size();
+        sessionOwner.addExpectedUpdatedObject(targetTaxon);
+
+        operation = new RemotingMoveFactualDataOperation(sessionOwner,
+                false,
+                sourceTaxonUuid,
+                targetTaxonUuid);
+        operation.execute(monitor, info);
+        Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
+        Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
+        Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
     }
 
 
index db1a0361bf30e66b3ad1eedffb11446ca7e05c37..5c7fa2169edd0883e6758aa83924cac7d3c83e5e 100644 (file)
@@ -32,7 +32,7 @@ public class MockSessionOwner<T extends CdmBase> implements ICdmEntitySessionEna
         this.updatedObjects = updatedObjects;
     }
 
-    public void addUpdatedObject(T updatedObject) {
+    public void addExpectedUpdatedObject(T updatedObject) {
         if(updatedObjects == null) {
             updatedObjects = new HashSet<T>();
         }