1
|
|
2
|
package eu.etaxonomy.taxeditor.workbench;
|
3
|
|
4
|
import javax.inject.Named;
|
5
|
|
6
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
7
|
import org.eclipse.e4.core.di.annotations.Execute;
|
8
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
9
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
10
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
11
|
|
12
|
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
|
13
|
|
14
|
public class SaveHandler {
|
15
|
|
16
|
@CanExecute
|
17
|
public boolean canExecute(EPartService partService) {
|
18
|
MPart activePart = partService.getActivePart();
|
19
|
if(activePart==null){
|
20
|
return false;
|
21
|
}
|
22
|
boolean isSavable = activePart.isDirty();
|
23
|
if(!isSavable){
|
24
|
if(activePart.getObject() instanceof ISelectionElementEditingPart){
|
25
|
MPart savablePart = WorkbenchUtility.findSavablePart((ISelectionElementEditingPart) activePart.getObject());
|
26
|
if(savablePart!=null){
|
27
|
isSavable = savablePart.isDirty();
|
28
|
}
|
29
|
}
|
30
|
}
|
31
|
return isSavable;
|
32
|
}
|
33
|
|
34
|
|
35
|
@Execute
|
36
|
void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
|
37
|
if(part.isDirty()){
|
38
|
partService.savePart(part, false);
|
39
|
}
|
40
|
else if(part.getObject() instanceof ISelectionElementEditingPart){
|
41
|
MPart savablePart = WorkbenchUtility.findSavablePart((ISelectionElementEditingPart) part.getObject());
|
42
|
partService.savePart(savablePart, false);
|
43
|
}
|
44
|
}
|
45
|
|
46
|
}
|