ref #6596 Keep track of active "editor"
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Jun 2017 08:28:47 +0000 (10:28 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Jun 2017 08:28:59 +0000 (10:28 +0200)
 - Add IE4SavablePart to E4 parts that can be saved
 - SaveHandler will recurse through selection providing parts to find
savable parts that can be saved

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/IE4SavablePart.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/ISelectionElementEditingPart.java

index 53ee861dc95852efb56cf065c7778eda20685419..f2355066f9d3e0e7d0dd82c8383dcefbc0dba663 100644 (file)
@@ -73,6 +73,7 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
  * Displays the derivate hierarchy of the specimen specified in the editor input.
@@ -80,7 +81,7 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
  */
 public class DerivateView implements IPartContentHasFactualData, IConversationEnabled,
         ICdmEntitySessionEnabled, IDirtyMarkable, IPostOperationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
-        IContextListener {
+        IContextListener, IE4SavablePart {
 
     private static final String SPECIMEN_EDITOR = Messages.DerivateView_SPECIMEN_EDITOR;
 
@@ -316,7 +317,8 @@ public class DerivateView implements IPartContentHasFactualData, IConversationEn
     }
 
     @Persist
-    public void doSave(IProgressMonitor monitor) {
+    @Override
+    public void save(IProgressMonitor monitor) {
         String taskName = Messages.DerivateView_SAVING_HIERARCHY;
         monitor.beginTask(taskName, 3);
         if (!conversation.isBound()) {
index 40eedab684cb27e728a96f9d4f1b8a07d69255f4..9afbdeadbb145ce32d4eee3aedf4b06e2daaec33 100644 (file)
@@ -4,6 +4,7 @@
 package eu.etaxonomy.taxeditor.view;
 
 import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;
@@ -31,7 +32,7 @@ public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart impl
      * If it is <code>true</code> then it is currently delaying a selection.
      */
     private boolean isInDelay;
-    
+
     protected Object selectionProvidingPart;
 
 
@@ -94,6 +95,14 @@ public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart impl
             isInDelay = true;
             Display.getCurrent().asyncExec(delaySelection);
         }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void showViewer(Object part, IStructuredSelection selection) {
+        super.showViewer(part, selection);
         selectionProvidingPart = part;
     }
 
index 1a1974f340179d4f3cce30f38912efe69624fc7c..8dc14f716c0111291db7b04355a9229657ab77fd 100644 (file)
@@ -251,8 +251,7 @@ public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartC
                                         TaxonRelationship rel = rels.iterator().next();
                                         if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
                                                 getViewer().setInput(rel);
-                                                showViewer();
-//                                               super.showViewer(part, selection);
+                                                 super.showViewer(part, selection);
                                                  return;
                                         }
                                 }
@@ -262,8 +261,7 @@ public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartC
                }
         }
         getViewer().setInput(element);
-        showViewer();
-//        super.showViewer(part, selection);
+        super.showViewer(part, selection);
     }
 }
 
index b21d196893081156d7f62974462ac246be4753f0..1e16c0b526efb80fbd6b604cbaaecc258c564cfe 100644 (file)
@@ -3,34 +3,72 @@ package eu.etaxonomy.taxeditor.workbench;
 
 import java.util.Collections;
 
+import javax.inject.Named;
+
 import org.eclipse.core.commands.Command;
 import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.e4.core.commands.ECommandService;
 import org.eclipse.e4.core.commands.EHandlerService;
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.ui.ISaveablePart;
 import org.eclipse.ui.internal.e4.compatibility.CompatibilityPart;
 
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
+import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
+
 public class SaveHandler {
 
        @Execute
-       public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService) {
-           partService.getDirtyParts().forEach(mPart ->
-           {
-               if(mPart.getObject() instanceof CompatibilityPart){
-                   //FIXME E4 remove when fully migrated
-                   Command command = commandService.getCommand("org.eclipse.ui.file.save");
-                ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP);
-                   handlerService.executeHandler(parameterizedCommand);
-               }
-               else{
-                   partService.savePart(mPart, false);
-               }
-           });
+       public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService
+               , @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
+           if(activePart.isDirty()){
+               savePart(partService, commandService, handlerService, activePart);
+           } else {
+            Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart.getObject());
+            if(e4WrappedPart instanceof ISelectionElementEditingPart){
+                ISelectionElementEditingPart editingPart = (ISelectionElementEditingPart)e4WrappedPart;
+                Object savablePart = findSavablePart(editingPart);
+                if(savablePart instanceof ISaveablePart){
+                    ((ISaveablePart) savablePart).doSave(new NullProgressMonitor());
+                }
+                else if(savablePart instanceof IE4SavablePart){
+                    ((IE4SavablePart) savablePart).save(new NullProgressMonitor());
+                }
+            }
+        }
+       }
+
+       private Object findSavablePart(ISelectionElementEditingPart part){
+           Object selectionProvidingPart = part.getSelectionProvidingPart();
+           if(selectionProvidingPart instanceof ISaveablePart || selectionProvidingPart instanceof IE4SavablePart){
+               return selectionProvidingPart;
+           }
+           else if(selectionProvidingPart instanceof ISelectionElementEditingPart){
+               return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
+           }
+           return null;
        }
 
 
+    private void savePart(EPartService partService, ECommandService commandService, EHandlerService handlerService,
+            MPart mPart) {
+        if(mPart.getObject() instanceof CompatibilityPart){
+            //FIXME E4 remove when fully migrated
+            Command command = commandService.getCommand("org.eclipse.ui.file.save");
+            ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP);
+            handlerService.executeHandler(parameterizedCommand);
+        }
+        else{
+            partService.savePart(mPart, false);
+        }
+    }
+
+
        @CanExecute
        public boolean canExecute(EPartService partService) {
            return !partService.getDirtyParts().isEmpty();
diff --git a/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/IE4SavablePart.java b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/IE4SavablePart.java
new file mode 100644 (file)
index 0000000..9c71c16
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+* Copyright (C) 2017 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.workbench.part;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * This interface is used to be able to save a part when it is providing
+ * an element which is edited in another part.
+ *
+ * <br>
+ * This interface is used as a temporary workaround during e4 migration
+ * for simulating the IEditorPart behavior of editors VS views
+ *
+ * @see ISelectionElementEditingPart
+ * @author pplitzner
+ * @since Jun 28, 2017
+ *
+ */
+public interface IE4SavablePart {
+    //FIXME E4
+
+    /**
+     * Save this part
+     * @param monitor the progress monitor for long running save actions
+     */
+    public void save(IProgressMonitor monitor);
+}
index 65ed5e3d648ad80b11cc06e11dae384e873d1636..9357405feac1f5e307b5b2b27690152e0dfd5b16 100644 (file)
@@ -15,6 +15,7 @@ package eu.etaxonomy.taxeditor.workbench.part;
  * This interface is used as a temporary workaround during e4 migration
  * for simulating the IEditorPart behavior of editors VS views
  *
+ *@see IE4SavablePart
  * @author pplitzner
  * @since Jun 27, 2017
  *