ref #6906 Migrate media view
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 14 Aug 2017 11:31:22 +0000 (13:31 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 15 Aug 2017 09:06:37 +0000 (11:06 +0200)
eu.etaxonomy.taxeditor.editor/fragment.e4xmi
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddImageGalleryHandler.java
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF

index 1eaf497c78126434c7e88ec33f1ae680a7f302ee..7bfd1547781e55cfe1470fe419eea9b392517f95 100644 (file)
         <children xsi:type="menu:HandledMenuItem" xmi:id="_eDZC0GhvEee3K4uKJljEYg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.removecharacter" label="Remove Character" command="_oBEz8GhvEee3K4uKJljEYg"/>
       </menus>
     </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"/>
+      <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"/>
+      </menus>
+    </elements>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="__mwtMDVpEee_b7RlBzTDRw" featurename="commands" parentElementId="xpath:/">
     <elements xsi:type="commands:Command" xmi:id="_BjF3ADVqEee_b7RlBzTDRw" elementId="eu.etaxonomy.taxeditor.editor.command.specimeneditor.create_field_unit" commandName="%command.commandname.1"/>
     <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"/>
   </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">
       <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_1D-38FvqEeerXd84Zrk_9A" coreExpressionId="isShowExperimentalFeatures"/>
-      <parameters xmi:id="_wJkmoEalEeeXMc6kSYO7Xg" elementId="eu.etaxonomy.taxeditor.editor.parameter.0" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.editor.workingSet.CharacterEditor"/>
+      <parameters xmi:id="_wJkmoEalEeeXMc6kSYO7Xg" elementId="eu.etaxonomy.taxeditor.editor.showView.parameter.charactereditor" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.editor.workingSet.CharacterEditor"/>
+    </elements>
+    <elements xsi:type="menu:HandledMenuItem" xmi:id="_cBaP4IDMEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.featuretreeeditor" label="%view.name.1" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/camera-photo.png" command="_WPjpoDSnEeek0dKsFNy--Q">
+      <parameters xmi:id="_cBaP4oDMEeeBD7P1FZoD-g" elementId="eu.etaxonomy.taxeditor.editor.showView.parameter.mediaview" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4"/>
     </elements>
   </fragments>
 </fragment:ModelFragments>
index f95dcdf810fb7260a9da61caca833db71980b1fb..d277730f2ddc6a4dfeb366f2d99680660f6aecc4 100644 (file)
                 name="%view.name.0"
                 restorable="true">
          </view>
-         <view
-               allowMultiple="false"
-               category="eu.etaxonomy.taxeditor.editor.category"
-               class="eu.etaxonomy.taxeditor.editor.view.media.MediaViewPart"
-               icon="icons/camera-photo.png"
-               id="eu.etaxonomy.taxeditor.editor.view.media"
-               name="%view.name.1"
-               restorable="true">
-         </view>
          <view
                category="eu.etaxonomy.taxeditor.editor.category"
                class="eu.etaxonomy.taxeditor.editor.view.concept.ConceptViewPart"
                </reference>
             </visibleWhen>
          </command>
-         <command
-               commandId="org.eclipse.ui.views.showView"
-               label="%command.label.5"
-               style="push">
-            <parameter
-                  name="org.eclipse.ui.views.showView.viewId"
-                  value="eu.etaxonomy.taxeditor.editor.view.media">
-            </parameter>
-            <visibleWhen
-                  checkEnabled="true">
-               <reference
-                     definitionId="isCdmStoreConnected">
-               </reference>
-            </visibleWhen>
-         </command>
          <command
                commandId="org.eclipse.ui.views.showView"
                label="%command.label.6"
       
       <menuContribution
             locationURI="popup:eu.etaxonomy.taxeditor.editor.view.media">
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.media.command.newimagegallery"
-               label="%command.label.37"
-               style="push">
-          <!--  <visibleWhen>
-               <or>
-                  <reference
-                        definitionId="isBulkEditor">
-                  </reference>
-                  <reference
-                        definitionId="isTaxonEditor">
-                  </reference>
-                  <reference
-                        definitionId="isDerivateEditor">
-                  </reference>
-               </or>
-            </visibleWhen>-->
-         </command>
-         <separator
-               name="taxeditor-editor.separator1"
-               visible="true">
-         </separator>
          <command
                commandId="eu.etaxonomy.taxeditor.editor.media.command.newimage"
                label="%command.label.38"
             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.AddImageGalleryHandler"
-            id="eu.etaxonomy.taxeditor.editor.media.command.newimagegallery"
-            name="%command.name.20">
-      </command>
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.media.category"
             defaultHandler="eu.etaxonomy.taxeditor.editor.view.media.handler.CreateMediaHandler"
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
new file mode 100644 (file)
index 0000000..c7063f1
--- /dev/null
@@ -0,0 +1,180 @@
+/**
+* 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.e4;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.EMenuService;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeNode;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.description.IDescribable;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.editor.view.media.MediaContentProvider;
+import eu.etaxonomy.taxeditor.editor.view.media.MediaLabelProvider;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
+import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
+import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
+
+/**
+ *
+ * @author pplitzner
+ * @since Aug 14, 2017
+ *
+ */
+public class MediaViewPartE4 extends AbstractCdmEditorPartE4
+        implements IPartContentHasDetails, IPartContentHasSupplementalData, IPostOperationEnabled {
+
+    private ISelectionChangedListener selectionChangedListener;
+
+    private TreeViewer viewer;
+
+       @Inject
+       private ESelectionService selService;
+
+       @PostConstruct
+       public void create(Composite parent, EMenuService menuService) {
+
+               viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL
+                               | SWT.V_SCROLL | SWT.FULL_SELECTION));
+
+               viewer.setContentProvider(new MediaContentProvider());
+               viewer.setLabelProvider(new MediaLabelProvider());
+               viewer.setAutoExpandLevel(2);
+
+               // Propagate selection from viewer
+        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
+        viewer.addSelectionChangedListener(selectionChangedListener);
+
+        //create context menu
+        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.mediaview");
+       }
+
+       @Inject
+       @Optional
+       public void selectionChanged(
+               @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
+               @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+               MPart thisPart){
+           if(activePart==thisPart){
+               return;
+           }
+
+           Object partObject = createPartObject(activePart);
+
+           if(partObject instanceof IPartContentHasMedia && ((IPartContentHasMedia) partObject).canAttachMedia()){
+               IStructuredSelection structuredSelection = createSelection(selection);
+               if(structuredSelection==null || structuredSelection.isEmpty()){
+                   showEmptyPage();
+                   return;
+               }
+
+
+               //        if (partObject instanceof DetailsViewPart || partObject instanceof SupplementalDataViewPart
+               //                || partObject instanceof DescriptiveViewPart) {
+               //            // do not show empty page as these views are also used to edit the
+               //            // description selected in this view
+               //            return;
+               //        }
+
+               Object firstElement = structuredSelection.getFirstElement();
+               if (partObject instanceof MultiPageTaxonEditor){
+                   if (firstElement != ((MultiPageTaxonEditor)partObject).getTaxon()){
+                       showEmptyPage();
+                       return;
+                   }
+               }
+               if(firstElement instanceof TreeNode){
+                   showViewer(new StructuredSelection(((TreeNode) firstElement).getValue()), activePart, viewer);
+                   return;
+               }
+               else if(firstElement!=null
+                       && firstElement instanceof IDescribable<?>){
+                   showViewer((IStructuredSelection) selection, activePart, viewer);
+                   return;
+               }
+           }
+           showEmptyPage();
+           return;
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       public void changed(Object object) {
+           viewer.expandToLevel(2);
+           viewer.refresh();
+           if(object != null){
+               StructuredSelection selection = new StructuredSelection(object);
+               viewer.setSelection(selection, true);
+           }
+//         //TODO: should be replaced with the possibility to set views dirty
+//         // when we move to Eclipse 4
+//         // take a look at ISaveblePart
+//         if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
+//             ((BulkEditor) part).forceDirty();
+//             IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
+//            ((BulkEditor) part).changed(selection.getFirstElement());
+//
+//         }
+//         if (part instanceof E4PartWrapper){
+//             part = WorkbenchUtility.getE4WrappedPart(part);
+//             if (part instanceof IDirtyMarkable){
+//                      StructuredSelection selection = new StructuredSelection(object);
+//                     ((IDirtyMarkable)part).changed(selection.getFirstElement());
+//             }
+//         }
+
+           super.changed(object);
+       }
+
+       @Override
+       protected String getViewName() {
+               return Messages.MediaViewPart_MEDIA;
+       }
+
+    public Viewer getViewer() {
+        return viewer;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean postOperation(CdmBase objectAffectedByOperation) {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onComplete() {
+        viewer.refresh();
+        return true;
+    }
+}
index 5f7a22a130202e67e5c0aeca3adaba2685fc72f6..796a7128d937a10a46769c85fa09a1ef24298cee 100644 (file)
@@ -3,12 +3,12 @@
  */
 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.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
+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 eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
@@ -18,51 +18,43 @@ import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.AddDerivedUnitFacadeMediaOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
-import eu.etaxonomy.taxeditor.editor.view.media.MediaViewPart;
+import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 
 /**
- * @author p.ciardelli
- * @version $Id: $
+ *
+ * @author pplitzner
+ * @since Aug 14, 2017
+ *
  */
-public class AddImageGalleryHandler extends AbstractHandler {
+public class AddImageGalleryHandler {
 
-       /** {@inheritDoc} */
-       @Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
+    /** {@inheritDoc} */
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MMenuItem menuItem) {
 
-           IWorkbenchPart part = HandlerUtil.getActivePart(event);
-           IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
+        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
 
-           if(part instanceof MediaViewPart){
-               Object viewerInput = ((MediaViewPart)part).getViewer().getInput();
-               try {
-                   if(viewerInput instanceof CdmBase){
-                       if(((CdmBase) viewerInput).isInstanceOf(Taxon.class)){
-                           Taxon taxon = HibernateProxyHelper.deproxy(viewerInput, Taxon.class);
+        Object viewerInput = mediaView.getViewer().getInput();
+        if(viewerInput instanceof CdmBase){
+            if(((CdmBase) viewerInput).isInstanceOf(Taxon.class)){
+                Taxon taxon = HibernateProxyHelper.deproxy(viewerInput, Taxon.class);
 
-                           AbstractPostOperation<?> operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(),
-                                   EditorUtil.getUndoContext(), taxon, postOperationEnabled, true);
+                AbstractPostOperation<?> operation = new CreateTaxonDescriptionOperation(menuItem.getLocalizedLabel(),
+                        EditorUtil.getUndoContext(), taxon, mediaView, true);
 
-                           AbstractUtility.executeOperation(operation);
-                       }
-                       else if(((CdmBase) viewerInput).isInstanceOf(SpecimenOrObservationBase.class)){
-                           SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(viewerInput, SpecimenOrObservationBase.class);
+                AbstractUtility.executeOperation(operation);
+            }
+            else if(((CdmBase) viewerInput).isInstanceOf(SpecimenOrObservationBase.class)){
+                SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(viewerInput, SpecimenOrObservationBase.class);
 
-                        AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(),
-                                   BulkEditorUtil.getUndoContext(), specimen, postOperationEnabled);
+                AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(menuItem.getLocalizedLabel(),
+                        BulkEditorUtil.getUndoContext(), specimen, mediaView);
 
-                           AbstractUtility.executeOperation(operation);
-                       }
-                   }
-               } catch (NotDefinedException e) {
-                   MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
-               }
-           }
-           return null;
-       }
+                AbstractUtility.executeOperation(operation);
+            }
+        }
+    }
 
 }
index 24768ea9e3c63bc4560f95297cc7abe35b4e8b59..2b7a59364e86aa535aaf3d479266fa1e2d934e1d 100644 (file)
@@ -59,6 +59,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.view.datasource.handler,
  eu.etaxonomy.taxeditor.view.derivateSearch,
  eu.etaxonomy.taxeditor.view.detail,
+ eu.etaxonomy.taxeditor.view.e4,
  eu.etaxonomy.taxeditor.view.specimenSearch,
  eu.etaxonomy.taxeditor.view.supplementaldata,
  org.eclipse.wb.swt