multiple selection for changeAcceptedTaxonAsSynonym and improve multiple selection...
authorKatja Luther <k.luther@bgbm.org>
Thu, 11 Jan 2018 11:04:22 +0000 (12:04 +0100)
committerKatja Luther <k.luther@bgbm.org>
Thu, 11 Jan 2018 11:04:22 +0000 (12:04 +0100)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/Messages.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages.properties
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages_de.properties
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorLabels.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/TaxonNavigatorE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingChangeAcceptedTaxonToSynonymHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java

index 082c4ead662383d674c2ac5e399a0ffb983f0223..08946e15fd1d6c31caae67002da292092cdebc05 100644 (file)
@@ -29,21 +29,42 @@ public class RemoveMergeCandidateHandlerE4  {
 
 
     @Execute
-    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmBase selection,
+    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
             @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
         BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
-        editor.getEditorInput().removeMergeCandidate(selection);
-        editor.refresh();
+        if (selection instanceof Object[]){
+            for(Object object: (Object[])selection){
+                 if (object instanceof CdmBase){
+                        editor.getEditorInput().removeMergeCandidate((CdmBase)object);
+                     editor.refresh();
+                 }
+             }
+         }else if (selection instanceof CdmBase){
+                editor.getEditorInput().removeMergeCandidate((CdmBase)selection);
+             editor.refresh();
+         }
+        
+        
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmBase selection,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
             @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem) {
         boolean canExecute = false;
         BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
-        canExecute = editor.getEditorInput().isMergingEnabled()
-                && editor.getEditorInput().getMergeCandidates().contains(selection);
+        boolean selectedMergeCandidate = false;
+        if (selection instanceof Object[]){
+            for(Object object: (Object[])selection){
+                 if (object instanceof CdmBase){
+                        editor.getEditorInput().getMergeCandidates().contains((CdmBase)object);
+                        selectedMergeCandidate = true;
+                 }
+             }
+         }
+        
+        canExecute = editor.getEditorInput().isMergingEnabled() && selectedMergeCandidate;
+//                && editor.getEditorInput().getMergeCandidates().contains(selection);
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 7d712c49371e3ce56df149b090599c0b0e00247e..bb383be7f65a2a60521f086da8ccd2bee316ef79 100644 (file)
@@ -111,7 +111,7 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
        }
 
        public void removeMergeCandidate(T t){
-           mergeCandidates.remove(t);
+               mergeCandidates.remove(t);
        }
 
     public void addToDelete(T t, DeleteConfiguratorBase config) {
index 430ac6575a5ce57c8b3955b15da8f34defd9d559..20894c911b99feb7f5205a21f985e0893d149037 100644 (file)
@@ -179,6 +179,7 @@ public class Messages extends NLS {
     public static String TreeNodeDropAdapter_UNSAVED_PARENT_MESSAGE;
     public static String SetPublishForSubtreeOperation_CHANGE_PUBLISH_OP;
     public static String TaxonNavigatorLabels_SET_PUBLISH_FOR_CHILDREN;
+       public static String TaxonNavigatorLabels_ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION;
        
 
 
index 4c89c01c009d6d0bf13d7cfd22e64b9e0809fcf6..c2e1c0b4e901f6e10f721a2ed28b0d770384ffce 100644 (file)
@@ -138,6 +138,7 @@ TaxonNavigatorLabels_NOT_TAXON_SELECTED=No taxon tree node selected for operatio
 TaxonNavigatorLabels_ONLY_SINGLE_TAXON=The chosen operation is available only for a single taxon.
 TaxonNavigatorLabels_SET_SEC_FOR_CHILDREN=Set new Secundum Reference for all children.
 TaxonNavigatorLabels_UNSAVED_CHANGES=There are unsaved changes in the source taxon. Please save first.
+TaxonNavigatorLabels_ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION=The selected taxa need to be from the same classification.
 TaxonNodeLabelProvider_NO_TAXON=>NO TAXON<
 TaxonNodeLabelProvider_CLASSIFICATION=Classification: 
 TaxonNodeLabelProvider_NODE_WITH_NO_TAXON=The taxon node does not have a taxon attached to it. Please check your import. TaxonNode: %s
index 68b5dcf7139523d0d9a5322997ac243d9cb844c0..cf3178cd8726780aee1e79291bd931be8a0884f9 100644 (file)
@@ -138,6 +138,7 @@ TaxonNavigatorLabels_NOT_TAXON_SELECTED=Kein Taxonknoten ausgew
 TaxonNavigatorLabels_ONLY_SINGLE_TAXON=Dieser Vorgang ist nur für einzelne Taxa möglich.
 TaxonNavigatorLabels_SET_SEC_FOR_CHILDREN=Neue secundum Referenz für alle Kinder setzen
 TaxonNavigatorLabels_UNSAVED_CHANGES=Es gibt Änderungen in dem Quell-Taxon. Bitte speichern Sie erst.
+TaxonNavigatorLabels_ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION=Die ausgewählten Taxa müssen zur gleichen Klassifikation gehören.
 TaxonNodeLabelProvider_NO_TAXON=>KEIN TAXON<
 TaxonNodeLabelProvider_NODE_WITH_NO_TAXON=Der Taxonknoten enthält kein Taxon. Bitte überprüfen Sie den Import. Taxonknoten: %s
 TaxonNodeLabelProvider_TAXON=Taxon: 
index f1ea7696aaef61d1930518832a05fadc098db5b8..162f44ba249b0835de049fcbfd40f50fd0fbb99c 100644 (file)
@@ -29,6 +29,7 @@ public interface TaxonNavigatorLabels {
     public static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = Messages.TaxonNavigatorLabels_NOT_A_NODE;
     public static final String UNSAVED_CHANGES_MESSAGE = Messages.TaxonNavigatorLabels_UNSAVED_CHANGES;
     public static final String CHANGE_SECUNDUM_FOR_SUBTREE = Messages.TaxonNavigatorLabels_SET_SEC_FOR_CHILDREN;
+       public static final String ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION = Messages.TaxonNavigatorLabels_ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION;
 
 
 
index 72dbc265bc7416fe9682831d7d0481f129fd6083..d1aa6cfd3c44f24be0ca9e43878a8f6091e69476 100644 (file)
@@ -151,7 +151,7 @@ public class TaxonNavigatorE4 implements
            layout.type = SWT.VERTICAL;
 
            parent.setLayout(layout);
-           viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+           viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
            viewer.getControl().setLayoutData(LayoutConstants.FILL());
 
            viewer.setContentProvider(new TaxonNavigatorContentProviderE4());
index a6ecb3dc0485f84a1e651b392979ecc9eff5e955..26633e3d4be9970dbbfd10b3aa23e6b3bd74ef61 100644 (file)
@@ -4,7 +4,10 @@
 package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
 
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.inject.Named;
@@ -20,6 +23,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.swt.widgets.Shell;
 
+import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
@@ -37,7 +41,8 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHandlerE4 {
 
 
-    private TaxonNode oldTaxonNode;
+    private Set<TaxonNode> oldTaxonNodes = new HashSet();
+    private Classification classification;
 
     public RemotingChangeAcceptedTaxonToSynonymHandlerE4() {
         super(TaxonNavigatorLabels.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
@@ -49,11 +54,11 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
             MPart activePart,
             MHandledMenuItem menuItem) {
         // check that only a single taxon tree node has been selected
-        if(selection.size() > 1) {
-            return new Status(IStatus.ERROR,
-                    "unknown", //$NON-NLS-1$
-                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
-        }
+//        if(selection.size() > 1) {
+//            return new Status(IStatus.ERROR,
+//                    "unknown", //$NON-NLS-1$
+//                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
+//        }
 
         // check for no taxon tree node selected
         if(selection.size() == 0) {
@@ -63,30 +68,39 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
         }
 
         // check that selected object is a taxon node
-        Object obj = selection.iterator().next();
-        if(obj instanceof TaxonNode && ((TaxonNode)obj).hasTaxon()) {
-            oldTaxonNode = (TaxonNode)obj;
-        } else {
-               if (obj instanceof TaxonNode && !((TaxonNode)obj).hasTaxon()){
-                       return new Status(IStatus.ERROR,
-                        "Operation not available for Classifications", //$NON-NLS-1$
-                        TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
-               }
-            return new Status(IStatus.ERROR,
-                    "unknown", //$NON-NLS-1$
-                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
-        }
-        // check that the source taxon node does not have children
-        if(oldTaxonNode.getCountChildren() > 0) {
-            return new Status(IStatus.ERROR,
-                    "unknown", //$NON-NLS-1$
-                    TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
-
+        Iterator it = selection.iterator();
+        while(it.hasNext()){
+               Object obj = it.next();
+               if(obj instanceof TaxonNode && ((TaxonNode)obj).hasTaxon()) {
+                   oldTaxonNodes.add((TaxonNode)obj);
+                   if (classification == null){
+                       classification = ((TaxonNode)obj).getClassification();
+                   }else if (classification != ((TaxonNode)obj).getClassification()){
+                       return new Status(IStatus.ERROR,
+                               "unknown", //$NON-NLS-1$
+                               TaxonNavigatorLabels.ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION);
+                   }
+               } else {
+                       if (obj instanceof TaxonNode && !((TaxonNode)obj).hasTaxon()){
+                               return new Status(IStatus.ERROR,
+                               "Operation not available for Classifications", //$NON-NLS-1$
+                               TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+                       }
+                   return new Status(IStatus.ERROR,
+                           "unknown", //$NON-NLS-1$
+                           TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+               }
+               // check that the source taxon node does not have children
+               if(((TaxonNode)obj).getCountChildren() > 0) {
+                   return new Status(IStatus.ERROR,
+                           "unknown", //$NON-NLS-1$
+                           TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
+       
+               }
+       
+               // check if corresponding name editor is closed
+               EditorUtil.closeObsoleteEditor((TaxonNode)obj, partService);
         }
-
-        // check if corresponding name editor is closed
-        EditorUtil.closeObsoleteEditor(oldTaxonNode, partService);
-
         return Status.OK_STATUS;
     }
 
@@ -96,22 +110,27 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
             MPart activePart,
             MHandledMenuItem menuItem) {
         List<UUID> excludeTaxa = new ArrayList<UUID>();
-        excludeTaxa.add(oldTaxonNode.getTaxon().getUuid());
+        for (TaxonNode oldNode:oldTaxonNodes){
+               excludeTaxa.add(oldNode.getTaxon().getUuid());
+        }
         TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(shell,
 //                new ConversationHolderMock(),
                 Messages.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON,
                 excludeTaxa,
-                oldTaxonNode,
-                oldTaxonNode.getClassification());
+                null,
+                classification);
 
         if (newAcceptedTaxonNode == null) {
             return null;
         }
-
+        Set<UUID> nodeUuids = new HashSet();
+        for (TaxonNode node: oldTaxonNodes){
+               nodeUuids.add(node.getUuid());
+        }
         RemotingChangeAcceptedTaxonToSynonymOperation rcattso =
                 new RemotingChangeAcceptedTaxonToSynonymOperation(getTrigger(),
                         false,
-                        oldTaxonNode.getUuid(),
+                        nodeUuids,
                         newAcceptedTaxonNode.getUuid());
 
         return rcattso;
index 2020b2952ae627198d53e9ab6ac50ca3fb6f8dba..cf3b979fc04ff273c1eec41a44fdcfaeeddbcd5c 100644 (file)
@@ -8,6 +8,8 @@
 */
 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
 
+import java.util.HashSet;
+import java.util.Set;
 import java.util.UUID;
 
 import org.eclipse.core.runtime.IAdaptable;
@@ -28,12 +30,24 @@ import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
  */
 public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUpdateOperation {
 
-    private final UUID oldTaxonNodeUuid;
+    private Set<UUID> oldTaxonNodeUuids = new HashSet();
     private final UUID newAcceptedTaxonNodeUuid;
 
 
     private final static String LABEL = Messages.RemotingChangeAcceptedTaxonToSynonymOperation_CHANGE_OP;
 
+    /**
+     * @param label
+     */
+    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
+            boolean async,
+            Set<UUID> oldTaxonNodeUuids,
+            UUID newAcceptedTaxonNodeUuid) {
+        super(LABEL, Action.Update, source, async);
+        this.oldTaxonNodeUuids.addAll(oldTaxonNodeUuids);
+        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
+    }
+    
     /**
      * @param label
      */
@@ -42,7 +56,7 @@ public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUp
             UUID oldTaxonNodeUuid,
             UUID newAcceptedTaxonNodeUuid) {
         super(LABEL, Action.Update, source, async);
-        this.oldTaxonNodeUuid = oldTaxonNodeUuid;
+        this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
         this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
     }
 
@@ -51,11 +65,20 @@ public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUp
      */
     @Override
     protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
-        return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuid,
-                newAcceptedTaxonNodeUuid,
-                null,
-                null,
-                null);
+       if (this.oldTaxonNodeUuids.size() == 1){
+               return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuids.iterator().next(),
+                    newAcceptedTaxonNodeUuid,
+                    null,
+                    null,
+                    null);
+       }else{
+               return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeSynonymsOfAnotherTaxonNode(oldTaxonNodeUuids,
+                    newAcceptedTaxonNodeUuid,
+                    null,
+                    null,
+                    null);
+       }
+        
     }
 
 }