commit e6aba3060593b53c96c1f49e7ffa0e86cc6a5fb2
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Tue Aug 15 09:55:17 2017 +0200

    ref #6906 Migrate media view context menu

diff --git a/eu.etaxonomy.taxeditor.editor/fragment.e4xmi b/eu.etaxonomy.taxeditor.editor/fragment.e4xmi
index 7bfd15477..795ee0a2d 100644
--- a/eu.etaxonomy.taxeditor.editor/fragment.e4xmi
+++ b/eu.etaxonomy.taxeditor.editor/fragment.e4xmi
@@ -63,8 +63,30 @@
     </elements>
     <elements xsi:type="basic:PartDescriptor" xmi:id="_7GbckIDLEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4" label="%view.name.1" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/camera-photo.png" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4">
       <handlers xmi:id="_k638MIDSEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.view.media.handler.AddImageGalleryHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.media.handler.AddImageGalleryHandler" command="_fIAlsIDSEeeBD7P1FZoD-g"/>
+      <handlers xmi:id="_cedukIDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.view.media.handler.CreateMediaHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.media.handler.CreateMediaHandler" command="_VZ6twIDoEeeBD7P1FZoD-g"/>
+      <handlers xmi:id="_-rEh0IDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.view.media.handler.MoveImageUpInListHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.media.handler.MoveImageUpInListHandler" command="_459e0IDoEeeBD7P1FZoD-g"/>
+      <handlers xmi:id="_F_VZoIDpEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.view.media.handler.MoveImageDownInListHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.media.handler.MoveImageDownInListHandler" command="_7tiZsIDoEeeBD7P1FZoD-g"/>
+      <handlers xmi:id="_1LMfUIDuEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.view.media.handler.AddExistingMediaHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.media.handler.AddExistingMediaHandler" command="_0eupoIDoEeeBD7P1FZoD-g"/>
+      <handlers xmi:id="_vFCaIIGCEee6OIMIZFL1jw" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DeleteHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DeleteHandler" command="_jWmdEIGCEee6OIMIZFL1jw"/>
       <menus xsi:type="menu:PopupMenu" xmi:id="_UwO5kIDSEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.popupmenu.mediaview">
-        <children xsi:type="menu:HandledMenuItem" xmi:id="_XhTTAIDSEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandlabel37" label="%command.label.37" iconURI="" command="_fIAlsIDSEeeBD7P1FZoD-g"/>
+        <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_Z2OaYIF_Eee6OIMIZFL1jw" coreExpressionId="isCdmStoreConnected"/>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_XhTTAIDSEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.newImageGallery" label="%command.name.20" iconURI="" command="_fIAlsIDSEeeBD7P1FZoD-g"/>
+        <children xsi:type="menu:MenuSeparator" xmi:id="_0Z-zoIGEEee6OIMIZFL1jw" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.7"/>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_gljfwIDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.newImage" label="%command.name.21" command="_VZ6twIDoEeeBD7P1FZoD-g">
+          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_sHDNAIDoEeeBD7P1FZoD-g" coreExpressionId="isImageGallery"/>
+        </children>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_6amuAIDvEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.addExistingImage" label="%command.name.37" command="_0eupoIDoEeeBD7P1FZoD-g">
+          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_NQtSEIGEEee6OIMIZFL1jw" coreExpressionId="isImageGallery"/>
+        </children>
+        <children xsi:type="menu:MenuSeparator" xmi:id="_Xeq6IIDwEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.6"/>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_o4rk0IDuEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.moveImageUp" label="%command.name.22" command="_459e0IDoEeeBD7P1FZoD-g">
+          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_SXwqsIDwEeeBD7P1FZoD-g" coreExpressionId="isMedia"/>
+        </children>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_Akju0IDwEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.moveImageDown" label="%command.name.19" command="_7tiZsIDoEeeBD7P1FZoD-g">
+          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_wJU2wIGEEee6OIMIZFL1jw" coreExpressionId="isMedia"/>
+        </children>
+        <children xsi:type="menu:MenuSeparator" xmi:id="_W3Gj0IDwEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.3"/>
+        <children xsi:type="menu:HandledMenuItem" xmi:id="_y6pZwIGCEee6OIMIZFL1jw" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.deleteMedia" label="%command.label.41" command="_jWmdEIGCEee6OIMIZFL1jw"/>
       </menus>
     </elements>
   </fragments>
