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.
*/
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;
}
@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()) {
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;
* If it is <code>true</code> then it is currently delaying a selection.
*/
private boolean isInDelay;
-
+
protected Object selectionProvidingPart;
isInDelay = true;
Display.getCurrent().asyncExec(delaySelection);
}
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void showViewer(Object part, IStructuredSelection selection) {
+ super.showViewer(part, selection);
selectionProvidingPart = part;
}
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();
--- /dev/null
+/**
+* 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);
+}