ref #6932 Migrate marker type handler
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 26 Sep 2017 13:28:41 +0000 (15:28 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 26 Sep 2017 13:28:41 +0000 (15:28 +0200)
eu.etaxonomy.taxeditor.bulkeditor/fragment.e4xmi
eu.etaxonomy.taxeditor.bulkeditor/plugin.xml
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicMarkerTypeEditingMenuE4.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java

index 1ed8609e9357d183f13762c094298930914f1fd3..ead9eb0598009ec5e04de030396b9e586c4982c5 100644 (file)
@@ -14,6 +14,7 @@
     <elements xsi:type="commands:Command" xmi:id="_S8xR4JcNEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.delete" commandName="%command.label.4"/>
     <elements xsi:type="commands:Command" xmi:id="_jWkVYJcOEeeM745tzuPNCQ" elementId="taxeditor-bulkeditor.dynamicnewobjectcommand" commandName="%command.name.2"/>
     <elements xsi:type="commands:Command" xmi:id="_tLGKgJcOEeeM745tzuPNCQ" elementId="taxeditor-bulkeditor.dynamicdeleteobjectcommand" commandName="%command.name.3"/>
+    <elements xsi:type="commands:Command" xmi:id="_Svo9oKK6EeeZb4PEjoRsuw" elementId="taxeditor-bulkeditor.command.setMarkerFlag" commandName="%command.name.6"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_l_8NMCQUEeelPNxAg-e3TA" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.admin">
     <elements xsi:type="menu:MenuSeparator" xmi:id="_zph3kDF2Eee-JvlKXQGppA" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.0"/>
@@ -52,6 +53,7 @@
       <handlers xmi:id="_a-U4EJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMergeTargetHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMergeTargetHandlerE4" command="_GAm9cJcNEeeM745tzuPNCQ"/>
       <handlers xmi:id="_qPOPQJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.NewObjectHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.NewObjectHandlerE4" command="_jWkVYJcOEeeM745tzuPNCQ"/>
       <handlers xmi:id="_vskBsJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.DeleteObjectHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.DeleteObjectHandlerE4" command="_tLGKgJcOEeeM745tzuPNCQ"/>
+      <handlers xmi:id="_c9ppwKK6EeeZb4PEjoRsuw" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMarkerFlagHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMarkerFlagHandlerE4" command="_Svo9oKK6EeeZb4PEjoRsuw"/>
       <menus xsi:type="menu:PopupMenu" xmi:id="_B6IFsJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor">
         <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_H83EMJcMEeeM745tzuPNCQ" coreExpressionId="isCdmStoreConnected"/>
         <children xsi:type="menu:DynamicMenuContribution" xmi:id="_Y49vAJfHEeeUB5KN7hGpYQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicNewObjectMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicNewObjectMenuE4"/>
@@ -65,7 +67,7 @@
         <children xsi:type="menu:HandledMenuItem" xmi:id="_l6dgYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.convertTeam2Person" label="%command.label.5" command="_PtZy4JcNEeeM745tzuPNCQ"/>
         <children xsi:type="menu:HandledMenuItem" xmi:id="_oKqBYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.convertPerson2Team" label="%command.label.6" command="_RFEJYJcNEeeM745tzuPNCQ"/>
         <children xsi:type="menu:MenuSeparator" xmi:id="_p-7bYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.3"/>
-        <children xsi:type="menu:Menu" xmi:id="_saDaAJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menu.chooseMarkerType" label="%menu.label.2"/>
+        <children xsi:type="menu:DynamicMenuContribution" xmi:id="_MughoKK6EeeZb4PEjoRsuw" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4"/>
         <children xsi:type="menu:MenuSeparator" xmi:id="_x3rgUJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.4"/>
         <children xsi:type="menu:HandledMenuItem" xmi:id="_yt2TUJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.delete" label="%command.label.4" command="_S8xR4JcNEeeM745tzuPNCQ"/>
       </menus>
index 2765e9a775fd1d0aaaeed0e36a718376532f4569..95d273008cfaba8e358b965360ba17c4347509ba 100644 (file)
             name="%editor.name.1">
       </editor>
    </extension>
-   <extension
-         point="org.eclipse.ui.menus">
-      <menuContribution
-            locationURI="popup:bulkeditor.editor">
-         <menu
-               label="%menu.label.1">
-            <dynamic
-                  class="eu.etaxonomy.taxeditor.bulkeditor.command.DynamicNewObjectMenu"
-                  id="eu.etaxonomy.taxeditor.bulkeditor.dynamicNewMenu">
-               <visibleWhen
-                     checkEnabled="false">
-                  <reference
-                        definitionId="isCdmStoreConnected">
-                  </reference>
-               </visibleWhen>
-            </dynamic>
-            <visibleWhen
-                  checkEnabled="true">
-               <reference
-                     definitionId="isCdmStoreConnected">
-               </reference>
-            </visibleWhen>
-         </menu>
-         <separator
-               name="taxeditor-bulkeditor.separator4"
-               visible="true">
-         </separator>
-         <command
-               commandId="bulkeditor.commands.setmergetarget"
-               label="%command.label.0"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isMergeEnabled">
-               </reference>
-            </visibleWhen>
-         </command>
-         
-         <command
-               commandId="bulkeditor.commands.setmergecandidate"
-               label="%command.label.1"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isMergeEnabled">
-               </reference>
-            </visibleWhen>
-         </command>
-         <command
-               commandId="bulkeditor.commands.removemergecandidate"
-               label="%command.label.2"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isMergeEnabled">
-               </reference>
-            </visibleWhen>
-         </command>            
-         <command
-               commandId="bulkeditor.commands.mergegroup"
-               label="%command.label.3"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isMergeEnabled">
-               </reference>
-            </visibleWhen>
-         </command>
-         <separator
-               name="eu.etaxonomy.taxeditor.bulkeditor.separator1"
-               visible="true">
-         </separator>
-         <command
-               commandId="eu.etaxonomy.taxeditor.bulkeditor.convertTeam2Person"
-               label="%command.label.5"
-               style="push">
-                  <visibleWhen
-                               checkEnabled="true">
-                               <and>
-                               <reference
-                       definitionId="isConvertEnabled">
-                               </reference>
-                               <reference 
-                                               definitionId="isTeam">
-                               </reference>
-                       </and>
-                       </visibleWhen>
-         </command>
-         <command
-               commandId="eu.etaxonomy.taxeditor.bulkeditor.convertPerson2Team"
-               label="%command.label.6"
-               style="push">
-               <visibleWhen 
-                       checkEnabled="true">>
-                               <and>
-                               <reference
-                       definitionId="isConvertEnabled">
-                               </reference>
-                               <reference 
-                                       definitionId="isPerson">
-                               </reference>
-                       </and>
-                       </visibleWhen>
-         </command>
-         <separator
-               name="taxeditor-bulkeditor.separator2"
-               visible="true">
-         </separator>
-         <menu
-               label="%menu.label.2">
-            <dynamic
-                  class="eu.etaxonomy.taxeditor.bulkeditor.command.DynamicMarkerTypeEditingMenu"
-                  id="eu.etaxonomy.taxeditor.bulkeditor.dynamicMarkerTypeEditingMenu">
-            </dynamic>
-            <visibleWhen
-                  checkEnabled="true">
-               <reference
-                     definitionId="isCdmStoreConnected">
-               </reference>
-            </visibleWhen>
-         </menu>
-         <separator
-               name="taxeditor-bulkeditor.separator3"
-               visible="true">
-         </separator>
-         <command
-               commandId="eu.etaxonomy.taxeditor.bulkeditor.delete"
-               label="%command.label.4"
-               style="push">
-            <visibleWhen
-                  checkEnabled="true">
-               <reference
-                     definitionId="isCdmStoreConnected">
-               </reference>
-            </visibleWhen>
-         </command>
-         <dynamic
-               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
-               id="eu.etaxonomy.taxeditor.bulkeditor.cdmViewerContextMenu">
-         </dynamic>
-      <!--menuContribution
-            locationURI="popup:org.eclipse.ui.popup.any"-->
-      </menuContribution>
-   </extension>
    <extension
          point="org.eclipse.ui.commands">
-      <command
-            defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.SetMarkerFlagHandler"
-            id="taxeditor-bulkeditor.command.setMarkerFlag"
-            name="%command.name.6">
-      </command>
       <command
             id="eu.etaxonomy.taxeditor.openReferencingObjectsView"
             name="%command.name.OPEN_REFERENCING_OBJECTS_VIEW">
                typeId="eu.etaxonomy.taxeditor.uuidParameterType">
          </commandParameter>
       </command>
-      <command
-            defaultHandler="eu.etaxonomy.taxeditor.handler.defaultHandler.OpenReferencingObjectsView"
-            id="eu.etaxonomy.taxeditor.openReferencingObjectsViewFromMenu"
-            name="%command.name.OPEN_REFERENCING_OBJECTS_VIEW">
-      </command>
       <!--command
             defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.NewEntityHandler"
             id="eu.etaxonomy.taxeditor.bulkeditor.command.new"
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicMarkerTypeEditingMenuE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicMarkerTypeEditingMenuE4.java
new file mode 100644 (file)
index 0000000..2d7b777
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.bulkeditor.e4.command;
+
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.ui.di.AboutToShow;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
+import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+import org.eclipse.e4.ui.services.IServiceConstants;
+
+import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ *
+ * @author pplitzner
+ * @date 26.09.2017
+ *
+ */
+public class DynamicMarkerTypeEditingMenuE4 {
+
+    public static final String COMMAND_ID = "taxeditor-bulkeditor.command.setMarkerFlag";
+    public static final String COMMAND_PARAMETER_MARKER_TYPE = COMMAND_ID+".markerType";
+    public static final String COMMAND_PARAMETER_MARKER_STATE = COMMAND_ID+".markerState";
+
+       /** {@inheritDoc} */
+    @AboutToShow
+    public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
+        if(selection==null){
+            return;
+        }
+        MMenu menu = MMenuFactory.INSTANCE.createMenu();
+        menu.setLabel("Choose marker type");
+        items.add(menu);
+        for(MarkerType markerType : CdmStore.getTermManager().getPreferredTerms(MarkerType.class)){
+            createMenuItem(menu, markerType);
+        }
+    }
+
+       private void createMenuItem(MMenu menu, final MarkerType markerType) {
+
+           MMenu subMenu = MMenuFactory.INSTANCE.createMenu();
+           subMenu.setLabel(String.format("Set Flag '%s'", markerType.getLabel()));
+           menu.getChildren().add(subMenu);
+
+           MHandledMenuItem subMenuItemYes = MMenuFactory.INSTANCE.createHandledMenuItem();
+           subMenuItemYes.setLabel("Yes");
+           MCommand mCommandYes = MCommandsFactory.INSTANCE.createCommand();
+           mCommandYes.setElementId(COMMAND_ID);
+           //set params
+           subMenuItemYes.getTransientData().put(COMMAND_PARAMETER_MARKER_TYPE, markerType);
+           subMenuItemYes.getTransientData().put(COMMAND_PARAMETER_MARKER_STATE, true);
+           subMenuItemYes.setCommand(mCommandYes);
+           subMenu.getChildren().add(subMenuItemYes);
+
+           MHandledMenuItem subMenuItemNo = MMenuFactory.INSTANCE.createHandledMenuItem();
+           subMenuItemNo.setLabel("No");
+           MCommand mCommandNo = MCommandsFactory.INSTANCE.createCommand();
+           mCommandNo.setElementId(COMMAND_ID);
+           //set params
+           subMenuItemNo.getTransientData().put(COMMAND_PARAMETER_MARKER_TYPE, markerType);
+           subMenuItemNo.getTransientData().put(COMMAND_PARAMETER_MARKER_STATE, false);
+           subMenuItemNo.setCommand(mCommandNo);
+           subMenu.getChildren().add(subMenuItemNo);
+       }
+
+}
index 98a3adb1ac831d204abdf764058a2cb2319b228d..96cc01d9082ccc0df98aab13186dacd9bed3dfb2 100644 (file)
@@ -1,82 +1,64 @@
 /**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 
 package eu.etaxonomy.taxeditor.bulkeditor.e4.handler;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
+import java.util.Collections;
+
+import javax.inject.Named;
 
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.handlers.HandlerUtil;
+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;
 
 import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
 import eu.etaxonomy.cdm.model.common.MarkerType;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
-import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
+import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
+import eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4;
+import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
 import eu.etaxonomy.taxeditor.bulkeditor.operation.SetMarkerFlagOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 
 /**
- * <p>SetMarkerFlagTrueHandler class.</p>
  *
- * @author p.ciardelli
- * @created 20.10.2009
- * @version 1.0
+ * @author pplitzner
+ * @date 26.09.2017
+ *
  */
