*/
package eu.etaxonomy.taxeditor.event;
-import java.util.Collection;
-
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.ui.di.UIEventTopic;
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.swt.widgets.Shell;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
-import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
/**
* @author pplitzner
return shell;
}
- public static MPart getActiveEditorPart(EPartService partService){
- Collection<MPart> parts = partService.getParts();
- for (MPart part : parts) {
- if(part.getObject()!=null && part.getObject() instanceof IE4SavablePart
- && part.isVisible()){
- return part;
- }
- }
- return null;
- }
-
// private EventHandler testHandler;
//
// @Inject
*/
package eu.etaxonomy.taxeditor.view;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
}
@Override
- public Object getSelectionProvidingPart() {
- return selectionProvidingPart;
+ public MPart getSelectionProvidingPart() {
+ return (MPart) selectionProvidingPart;
}
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
-import eu.etaxonomy.taxeditor.event.EventUtility;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
@Optional@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
MPart thisPart, UISynchronize sync, EPartService partService){
- if(activePart==thisPart && EventUtility.getActiveEditorPart(partService)==null){
+ if(activePart==thisPart && WorkbenchUtility.getActiveEditorPart(partService)==null){
showEmptyPage();
return;
}
* {@inheritDoc}
*/
@Override
- public Object getSelectionProvidingPart() {
+ public MPart getSelectionProvidingPart() {
return selectionProvidingPart;
}
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
- , @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 = WorkbenchUtility.findSavablePart(editingPart);
- if(savablePart instanceof ISaveablePart){
- ((ISaveablePart) savablePart).doSave(new NullProgressMonitor());
- }
- else if(savablePart instanceof IE4SavablePart){
- ((IE4SavablePart) savablePart).save(new NullProgressMonitor());
- }
- else if(savablePart instanceof MPart){
- savePart(partService, commandService, handlerService, (MPart) savablePart);
- }
- }
+ @CanExecute
+ public boolean canExecute(EPartService partService) {
+ MPart activePart = partService.getActivePart();
+ if(activePart==null){
+ return false;
}
- }
-
- 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);
+ boolean isSavable = activePart.isDirty();
+ if(!isSavable){
+ if(activePart.getObject() instanceof ISelectionElementEditingPart){
+ MPart savablePart = WorkbenchUtility.findSavablePart((ISelectionElementEditingPart) activePart.getObject());
+ isSavable = savablePart.isDirty();
+ }
}
+ return isSavable;
}
- @CanExecute
- public boolean canExecute(EPartService partService) {
- return !partService.getDirtyParts().isEmpty();
- }
+ @Execute
+ void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
+ if(part.isDirty()){
+ partService.savePart(part, false);
+ }
+ else if(part.getObject() instanceof ISelectionElementEditingPart){
+ MPart savablePart = WorkbenchUtility.findSavablePart((ISelectionElementEditingPart) part.getObject());
+ partService.savePart(savablePart, false);
+ }
+ }
}
\ No newline at end of file
import java.io.File;
import java.net.URL;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.program.Program;
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
*/
public class WorkbenchUtility {
+ public static MPart getActiveEditorPart(EPartService partService){
+ Collection<MPart> parts = partService.getParts();
+ for (MPart part : parts) {
+ if(part.getObject()!=null && part.getObject() instanceof IE4SavablePart
+ && part.isVisible()){
+ return part;
+ }
+ }
+ return null;
+ }
+
/**
* Checks if the activePart is an E4 wrapper for a legacy part and returns
* that part
return baseLocation;
}
- public static Object findSavablePart(ISelectionElementEditingPart part){
- Object selectionProvidingPart = getE4WrappedPart(part.getSelectionProvidingPart());
- if(selectionProvidingPart instanceof ISelectionElementEditingPart){
- return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
- }
- else if(selectionProvidingPart instanceof IE4SavablePart || selectionProvidingPart instanceof MPart){
+ public static MPart findSavablePart(ISelectionElementEditingPart part){
+ MPart selectionProvidingPart = part.getSelectionProvidingPart();
+ if(selectionProvidingPart!=null){
+ if(selectionProvidingPart.getObject() instanceof ISelectionElementEditingPart){
+ return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
+ }
return selectionProvidingPart;
}
return null;
*/
package eu.etaxonomy.taxeditor.workbench.part;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+
/**
* Classes implementing this interface should be parts that edit elements
* coming from other parts via a selection change
* Returns the part that has provided the last selection
* @return the selection providing part
*/
- public Object getSelectionProvidingPart();
+ public MPart getSelectionProvidingPart();
}