ref #6566 Adjust SingleRead context menu items visibility
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / derivate / handler / SingleReadCopyToClipboardHandler.java
index ae5a9f11dee6f002051b25a819540228013654d6..5952709387f3ae97840786de4d286f3b49d7422a 100644 (file)
@@ -4,6 +4,7 @@ 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.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
@@ -25,10 +26,12 @@ public class SingleReadCopyToClipboardHandler {
     }
 
     @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
+    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
         boolean canExecute = false;
-        Object object = selectedTreeNode.getValue();
-        canExecute = (object instanceof SingleRead);
+        if(selectedTreeNode!=null){
+            Object object = selectedTreeNode.getValue();
+            canExecute = (object instanceof SingleRead);
+        }
         menuItem.setVisible(canExecute);
         return canExecute;
     }