@@ -83,7 +105,12 @@
     <elements xsi:type="commands:Command" xmi:id="_K4DxEDumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.derivative.removeSingleReadFromSequence" commandName="%command.name.REMOVE_SINGLE_READ"/>
     <elements xsi:type="commands:Command" xmi:id="_N0wLsDumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.derivative.copySingleReadToClipBoard" commandName="%command.name.COPY_SINGLE_READ_TO_CLIPBOARD"/>
     <elements xsi:type="commands:Command" xmi:id="_YPp1wDvREeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.derivate.delete" commandName="Delete"/>
-    <elements xsi:type="commands:Command" xmi:id="_fIAlsIDSEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.media.command.newimagegallery" commandName="%command.label.37"/>
+    <elements xsi:type="commands:Command" xmi:id="_fIAlsIDSEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.media.command.newimagegallery" commandName="%command.name.20"/>
+    <elements xsi:type="commands:Command" xmi:id="_VZ6twIDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.media.command.newimage" commandName="%command.name.21"/>
+    <elements xsi:type="commands:Command" xmi:id="_0eupoIDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.media.command.useExistingImage" commandName="%command.name.37"/>
+    <elements xsi:type="commands:Command" xmi:id="_459e0IDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.media.command.moveimgup" commandName="%command.name.22"/>
+    <elements xsi:type="commands:Command" xmi:id="_7tiZsIDoEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.media.command.moveimgdown" commandName="%command.name.19"/>
+    <elements xsi:type="commands:Command" xmi:id="_jWmdEIGCEee6OIMIZFL1jw" elementId="eu.etaxonomy.taxeditor.editor.media.command.delete" commandName="Delete Media"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView">
     <elements xsi:type="menu:HandledMenuItem" xmi:id="_tvph4EalEeeXMc6kSYO7Xg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.featuretreeeditor" label="Character Editor" command="_WPjpoDSnEeek0dKsFNy--Q">
diff --git a/eu.etaxonomy.taxeditor.editor/plugin.xml b/eu.etaxonomy.taxeditor.editor/plugin.xml
index d277730f2..e4eabf407 100644
--- a/eu.etaxonomy.taxeditor.editor/plugin.xml
+++ b/eu.etaxonomy.taxeditor.editor/plugin.xml
@@ -862,63 +862,6 @@
       
       
       
-      <menuContribution
-            locationURI="popup:eu.etaxonomy.taxeditor.editor.view.media">
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.media.command.newimage"
-               label="%command.label.38"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isImageGallery">
-               </reference>
-            </visibleWhen>
-         </command>
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.media.command.useExistingImage"
-               label="%command.label.50"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isImageGallery">
-               </reference>
-            </visibleWhen>
-         </command>
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.media.command.moveimgdown"
-               label="%command.label.39"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isMedia">
-               </reference>
-            </visibleWhen>
-         </command>
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.media.command.moveimgup"
-               label="%command.label.40"
-               style="push">
-            <visibleWhen>
-               <reference
-                     definitionId="isMedia">
-               </reference>
-            </visibleWhen>
-         </command>
-         <separator
-               name="taxeditor-editor.separator2"
-               visible="true">
-         </separator>
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.media.command.delete"
-               label="%command.label.41"
-               style="push">
-         </command>
-         <command
-               commandId="org.eclipse.ui.file.save"
-               label="%command.label.42"
-               style="push">
-         </command>
-      </menuContribution>
       <menuContribution
             locationURI="popup:eu.etaxonomy.taxeditor.editor.view.concept">
          <menu
@@ -1371,36 +1314,6 @@
             id="eu.etaxonomy.taxeditor.editor.media.category"
             name="%category.name.3">
       </category>
