Merge branch 'develop' into bulkEditorE4
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / e4 / handler / RemotingChangeAcceptedTaxonToSynonymHandlerE4.java
index 5df761d19ba9a3725e8763c00bc4c5fac6dd378b..9831b0b37704e5edcf5fe8f427fb83217b68ef26 100644 (file)
@@ -7,11 +7,16 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
+import javax.inject.Named;
+
 import org.eclipse.core.commands.operations.AbstractOperation;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.e4.core.di.annotations.CanExecute;
 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.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.swt.widgets.Shell;
 
@@ -40,7 +45,7 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
     }
 
     @Override
-    public IStatus allowOperations(TreeSelection selection,
+    public IStatus allowOperations(IStructuredSelection selection,
             Shell shell,
             MPart activePart,
             MHandledMenuItem menuItem) {
@@ -87,7 +92,7 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
     }
 
     @Override
-    public AbstractOperation prepareOperation(TreeSelection selection,
+    public AbstractOperation prepareOperation(IStructuredSelection selection,
             Shell shell,
             MPart activePart,
             MHandledMenuItem menuItem) {
@@ -113,6 +118,15 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
         return rcattso;
     }
 
+    @CanExecute
+    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
+        boolean canExecute = false;
+        canExecute = selection.getFirstElement() instanceof TaxonNode
+                && ((TaxonNode) selection.getFirstElement()).getTaxon()!=null;
+        menuItem.setVisible(canExecute);
+        return canExecute;
+    }
+
     @Override
     public void onComplete() {
     }