From 12257a98270d8b7aa7582616e89cb0f8dda73d9e Mon Sep 17 00:00:00 2001 From: Patrick Plitzner
true
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;
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
index 1a1974f34..8dc14f716 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
@@ -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);
}
}
diff --git a/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java
index b21d19689..1e16c0b52 100644
--- a/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java
+++ b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java
@@ -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
index 000000000..9c71c16c6
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/IE4SavablePart.java
@@ -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.
+ *
+ *