-      <command
-            categoryId="eu.etaxonomy.taxeditor.editor.media.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.view.media.handler.MoveImageDownInListHandler"
-            id="eu.etaxonomy.taxeditor.editor.media.command.moveimgdown"
-            name="%command.name.19">
-      </command>
-      <command
-            categoryId="eu.etaxonomy.taxeditor.editor.media.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.view.media.handler.CreateMediaHandler"
-            id="eu.etaxonomy.taxeditor.editor.media.command.newimage"
-            name="%command.name.21">
-      </command>
-      <command
-            categoryId="eu.etaxonomy.taxeditor.editor.media.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.view.media.handler.AddExistingMediaHandler"
-            id="eu.etaxonomy.taxeditor.editor.media.command.useExistingImage"
-            name="%command.name.37">
-      </command>
-      <command
-            categoryId="eu.etaxonomy.taxeditor.editor.media.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.view.media.handler.MoveImageUpInListHandler"
-            id="eu.etaxonomy.taxeditor.editor.media.command.moveimgup"
-            name="%command.name.22">
-      </command>
-       <command
-            categoryId="eu.etaxonomy.taxeditor.editor.media.category"
-            defaultHandler="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DeleteHandler"
-            id="eu.etaxonomy.taxeditor.editor.media.command.delete"
-            name="%command.name.49">
-      </command>
       
       <category
             id="eu.etaxonomy.taxeditor.editor.new.category"
@@ -1849,7 +1762,7 @@
             id="eu.etaxonomy.taxeditor.descriptions.propertyTester"
             namespace="eu.etaxonomy.taxeditor.descriptions.propertyTester"
             properties="isMedia,isDescription,isDescriptionElement,isDeletable,isFeatureNodeContainer,isImageGallery,isTaxonEditor,isBulkEditor,isDerivateEditor, isIndividualsAssociation"
