ref #6566 Adjust SingleRead context menu items visibility
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 22 May 2017 08:25:08 +0000 (10:25 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 22 May 2017 08:25:08 +0000 (10:25 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/SingleReadCopyToClipboardHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/SingleReadRemoveHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/SingleReadReuseHandler.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;
     }
index 3cd0a70917259e4adbe52ba37c44339cb6d5db4b..9342f300267b2ef7f35d306d3eba477bab47a8ad 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;
@@ -40,11 +41,13 @@ public class SingleReadRemoveHandler {
 
     @CanExecute
     public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
-            @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode,
+            @Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode,
             MHandledMenuItem menuItem) {
         boolean canExecute = false;
-        Object value = selectedTreeNode.getValue();
-        canExecute = value instanceof SingleRead && ((DerivateView) part.getObject()).getMultiLinkSingleReads().contains(value);
+        if(selectedTreeNode!=null){
+            Object value = selectedTreeNode.getValue();
+            canExecute = value instanceof SingleRead && ((DerivateView) part.getObject()).getMultiLinkSingleReads().contains(value);
+        }
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index e850ef78b36ad9d569abae563e869c8f52aadc67..ea7bea771213b1597b7d0fe3a32db5ab6c220c09 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;
@@ -46,13 +47,15 @@ public class SingleReadReuseHandler {
     }
 
     @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 value = selectedTreeNode.getValue();
-        TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
-        if(value instanceof Sequence && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead
-                && !((Sequence) value).getSingleReads().contains(clipboardNode.getValue())){
-            canExecute = true;
+        if(selectedTreeNode!=null){
+            Object value = selectedTreeNode.getValue();
+            TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
+            if(value instanceof Sequence && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead
+                    && !((Sequence) value).getSingleReads().contains(clipboardNode.getValue())){
+                canExecute = true;
+            }
         }
         menuItem.setVisible(canExecute);
         return canExecute;