-public class SetMarkerFlagHandlerE4 extends AbstractHandler {
+public class SetMarkerFlagHandlerE4 {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IAnnotatableEntity selection,
+            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+            MHandledMenuItem menuItem) {
+
+        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
+        AbstractBulkEditorInput input = editor.getEditorInput();
+        MarkerType markerType = (MarkerType) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_TYPE);
+        boolean markerState = (boolean) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_STATE);
+
+
+        AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), Collections.singleton(selection), markerType, markerState, editor);
+        BulkEditorUtil.executeOperation(operation);
+    }
+
 
-       /* (non-Javadoc)
-        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-        */
-       /** {@inheritDoc} */
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               
-               ISelection selection = HandlerUtil.getCurrentSelection(event);
-               
-               IEditorPart editor = HandlerUtil.getActiveEditor(event);
-               
-               Object[] data = (Object[]) ((Event) event.getTrigger()).data;
-               
-               if (selection instanceof TextSelection 
-                                       && editor instanceof BulkEditor) {
-                       TextSelection textSelection = (TextSelection) selection;
-                       BulkEditor bulkEditor = (BulkEditor) editor;
-                       
-                       LineAnnotationModel model = (LineAnnotationModel) bulkEditor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
-                       if (model != null) {
-                               Iterator iter = model.getAnnotationIterator(textSelection.getOffset(), textSelection.getLength(), true, true);
-                               
-                               Set<IAnnotatableEntity> annotatableEntities = new HashSet<IAnnotatableEntity>();
-                               while (iter.hasNext()) {
-                                       Object next = iter.next();
-                                       if (next instanceof LineAnnotation) {
-                                               Object entity = ((LineAnnotation) next).getEntity();
-                                               
-                                               if(entity instanceof IAnnotatableEntity){
-                                                       annotatableEntities.add((IAnnotatableEntity) entity);
-                                               }
-                                       }
-                               }
-                                                               
-                               AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), annotatableEntities, (MarkerType) data[0], (Boolean) data[1], bulkEditor);
-                               BulkEditorUtil.executeOperation(operation);
-                       }
-               }
-               return null;
-       }
+    @CanExecute
+    public boolean canExecute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
+            MHandledMenuItem menuItem){
+        boolean canExecute = false;
+        canExecute = selection instanceof IAnnotatableEntity;
+        menuItem.setVisible(canExecute);
+        return canExecute;
+    }
 }