-            type="org.eclipse.jface.viewers.TreeSelection">
+            type="java.lang.Object">
       </propertyTester>
       <propertyTester
             class="eu.etaxonomy.taxeditor.editor.handler.SpecimenPropertyTester"
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java
index c7063f1ec..81e400692 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java
@@ -166,6 +166,7 @@ public class MediaViewPartE4 extends AbstractCdmEditorPartE4
      */
     @Override
     public boolean postOperation(CdmBase objectAffectedByOperation) {
+        changed(objectAffectedByOperation);
         return true;
     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java
index 4367e2577..8d8f20d81 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java
@@ -1,41 +1,47 @@
 package eu.etaxonomy.taxeditor.editor.view.media.handler;
 
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.common.NotDefinedException;
+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.MMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
 
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.editor.view.media.operation.AddExistingMediaToImageGalleryOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.MediaSelectionDialog;
 
-public class AddExistingMediaHandler extends CreateMediaHandler {
-
-    /**
-     * @param event
-     * @param postOperationEnabled
-     * @param description
-     */
-    @Override
-    protected void executeOperation(ExecutionEvent event, IPostOperationEnabled postOperationEnabled,
-            DescriptionBase description) {
-        AbstractPostOperation operation = null;
-        try {
+public class AddExistingMediaHandler  {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
+            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MMenuItem menuItem) {
+
+        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
+
+        if(description != null){
+            AbstractPostOperation operation = null;
             //select media
             Media media = MediaSelectionDialog.select(AbstractUtility.getShell(), null, null);
             if(media!=null){
                 // TODO use undo context specific to editor
-                operation = new AddExistingMediaToImageGalleryOperation(media, event.getCommand().getName(),
-                        EditorUtil.getUndoContext(), description, postOperationEnabled);
+                operation = new AddExistingMediaToImageGalleryOperation(media, menuItem.getLocalizedLabel(),
+                        EditorUtil.getUndoContext(), description, mediaView);
                 AbstractUtility.executeOperation(operation);
             }
-        } catch (NotDefinedException e) {
-            MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
         }
     }
 
+    @CanExecute
+    private boolean canExecute(){
+        return true;
+    }
+
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/CreateMediaHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/CreateMediaHandler.java
index 5acff5c53..c7971db18 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/CreateMediaHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/CreateMediaHandler.java
@@ -3,88 +3,44 @@
  */
 package eu.etaxonomy.taxeditor.editor.view.media.handler;
 
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreePath;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.handlers.HandlerUtil;
+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.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
 
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.editor.view.media.operation.AddMediaToImageGalleryOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 
 /**
- * <p>CreateMediaHandler class.</p>
  *
- * @author p.ciardelli
- * @version $Id: $
+ * @author pplitzner
+ * @since Aug 14, 2017
+ *
  */
-public class CreateMediaHandler extends AbstractHandler {
-
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
-	/** {@inheritDoc} */
-	@Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-		IWorkbenchPart part = HandlerUtil.getActivePart(event);
-		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
-
-
-		DescriptionBase description = null;
+public class CreateMediaHandler {
 
-		IEditorPart editor = HandlerUtil.getActiveEditor(event);
-		if (editor instanceof FormEditor) {
-			editor = ((FormEditor) editor).getActiveEditor();
-		}
-
-		ISelection selection = HandlerUtil.getCurrentSelection(event);
-		if (selection instanceof TreeSelection) {
-			TreePath[] paths = ((TreeSelection) selection).getPaths();
+    @Execute
+    public Object execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
+            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MMenuItem menuItem) {
 
-			int count = paths[0].getSegmentCount();
-
-			for (int i = 0; i < count; i++ ) {
-				if (paths[0].getSegment(i) instanceof DescriptionBase) {
-					description = (DescriptionBase) paths[0].getSegment(i);
-					break;
-				}
-			}
-		}
+        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
 
 		if(description != null){
-			executeOperation(event, postOperationEnabled, description);
+			AbstractPostOperation operation = null;
+			// TODO use undo context specific to editor
+            operation = new AddMediaToImageGalleryOperation(menuItem.getLocalizedLabel(),
+                    EditorUtil.getUndoContext(), description, mediaView);
+            AbstractUtility.executeOperation(operation);
 		}
 
 		return null;
 	}
 
-    /**
-     * @param event
-     * @param postOperationEnabled
-     * @param description
-     */
-    protected void executeOperation(ExecutionEvent event, IPostOperationEnabled postOperationEnabled,
-            DescriptionBase description) {
-        AbstractPostOperation operation = null;
-        try {
-        	// TODO use undo context specific to editor
-        	operation = new AddMediaToImageGalleryOperation(event.getCommand().getName(),
-        			EditorUtil.getUndoContext(), description, postOperationEnabled);
-        	AbstractUtility.executeOperation(operation);
-        } catch (NotDefinedException e) {
-        	MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
-        }
-    }
-
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java
index ce2ed524a..fafbafe6f 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java
@@ -3,93 +3,83 @@
  */
 package eu.etaxonomy.taxeditor.editor.view.media.handler;
 
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Status;
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.TreePath;
 import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
-import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
-import eu.etaxonomy.cdm.model.media.ImageFile;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
+import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
+import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
- * <p>DeleteMediaHandler class.</p>
  *
- * @author p.ciardelli
- * @version $Id: $
+ * @author pplitzner
+ * @since Aug 15, 2017
+ *
  */
-public class DeleteMediaHandler extends AbstractHandler {
-
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
-	/** {@inheritDoc} */
-	@Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-		IWorkbenchPart part = HandlerUtil.getActivePart(event);
-		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
+public class DeleteMediaHandler  {
 
-		IEditorPart editor = HandlerUtil.getActiveEditor(event);
-		if (editor instanceof FormEditor) {
-			editor = ((FormEditor) editor).getActiveEditor();
-		}
-		IEditorInput input = editor.getEditorInput();
-		if (input instanceof TaxonEditorInput) {
-			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
+            @Named(IServiceConstants.ACTIVE_SELECTION) Media media,
+            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
+            MMenuItem menuItem) {
 
-			ISelection selection = HandlerUtil.getCurrentSelection(event);
-			if (selection instanceof TreeSelection) {
-				TreePath[] paths = ((TreeSelection) selection).getPaths();
+        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
 
-				int count = paths[0].getSegmentCount();
-				DescriptionElementBase element = null;
-				for (int i = 0; i < count; i++ ) {
-					if (paths[0].getSegment(i) instanceof DescriptionElementBase) {
-						element = (DescriptionElementBase) paths[0].getSegment(i);
-						break;
-					}
-				}
-				ImageFile image = (ImageFile) paths[0].getLastSegment();
+        IEditorPart editor = null;
+        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart());
+        if (e4WrappedPart instanceof FormEditor) {
+            editor = (FormEditor) e4WrappedPart;
+            IEditorInput input = editor.getEditorInput();
+            if (input instanceof TaxonEditorInput) {
+                ISelection selection = mediaView.getViewer().getSelection();
+                if (selection instanceof TreeSelection) {
+                    TreePath[] paths = ((TreeSelection) selection).getPaths();
+                    int count = paths[0].getSegmentCount();
+                    DescriptionBase description = null;
+                    for (int i = 0; i < count; i++ ) {
+                        if (paths[0].getSegment(i) instanceof DescriptionBase) {
+                            description = (DescriptionBase) paths[0].getSegment(i);
+                            break;
+                        }
+                    }
+                    // TODO use undo context specific to editor
+                    MediaDeletionConfigurator config = new MediaDeletionConfigurator();
+                    AbstractPostOperation<?> operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView);
 
-				AbstractPostOperation<?> operation = null;
-				// TODO use undo context specific to editor
-                MediaDeletionConfigurator config = new MediaDeletionConfigurator();
+                    DeleteConfiguratorDialog dialog;
+                    dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM,  null,  Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
+                    int result_dialog= dialog.open();
+                    if (result_dialog != IStatus.OK){
+                        return;
+                    }
 
-                DeleteConfiguratorDialog dialog;
-                dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), Messages.DeleteMediaHandler_CONFIRM,  null,  Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0);
-                int result_dialog= dialog.open();
-                if (result_dialog != Status.OK){
-                    return null;
+                    AbstractUtility.executeOperation(operation);
                 }
+            }
+        }
 
-
-//
-//				    if (config.isOnlyRemoveFromGallery()){
-//				        operation = new RemoveImageFromDescriptionElementOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), taxon, image, element, postOperationEnabled);
-//				    }else{
-//				        operation = new DeleteMediaOperation(event.getCommand().getName(), EditorUtil.getUndoContext(), element, image, config, postOperationEnabled);
-//				    }
-
-                EditorUtil.executeOperation(operation);
-			}
-		}
-		return null;
-	}
-
-}
+    }
+}
\ No newline at end of file
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java
index a473d8deb..9cb928fb4 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java
@@ -1,85 +1,78 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.editor.view.media.handler;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.common.NotDefinedException;
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.TreePath;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
- * <p>MoveImageDownInListHandler class.</p>
  *
  * @author p.ciardelli
  * @created 11.08.2009
  * @version 1.0
  */
