ref #7010 Adapt taxon navigator handlers for multiple selection
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 6 Jun 2018 15:26:30 +0000 (17:26 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Jun 2018 08:05:47 +0000 (10:05 +0200)
12 files changed:
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/CloneClassificationHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/CopyHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/CreateClassificationHierarchyHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/DeleteHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/NewTaxonNodeHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RefreshTreeHandlerE4.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/e4/handler/RemotingDeleteTaxonNodeHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingMoveFactualDataHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingMoveTaxonNodeHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetPublishFlagForSubtreeHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/SetSecReferenceForSubtreeHandlerE4.java

index c3251289cf131f8ae24a75442af6563167397a66..14d98d72cbb9826b7eb027eb6ad871558890fd22 100644 (file)
@@ -70,7 +70,8 @@ public class CloneClassificationHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection.getFirstElement() instanceof TaxonNode
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNode
                 && ((TaxonNode) selection.getFirstElement()).getTaxon()==null
                 && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
         menuItem.setVisible(canExecute);
index bea766d5ca4ab87040efc48f52bbbe5b06106c15..bf7cb4f27f4bc78027ff58cfc263381eb64fc957 100644 (file)
@@ -19,7 +19,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.TreeSelection;
 
-import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
@@ -56,7 +55,8 @@ public class CopyHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection.getFirstElement() instanceof ITaxonTreeNode;
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNodeDto;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index facc35d7fc0740f5f94798a54560cd6f39dc7ea0..569f1596b339984f65f2082e8475cd721a929576 100644 (file)
@@ -53,7 +53,8 @@ public class CreateClassificationHierarchyHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection.getFirstElement() instanceof TaxonNode
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNode
                 && ((TaxonNode) selection.getFirstElement()).getTaxon()==null
                 && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
         menuItem.setVisible(canExecute);
index 96d6eb460ef41939bd7a5c4da8669b32eaf18224..005265c78b408c6c66f139426c15ae14a286ce84 100644 (file)
@@ -186,7 +186,11 @@ public class DeleteHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = !selection.isEmpty() && !(selection.getFirstElement() instanceof Synonym);
+        canExecute = !selection.isEmpty();
+        Object[] array = selection.toArray();
+        for (Object object : array) {
+            canExecute &= !(object instanceof Synonym);
+        }
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index af2c9985d5dd4588818642e5a299a7d8198a1077..b11cc4b029a5e8aea2c42cf8f1098c98f562a6ef 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.e4.ui.workbench.modeling.EModelService;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
@@ -65,7 +66,11 @@ public class NewTaxonNodeHandlerE4 {
        }
 
     @CanExecute
-    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection){
-        return selection!=null && !selection.isEmpty();
+    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
+            MHandledMenuItem menuItem){
+        boolean canExecute = false;
+        canExecute = selection!=null && selection.size()==1;
+        menuItem.setVisible(canExecute);
+        return canExecute;
     }
 }
index 2f443f5a4c531518dbe4891b44f1155512e60018..91665b7ed3d620627cb43201f48131ba283a0bab 100644 (file)
@@ -18,7 +18,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.TreeSelection;
 
-import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
 import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
 
 /**
@@ -40,7 +39,7 @@ public class RefreshTreeHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection.getFirstElement() instanceof TaxonNodeDto;
+        canExecute = !selection.isEmpty();
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 8f0cd852f543e9f47fe8c7c2ded21bc7e9742fe1..d17b0aa89cb00af501a5dc1fafe673311f0a326f 100644 (file)
@@ -143,7 +143,9 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = (selection.getFirstElement() instanceof TaxonNodeDto) && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null ;
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNodeDto
+                && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null ;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 9f812d6908fc3c00c8440fb72f56e028ed5e1831..cd5225f6ef4e408ca58c02d2f7ac5619803ac7a7 100644 (file)
@@ -196,10 +196,11 @@ public class RemotingDeleteTaxonNodeHandlerE4 extends RemotingCdmHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        Object selectionElement =  selection.getFirstElement();
-
-        canExecute = (selectionElement instanceof TaxonNodeDto) ||
-                (selectionElement instanceof TaxonNode && ((TaxonNode)selectionElement).getTaxon() == null);
+        canExecute = selection.size()==1
+                && (selection.getFirstElement() instanceof TaxonNodeDto)
+                ||
+                (selection.getFirstElement() instanceof TaxonNode
+                        && ((TaxonNode)selection.getFirstElement()).getTaxon() == null);
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 2e3655c5340203563671af5e1662b93e4a99a303..4f6b6d1f13f79213663d828c2d93553ccc1a2cc7 100644 (file)
@@ -123,7 +123,9 @@ public class RemotingMoveFactualDataHandlerE4 extends RemotingCdmHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = (selection.getFirstElement() instanceof TaxonNodeDto) && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid()  != null;
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNodeDto
+                && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid()  != null;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index eae99bf928c3d3cbb2a39edc13f0d5a2eaea862c..9fbd551abb2f2f01a9cb52d2c84a52d91a351e68 100644 (file)
@@ -145,7 +145,9 @@ public class RemotingMoveTaxonNodeHandlerE4 extends RemotingCdmHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = (selection.getFirstElement() instanceof TaxonNodeDto) && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid()  != null;
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNodeDto
+                && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 3b2812bdaaf95e7882eef2fb97403d09708d3378..edcb60a69dd8bcb0c74c360cb202cd78b7315131 100755 (executable)
@@ -92,7 +92,8 @@ public class SetPublishFlagForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection.getFirstElement() instanceof TaxonNodeDto;
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNodeDto;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 560dedcc32d3efb0a3cb5ac8825a69b37faac5c5..ad60d001bfa03119633f161185990087d75eebb8 100755 (executable)
@@ -90,7 +90,8 @@ public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
     @CanExecute
     private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection.getFirstElement() instanceof TaxonNodeDto;
+        canExecute = selection.size()==1
+                && selection.getFirstElement() instanceof TaxonNodeDto;
         menuItem.setVisible(canExecute);
         return canExecute;
     }