ref #6902 migrate remaining context menu items for molecular module
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 10 Aug 2017 10:42:06 +0000 (12:42 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 10 Aug 2017 12:12:39 +0000 (14:12 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/SpecimenPropertyTester.java
eu.etaxonomy.taxeditor.molecular/fragment.e4xmi
eu.etaxonomy.taxeditor.molecular/plugin.xml
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSequenceToFileHandler.java
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ShowPherogramHandler.java

index 636c0f494ef625e16562f2c13adb3c584d992e5a..da4d0f17c20c9f534a31c5551948524710b130f8 100644 (file)
@@ -6,6 +6,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeNode;
 
 import eu.etaxonomy.cdm.model.molecular.Sequence;
+import eu.etaxonomy.cdm.model.molecular.SingleRead;
 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
@@ -20,6 +21,7 @@ import eu.etaxonomy.taxeditor.editor.EditorUtil;
  */
 public class SpecimenPropertyTester extends PropertyTester {
     private static final String SEQUENCE = "isSequence"; //$NON-NLS-1$
+    private static final String SINGLE_READ = "isSingleRead"; //$NON-NLS-1$
     private static final String IS_SPECIMEN_OR_OBSERVATION_BASE = "isSpecimenOrObservationBase"; //$NON-NLS-1$
     private static final String IS_ADD_DERIVATE_ALLOWED = "isAddDerivateAllowed"; //$NON-NLS-1$
     private static final String IS_ADD_MEDIA_ALLOWED = "isAddMediaAllowed"; //$NON-NLS-1$
@@ -37,6 +39,9 @@ public class SpecimenPropertyTester extends PropertyTester {
                 if (SEQUENCE.equals(property)) {
                     return isSequence(treeNodeOfSelection.getValue());
                 }
+                else if (SINGLE_READ.equals(property)) {
+                    return isSingleRead(treeNodeOfSelection.getValue());
+                }
                 else if (IS_SPECIMEN_OR_OBSERVATION_BASE.equals(property)) {
                     return isSpecimenOrObservationBase(treeNodeOfSelection.getValue());
                 }
@@ -66,6 +71,10 @@ public class SpecimenPropertyTester extends PropertyTester {
                 && !(object instanceof MediaSpecimen);
     }
 
+    private boolean isSingleRead(Object object) {
+        return (object instanceof SingleRead);
+    }
+
     private boolean isSequence(Object object) {
         return (object instanceof Sequence);
     }
index ef4d443a917c8f16ab39a6e21c0f887c5a83be4a..df2b61a42987f423a4dcc585507b278750ac452d 100644 (file)
@@ -2,13 +2,23 @@
 <fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_OhwnQCTfEeeiN5lBIuqN3g">
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="__mwtMDVpEee_b7RlBzTDRw" featurename="commands" parentElementId="xpath:/">
     <elements xsi:type="commands:Command" xmi:id="_JZdQ0H2sEeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.editSequence" commandName="%command.EDIT_SEQUENCE"/>
+    <elements xsi:type="commands:Command" xmi:id="_IXQocH22EeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.exportSequenceToFile" commandName="%command.label.EXPORT_SEQUENCE_TO_FILE"/>
+    <elements xsi:type="commands:Command" xmi:id="_m9gZAH22EeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.showPherogram" commandName="%command.name.SHOW_PHEROGRAM"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_RCmzgH2sEeeVL5aZ55YsWA" featurename="handlers" parentElementId="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
     <elements xsi:type="commands:Handler" xmi:id="_XuBioH2sEeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.handler.EditSequenceHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.molecular/eu.etaxonomy.taxeditor.molecular.handler.EditSequenceHandler" command="_JZdQ0H2sEeeVL5aZ55YsWA"/>
+    <elements xsi:type="commands:Handler" xmi:id="_QwuNwH22EeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.handler.ExportSequenceToFileHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.molecular/eu.etaxonomy.taxeditor.molecular.handler.ExportSequenceToFileHandler" command="_IXQocH22EeeVL5aZ55YsWA"/>
+    <elements xsi:type="commands:Handler" xmi:id="_reIrkH22EeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.handler.ShowPherogramHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.molecular/eu.etaxonomy.taxeditor.molecular.handler.ShowPherogramHandler" command="_m9gZAH22EeeVL5aZ55YsWA"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_o08AQH2sEeeVL5aZ55YsWA" featurename="children" parentElementId="eu.etaxonomy.taxeditor.editor.popupmenu.specimeneditor" positionInList="before:eu.etaxonomy.taxeditor.editor.menuseparator.beforeDelete">
     <elements xsi:type="menu:HandledMenuItem" xmi:id="_txARoH2sEeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.handledmenuitem.commandlabeledit_sequence" label="%command.label.EDIT_SEQUENCE" command="_JZdQ0H2sEeeVL5aZ55YsWA">
       <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_wpbQQH2sEeeVL5aZ55YsWA" coreExpressionId="isSequence"/>
     </elements>
+    <elements xsi:type="menu:HandledMenuItem" xmi:id="_VRC-UH22EeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.handledmenuitem.commandlabelexport_sequence_to_file" label="%command.label.EXPORT_SEQUENCE_TO_FILE" command="_IXQocH22EeeVL5aZ55YsWA">
+      <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_ZLzjsH22EeeVL5aZ55YsWA" coreExpressionId="isSequence"/>
+    </elements>
+    <elements xsi:type="menu:HandledMenuItem" xmi:id="_xftzgH22EeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.molecular.handledmenuitem.commandnameshow_pherogram" label="%command.name.SHOW_PHEROGRAM" command="_m9gZAH22EeeVL5aZ55YsWA">
+      <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_0tfXEH22EeeVL5aZ55YsWA" coreExpressionId="isSingleRead"/>
+    </elements>
   </fragments>
 </fragment:ModelFragments>
index d9233aa48ded9dc9b4b93de9c3c8b85eab4647ff..521206e463789172778899993e95c8071fbe48f2 100644 (file)
       </extension>
       <extension
             point="org.eclipse.ui.commands">
-         <command
-               defaultHandler="eu.etaxonomy.taxeditor.molecular.handler.ShowPherogramHandler"
-               id="eu.etaxonomy.taxeditor.molecular.showPherogram"
-               name="%command.name.SHOW_PHEROGRAM">
-         </command>
          <command
                id="eu.etaxonomy.taxeditor.molecular.AlignmentEditor.cutPherogramLeft"
                name="%command.name.CUT_PHEROGRAM_LEFT">
                id="eu.etaxonomy.taxeditor.molecular.AlignmentEditor.toggleLeftRightInsertion"
                name="%command.name.TOGGLE_LEFT_RIGHT_INSERTION">
          </command>
-         <command
-               defaultHandler="eu.etaxonomy.taxeditor.molecular.handler.ExportSequenceToFileHandler"
-               id="eu.etaxonomy.taxeditor.molecular.exportSequenceToFile"
-               name="%command.name.EXPORT_SEQUENCE_TO_FILE">
-         </command>
       </extension>
       <extension
             point="org.eclipse.ui.menus">
                </visibleWhen>
             </menu>
          </menuContribution>
-         <menuContribution
-               locationURI="popup:eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView?before=eu.etaxonomy.taxeditor.editor.derivative.reuseSingleReadMenuItem">
-            <separator
-                  name="eu.etaxonomy.taxeditor.molecular.separator5"
-                  visible="true">
-            </separator>
-            <command
-                  commandId="eu.etaxonomy.taxeditor.molecular.exportSequenceToFile"
-                  label="%command.label.EXPORT_SEQUENCE_TO_FILE"
-                  style="push">
-               <visibleWhen
-                     checkEnabled="true">
-                  <reference
-                        definitionId="isSequence">
-                  </reference>
-               </visibleWhen>
-            </command>
-            <command
-                  commandId="eu.etaxonomy.taxeditor.molecular.showPherogram"
-                  label="%command.label.SHOW_PHEROGRAM"
-                  style="push">
-               <visibleWhen
-                     checkEnabled="true">
-                  <reference
-                        definitionId="isSingleRead">
-                  </reference>
-               </visibleWhen>
-            </command>
-         </menuContribution>
       </extension>
       <extension
             point="org.eclipse.ui.handlers">
index 59d466b0b1a11d65ab1b06d9216cee9f0e120f62..a7b293acee6fc2edd7ab0fc57714f689935ec4cf 100644 (file)
 package eu.etaxonomy.taxeditor.molecular.handler;\r
 \r
 \r
-import info.bioinfweb.jphyloio.JPhyloIOEventWriter;\r
-import info.bioinfweb.jphyloio.ReadWriteParameterMap;\r
-import info.bioinfweb.jphyloio.ReadWriteParameterNames;\r
-import info.bioinfweb.jphyloio.dataadapters.implementations.ListBasedDocumentDataAdapter;\r
-import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;\r
-import info.bioinfweb.jphyloio.objecttranslation.ObjectTranslatorFactory;\r
-\r
 import java.io.File;\r
 import java.io.IOException;\r
 \r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
+import javax.inject.Named;\r
+\r
 import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.e4.core.di.annotations.Execute;\r
+import org.eclipse.e4.core.di.annotations.Optional;\r
+import org.eclipse.e4.ui.services.IServiceConstants;\r
 import org.eclipse.jface.viewers.TreeNode;\r
 import org.eclipse.jface.wizard.WizardDialog;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.swt.widgets.Shell;\r
 \r
 import eu.etaxonomy.cdm.model.molecular.Sequence;\r
-import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
 import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
 import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;\r
 import eu.etaxonomy.taxeditor.molecular.io.CDMPherogramAlignmentObjectTranslator;\r
@@ -39,6 +32,12 @@ import eu.etaxonomy.taxeditor.molecular.io.SingleReadAlignmentRDFXMLConstants;
 import eu.etaxonomy.taxeditor.molecular.io.wizard.ExportSingleReadAlignmentWizard;\r
 import eu.etaxonomy.taxeditor.molecular.l10n.Messages;\r
 import eu.etaxonomy.taxeditor.util.ApplicationUtil;\r
+import info.bioinfweb.jphyloio.JPhyloIOEventWriter;\r
+import info.bioinfweb.jphyloio.ReadWriteParameterMap;\r
+import info.bioinfweb.jphyloio.ReadWriteParameterNames;\r
+import info.bioinfweb.jphyloio.dataadapters.implementations.ListBasedDocumentDataAdapter;\r
+import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;\r
+import info.bioinfweb.jphyloio.objecttranslation.ObjectTranslatorFactory;\r
 \r
 \r
 \r
@@ -49,19 +48,18 @@ import eu.etaxonomy.taxeditor.util.ApplicationUtil;
  * @author Ben Stöver\r
  * @date 24.04.2016\r
  */\r
-public class ExportSequenceToFileHandler extends AbstractHandler {\r
+public class ExportSequenceToFileHandler {\r
     private static final JPhyloIOReaderWriterFactory factory = new JPhyloIOReaderWriterFactory();\r
 \r
 \r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);\r
-        TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);\r
+    @Execute\r
+    public Object execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)TreeNode treeNodeOfSelection,\r
+            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {\r
         if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence) {\r
             Sequence sequence = (Sequence)treeNodeOfSelection.getValue();\r
 \r
             final ExportSingleReadAlignmentWizard wizard = new ExportSingleReadAlignmentWizard();\r
-            final WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);\r
+            final WizardDialog dialog = new WizardDialog(shell, wizard);\r
             if (dialog.open() == IStatus.OK) {\r
                 // Prepare writer parameters:\r
                 ReadWriteParameterMap parameters = new ReadWriteParameterMap();\r
index 1d468b4414a2f12234ee5476553878b6fa09af88..a46705a1589d74ebf4097e1704799eb63b81c9b7 100644 (file)
@@ -1,26 +1,24 @@
 package eu.etaxonomy.taxeditor.molecular.handler;
 
 
-import info.bioinfweb.libralign.pherogram.model.PherogramComponentModel;
-
 import java.net.URI;
 
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.media.MediaUtils;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
 import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
 import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
 import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
+import info.bioinfweb.libralign.pherogram.model.PherogramComponentModel;
 
 
 
@@ -29,16 +27,14 @@ import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
  *
  * @author Ben Stöver
  */
-public class ShowPherogramHandler extends AbstractHandler {
+public class ShowPherogramHandler {
        public static void showPherogram(PherogramComponentModel model) throws PartInitException {
                PherogramViewPart.createView(model);
        }
 
 
-       @Override
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
-               TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);
+       @Execute
+       public Object execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)TreeNode treeNodeOfSelection) {
                if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof SingleRead) {
                    //TODO Can the parent node (containing the cut positions) be extracted from SingleRead?
                        try {