-public class MoveImageDownInListHandler extends AbstractHandler {
+public class MoveImageDownInListHandler  {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
+            @Named(IServiceConstants.ACTIVE_SELECTION) Media media,
+            MMenuItem menuItem) {
+
+        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
+
+        IEditorPart editor = null;
+        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart());
+        if (e4WrappedPart instanceof FormEditor) {
+            editor = (FormEditor) e4WrappedPart;
+            IEditorInput input = editor.getEditorInput();
+            if (input instanceof TaxonEditorInput) {
+                Taxon taxon = ((TaxonEditorInput) input).getTaxon();
 
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
-	/** {@inheritDoc} */
-	public Object execute(ExecutionEvent event) throws ExecutionException {
-		IWorkbenchPart part = HandlerUtil.getActivePart(event);
-		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
-				
-		IEditorPart editor = HandlerUtil.getActiveEditor(event);
-		if (editor instanceof FormEditor) {
-			editor = ((FormEditor) editor).getActiveEditor();
-		}
-		IEditorInput input = editor.getEditorInput();
-		if (input instanceof TaxonEditorInput) {
-			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
-			
-			ISelection selection = HandlerUtil.getCurrentSelection(event);
-						
-			if (selection instanceof TreeSelection) {
-				TreePath[] paths = ((TreeSelection) selection).getPaths();
-				int count = paths[0].getSegmentCount();
-				DescriptionBase description = null;
-				for (int i = 0; i < count; i++ ) {
-					if (paths[0].getSegment(i) instanceof DescriptionBase) {
-						description = (DescriptionBase) paths[0].getSegment(i);
-						break;
-					}
-				}				
-				Media media = (Media) paths[0].getLastSegment();
-				AbstractPostOperation operation = null;
-				try {
-					// TODO use undo context specific to editor
-					operation = new MoveMediaInListOperation(event.getCommand().getName(), 
-							EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, postOperationEnabled);
-					EditorUtil.executeOperation(operation);
-				} catch (NotDefinedException e) {
-					MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
-				}
-			}
-		} 
-		return null;
+                ISelection selection = mediaView.getViewer().getSelection();
+                if (selection instanceof TreeSelection) {
+                    TreePath[] paths = ((TreeSelection) selection).getPaths();
+                    int count = paths[0].getSegmentCount();
+                    DescriptionBase description = null;
+                    for (int i = 0; i < count; i++ ) {
+                        if (paths[0].getSegment(i) instanceof DescriptionBase) {
+                            description = (DescriptionBase) paths[0].getSegment(i);
+                            break;
+                        }
+                    }
+                    AbstractPostOperation operation = null;
+                    // TODO use undo context specific to editor
+                    operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(),
+                            EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, mediaView);
+                    AbstractUtility.executeOperation(operation);
+                }
+            }
+        }
 	}
 
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java
index ea525d205..f020333cb 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java
@@ -1,84 +1,78 @@
 /**
-* 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.editor.view.media.handler;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.common.NotDefinedException;
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.TreePath;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
- * <p>MoveImageUpInListHandler class.</p>
  *
  * @author p.ciardelli
  * @created 11.08.2009
  * @version 1.0
  */
