commit 3699c749fddd8b698ead1c8b6360fe98710b4a57
Author: Katja Luther <k.luther@bgbm.org>
Date:   Mon Mar 5 14:55:59 2018 +0100

    ref  #7227: check for empty selection for menu creation

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertPerson2TeamHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertPerson2TeamHandlerE4.java
index 651327ca5..539329ddc 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertPerson2TeamHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertPerson2TeamHandlerE4.java
@@ -17,6 +17,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
@@ -71,11 +72,11 @@ public class ConvertPerson2TeamHandlerE4 {
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmBase selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection instanceof Person;
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection.getFirstElement() instanceof Person && selection.size() == 1;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertTeam2PersonHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertTeam2PersonHandlerE4.java
index 8751c3292..2aa846c89 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertTeam2PersonHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertTeam2PersonHandlerE4.java
@@ -17,6 +17,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
@@ -73,11 +74,11 @@ public class ConvertTeam2PersonHandlerE4 {
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmBase selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection instanceof Team;
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = ((BulkEditorE4)activePart.getObject()).getEditorInput().isConvertingEnabled() && selection.getFirstElement() instanceof Team && selection.size() == 1;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/DeleteHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/DeleteHandlerE4.java
index 5b6f6e732..6779b8e8c 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/DeleteHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/DeleteHandlerE4.java
@@ -23,6 +23,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.application.ICdmRepository;
@@ -253,10 +254,11 @@ public class DeleteHandlerE4 {
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection!=null;
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = !selection.isEmpty();
         menuItem.setVisible(canExecute);
         return canExecute;
     }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/OpenBulkEditorHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/OpenBulkEditorHandlerE4.java
index 0cf9b162b..88f3da1fb 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/OpenBulkEditorHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/OpenBulkEditorHandlerE4.java
@@ -7,14 +7,22 @@
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 package eu.etaxonomy.taxeditor.bulkeditor.e4.handler;
+import javax.inject.Named;
+
 import org.eclipse.core.commands.ParameterizedCommand;
+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.basic.MPart;
+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;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
+import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
 import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
 import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputType;
 
@@ -33,4 +41,16 @@ public class OpenBulkEditorHandlerE4 {
 		AbstractBulkEditorInput input = AbstractBulkEditorInput.NewInstance(inputType);
 		BulkEditorUtil.openBulkEditor(input, modelService, partService, application);
 	}
+
+	 @CanExecute
+	 public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+	            MHandledMenuItem menuItem) {
+        boolean canExecute = false;
+        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = !selection.isEmpty();
+        menuItem.setVisible(canExecute);
+        return canExecute;
+
+	}
 }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java
index 08946e15f..6ea8ed558 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java
@@ -15,6 +15,7 @@ import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
@@ -43,26 +44,26 @@ public class RemoveMergeCandidateHandlerE4  {
         	 editor.getEditorInput().removeMergeCandidate((CdmBase)selection);
              editor.refresh();
          }
-        
-        
+
+
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem) {
         boolean canExecute = false;
         BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
         boolean selectedMergeCandidate = false;
-        if (selection instanceof Object[]){
-            for(Object object: (Object[])selection){
+        if (selection instanceof StructuredSelection){
+            for(Object object: selection.toArray()){
                  if (object instanceof CdmBase){
-                	 editor.getEditorInput().getMergeCandidates().contains((CdmBase)object);
+                	 editor.getEditorInput().getMergeCandidates().contains(object);
                 	 selectedMergeCandidate = true;
                  }
              }
          }
-        
+
         canExecute = editor.getEditorInput().isMergingEnabled() && selectedMergeCandidate;
 //                && editor.getEditorInput().getMergeCandidates().contains(selection);
         menuItem.setVisible(canExecute);
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java
index 08a304d59..6bfbcf75e 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java
@@ -15,11 +15,11 @@ import javax.inject.Named;
 
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
-import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.ui.di.UISynchronize;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
 import eu.etaxonomy.cdm.model.common.MarkerType;
@@ -54,10 +54,11 @@ public class SetMarkerFlagHandlerE4 {
 
 
     @CanExecute
-    public boolean canExecute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem){
         boolean canExecute = false;
-        canExecute = selection instanceof IAnnotatableEntity;
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = !selection.isEmpty() && selection.getFirstElement() instanceof IAnnotatableEntity;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeCandidateHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeCandidateHandlerE4.java
index 8b736ba93..54b5f6453 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeCandidateHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeCandidateHandlerE4.java
@@ -15,6 +15,7 @@ import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
@@ -50,14 +51,15 @@ public class SetMergeCandidateHandlerE4 {
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem) {
         boolean canExecute = false;
         BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
-        canExecute = selection!=null
+
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = !selection.isEmpty()
                 && editor.getEditorInput().isMergingEnabled()
-                && !editor.getEditorInput().getMergeCandidates().contains(selection);
+                && !editor.getEditorInput().getMergeCandidates().contains(selection.getFirstElement());
         menuItem.setVisible(canExecute);
         return canExecute;
     }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java
index f4197b9ef..3ea037b35 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java
@@ -15,6 +15,7 @@ import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
@@ -41,12 +42,12 @@ public class SetMergeTargetHandlerE4 {
 	}
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmBase selection,
-            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MHandledMenuItem menuItem) {
         boolean canExecute = false;
         BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
-        canExecute = selection!=null
+        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
+        canExecute = !selection.isEmpty()
                 && editor.getEditorInput().isMergingEnabled()
                 && (editor.getEditorInput().getMergeTarget()==null
                 || !editor.getEditorInput().getMergeTarget().equals(selection));
