Revision e6f456aa
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.event; |
10 | 10 |
|
11 |
import java.util.Collection; |
|
12 |
|
|
13 | 11 |
import javax.annotation.PostConstruct; |
14 | 12 |
import javax.inject.Inject; |
15 | 13 |
import javax.inject.Named; |
... | ... | |
20 | 18 |
import org.eclipse.e4.ui.di.UIEventTopic; |
21 | 19 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
22 | 20 |
import org.eclipse.e4.ui.services.IServiceConstants; |
23 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
|
24 | 21 |
import org.eclipse.swt.widgets.Shell; |
25 | 22 |
|
26 | 23 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
27 | 24 |
import eu.etaxonomy.taxeditor.editor.ITaxonEditor; |
28 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
|
29 | 25 |
|
30 | 26 |
/** |
31 | 27 |
* @author pplitzner |
... | ... | |
98 | 94 |
return shell; |
99 | 95 |
} |
100 | 96 |
|
101 |
public static MPart getActiveEditorPart(EPartService partService){ |
|
102 |
Collection<MPart> parts = partService.getParts(); |
|
103 |
for (MPart part : parts) { |
|
104 |
if(part.getObject()!=null && part.getObject() instanceof IE4SavablePart |
|
105 |
&& part.isVisible()){ |
|
106 |
return part; |
|
107 |
} |
|
108 |
} |
|
109 |
return null; |
|
110 |
} |
|
111 |
|
|
112 | 97 |
// private EventHandler testHandler; |
113 | 98 |
// |
114 | 99 |
// @Inject |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java | ||
---|---|---|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.taxeditor.view; |
5 | 5 |
|
6 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
6 | 7 |
import org.eclipse.jface.viewers.ISelection; |
7 | 8 |
import org.eclipse.jface.viewers.IStructuredSelection; |
8 | 9 |
import org.eclipse.swt.widgets.Composite; |
... | ... | |
104 | 105 |
} |
105 | 106 |
|
106 | 107 |
@Override |
107 |
public Object getSelectionProvidingPart() {
|
|
108 |
return selectionProvidingPart; |
|
108 |
public MPart getSelectionProvidingPart() {
|
|
109 |
return (MPart) selectionProvidingPart;
|
|
109 | 110 |
} |
110 | 111 |
|
111 | 112 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java | ||
---|---|---|
38 | 38 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
39 | 39 |
import eu.etaxonomy.taxeditor.editor.IDistributionEditor; |
40 | 40 |
import eu.etaxonomy.taxeditor.editor.ITaxonEditor; |
41 |
import eu.etaxonomy.taxeditor.event.EventUtility; |
|
42 | 41 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
43 | 42 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
44 | 43 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
... | ... | |
135 | 134 |
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection, |
136 | 135 |
@Optional@Named(IServiceConstants.ACTIVE_PART)MPart activePart, |
137 | 136 |
MPart thisPart, UISynchronize sync, EPartService partService){ |
138 |
if(activePart==thisPart && EventUtility.getActiveEditorPart(partService)==null){
|
|
137 |
if(activePart==thisPart && WorkbenchUtility.getActiveEditorPart(partService)==null){
|
|
139 | 138 |
showEmptyPage(); |
140 | 139 |
return; |
141 | 140 |
} |
... | ... | |
302 | 301 |
* {@inheritDoc} |
303 | 302 |
*/ |
304 | 303 |
@Override |
305 |
public Object getSelectionProvidingPart() {
|
|
304 |
public MPart getSelectionProvidingPart() {
|
|
306 | 305 |
return selectionProvidingPart; |
307 | 306 |
} |
308 | 307 |
|
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package eu.etaxonomy.taxeditor.workbench; |
3 | 3 |
|
4 |
import java.util.Collections; |
|
5 |
|
|
6 | 4 |
import javax.inject.Named; |
7 | 5 |
|
8 |
import org.eclipse.core.commands.Command; |
|
9 |
import org.eclipse.core.commands.ParameterizedCommand; |
|
10 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
11 |
import org.eclipse.e4.core.commands.ECommandService; |
|
12 |
import org.eclipse.e4.core.commands.EHandlerService; |
|
13 | 6 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
14 | 7 |
import org.eclipse.e4.core.di.annotations.Execute; |
15 | 8 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
16 | 9 |
import org.eclipse.e4.ui.services.IServiceConstants; |
17 | 10 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
18 |
import org.eclipse.ui.ISaveablePart; |
|
19 |
import org.eclipse.ui.internal.e4.compatibility.CompatibilityPart; |
|
20 | 11 |
|
21 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
|
22 | 12 |
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart; |
23 | 13 |
|
24 | 14 |
public class SaveHandler { |
25 | 15 |
|
26 |
@Execute |
|
27 |
public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService |
|
28 |
, @Named(IServiceConstants.ACTIVE_PART)MPart activePart) { |
|
29 |
if(activePart.isDirty()){ |
|
30 |
savePart(partService, commandService, handlerService, activePart); |
|
31 |
} else { |
|
32 |
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart.getObject()); |
|
33 |
if(e4WrappedPart instanceof ISelectionElementEditingPart){ |
|
34 |
ISelectionElementEditingPart editingPart = (ISelectionElementEditingPart)e4WrappedPart; |
|
35 |
Object savablePart = WorkbenchUtility.findSavablePart(editingPart); |
|
36 |
if(savablePart instanceof ISaveablePart){ |
|
37 |
((ISaveablePart) savablePart).doSave(new NullProgressMonitor()); |
|
38 |
} |
|
39 |
else if(savablePart instanceof IE4SavablePart){ |
|
40 |
((IE4SavablePart) savablePart).save(new NullProgressMonitor()); |
|
41 |
} |
|
42 |
else if(savablePart instanceof MPart){ |
|
43 |
savePart(partService, commandService, handlerService, (MPart) savablePart); |
|
44 |
} |
|
45 |
} |
|
16 |
@CanExecute |
|
17 |
public boolean canExecute(EPartService partService) { |
|
18 |
MPart activePart = partService.getActivePart(); |
|
19 |
if(activePart==null){ |
|
20 |
return false; |
|
46 | 21 |
} |
47 |
} |
|
48 |
|
|
49 |
private void savePart(EPartService partService, ECommandService commandService, EHandlerService handlerService, |
|
50 |
MPart mPart) { |
|
51 |
if(mPart.getObject() instanceof CompatibilityPart){ |
|
52 |
//FIXME E4 remove when fully migrated |
|
53 |
Command command = commandService.getCommand("org.eclipse.ui.file.save"); |
|
54 |
ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP); |
|
55 |
handlerService.executeHandler(parameterizedCommand); |
|
56 |
} |
|
57 |
else{ |
|
58 |
partService.savePart(mPart, false); |
|
22 |
boolean isSavable = activePart.isDirty(); |
|
23 |
if(!isSavable){ |
|
24 |
if(activePart.getObject() instanceof ISelectionElementEditingPart){ |
|
25 |
MPart savablePart = WorkbenchUtility.findSavablePart((ISelectionElementEditingPart) activePart.getObject()); |
|
26 |
isSavable = savablePart.isDirty(); |
|
27 |
} |
|
59 | 28 |
} |
29 |
return isSavable; |
|
60 | 30 |
} |
61 | 31 |
|
62 | 32 |
|
63 |
@CanExecute |
|
64 |
public boolean canExecute(EPartService partService) { |
|
65 |
return !partService.getDirtyParts().isEmpty(); |
|
66 |
} |
|
33 |
@Execute |
|
34 |
void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) { |
|
35 |
if(part.isDirty()){ |
|
36 |
partService.savePart(part, false); |
|
37 |
} |
|
38 |
else if(part.getObject() instanceof ISelectionElementEditingPart){ |
|
39 |
MPart savablePart = WorkbenchUtility.findSavablePart((ISelectionElementEditingPart) part.getObject()); |
|
40 |
partService.savePart(savablePart, false); |
|
41 |
} |
|
42 |
} |
|
67 | 43 |
|
68 | 44 |
} |
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.io.File; |
12 | 12 |
import java.net.URL; |
13 |
import java.util.Collection; |
|
13 | 14 |
import java.util.List; |
14 | 15 |
|
15 | 16 |
import org.eclipse.core.runtime.Platform; |
... | ... | |
20 | 21 |
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement; |
21 | 22 |
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; |
22 | 23 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
24 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
|
23 | 25 |
import org.eclipse.swt.program.Program; |
24 | 26 |
|
25 | 27 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
... | ... | |
33 | 35 |
*/ |
34 | 36 |
public class WorkbenchUtility { |
35 | 37 |
|
38 |
public static MPart getActiveEditorPart(EPartService partService){ |
|
39 |
Collection<MPart> parts = partService.getParts(); |
|
40 |
for (MPart part : parts) { |
|
41 |
if(part.getObject()!=null && part.getObject() instanceof IE4SavablePart |
|
42 |
&& part.isVisible()){ |
|
43 |
return part; |
|
44 |
} |
|
45 |
} |
|
46 |
return null; |
|
47 |
} |
|
48 |
|
|
36 | 49 |
/** |
37 | 50 |
* Checks if the activePart is an E4 wrapper for a legacy part and returns |
38 | 51 |
* that part |
... | ... | |
61 | 74 |
return baseLocation; |
62 | 75 |
} |
63 | 76 |
|
64 |
public static Object findSavablePart(ISelectionElementEditingPart part){
|
|
65 |
Object selectionProvidingPart = getE4WrappedPart(part.getSelectionProvidingPart());
|
|
66 |
if(selectionProvidingPart instanceof ISelectionElementEditingPart){
|
|
67 |
return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
|
|
68 |
}
|
|
69 |
else if(selectionProvidingPart instanceof IE4SavablePart || selectionProvidingPart instanceof MPart){
|
|
77 |
public static MPart findSavablePart(ISelectionElementEditingPart part){
|
|
78 |
MPart selectionProvidingPart = part.getSelectionProvidingPart();
|
|
79 |
if(selectionProvidingPart!=null){
|
|
80 |
if(selectionProvidingPart.getObject() instanceof ISelectionElementEditingPart){
|
|
81 |
return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
|
|
82 |
}
|
|
70 | 83 |
return selectionProvidingPart; |
71 | 84 |
} |
72 | 85 |
return null; |
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/part/ISelectionElementEditingPart.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.workbench.part; |
10 | 10 |
|
11 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
12 |
|
|
11 | 13 |
/** |
12 | 14 |
* Classes implementing this interface should be parts that edit elements |
13 | 15 |
* coming from other parts via a selection change |
... | ... | |
28 | 30 |
* Returns the part that has provided the last selection |
29 | 31 |
* @return the selection providing part |
30 | 32 |
*/ |
31 |
public Object getSelectionProvidingPart();
|
|
33 |
public MPart getSelectionProvidingPart();
|
|
32 | 34 |
|
33 | 35 |
} |
Also available in: Unified diff
Fix state handling of save button/dirty flag for indirect edits(details)