-public class MoveImageUpInListHandler extends AbstractHandler {
+public class MoveImageUpInListHandler  {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
+            @Named(IServiceConstants.ACTIVE_SELECTION) Media media,
+            MMenuItem menuItem) {
+
+        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
+
+        IEditorPart editor = null;
+        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart());
+        if (e4WrappedPart instanceof FormEditor) {
+            editor = (FormEditor) e4WrappedPart;
+            IEditorInput input = editor.getEditorInput();
+            if (input instanceof TaxonEditorInput) {
+                Taxon taxon = ((TaxonEditorInput) input).getTaxon();
 
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
-	/** {@inheritDoc} */
-	public Object execute(ExecutionEvent event) throws ExecutionException {
-		IWorkbenchPart part = HandlerUtil.getActivePart(event);
-		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
-				
-		IEditorPart editor = HandlerUtil.getActiveEditor(event);
-		if (editor instanceof FormEditor) {
-			editor = ((FormEditor) editor).getActiveEditor();
-		}
-		IEditorInput input = editor.getEditorInput();
-		if (input instanceof TaxonEditorInput) {
-			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
-			
-			ISelection selection = HandlerUtil.getCurrentSelection(event);
-			if (selection instanceof TreeSelection) {
-				TreePath[] paths = ((TreeSelection) selection).getPaths();
-				int count = paths[0].getSegmentCount();
-				DescriptionBase element = null;
-				for (int i = 0; i < count; i++ ) {
-					if (paths[0].getSegment(i) instanceof DescriptionBase) {
-						element = (DescriptionBase) paths[0].getSegment(i);
-						break;
-					}
-				}				
-				Media media = (Media) paths[0].getLastSegment();
-				AbstractPostOperation operation = null;
-				try {
-					// TODO use undo context specific to editor
-					operation = new MoveMediaInListOperation(event.getCommand().getName(), 
-							EditorUtil.getUndoContext(), taxon, element, media, MoveMediaInListOperation.UP, postOperationEnabled);
-					EditorUtil.executeOperation(operation);
-				} catch (NotDefinedException e) {
-					MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
-				}
-			}
-		} 
-		return null;
-	}
+                ISelection selection = mediaView.getViewer().getSelection();
+                if (selection instanceof TreeSelection) {
+                    TreePath[] paths = ((TreeSelection) selection).getPaths();
+                    int count = paths[0].getSegmentCount();
+                    DescriptionBase element = null;
+                    for (int i = 0; i < count; i++ ) {
+                        if (paths[0].getSegment(i) instanceof DescriptionBase) {
+                            element = (DescriptionBase) paths[0].getSegment(i);
+                            break;
+                        }
+                    }
+                    AbstractPostOperation operation = null;
+                    // TODO use undo context specific to editor
+                    operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(),
+                            EditorUtil.getUndoContext(), taxon, element, media, MoveMediaInListOperation.UP, mediaView);
+                    AbstractUtility.executeOperation(operation);
+                }
+            }
+        }
+    }
 
 }
