Project

General

Profile

Download (1.47 KB) Statistics
| Branch: | Tag: | Revision:
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
                isSavable = savablePart.isDirty();
27
            }
28
        }
29
        return isSavable;
30
    }
31

    
32

    
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
	    }
43

    
44
}
(6-6/8)