b21d196893081156d7f62974462ac246be4753f0
[taxeditor.git] / eu.etaxonomy.taxeditor.workbench / src / main / java / eu / etaxonomy / taxeditor / workbench / SaveHandler.java
1
2 package eu.etaxonomy.taxeditor.workbench;
3
4 import java.util.Collections;
5
6 import org.eclipse.core.commands.Command;
7 import org.eclipse.core.commands.ParameterizedCommand;
8 import org.eclipse.e4.core.commands.ECommandService;
9 import org.eclipse.e4.core.commands.EHandlerService;
10 import org.eclipse.e4.core.di.annotations.CanExecute;
11 import org.eclipse.e4.core.di.annotations.Execute;
12 import org.eclipse.e4.ui.workbench.modeling.EPartService;
13 import org.eclipse.ui.internal.e4.compatibility.CompatibilityPart;
14
15 public class SaveHandler {
16
17 @Execute
18 public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService) {
19 partService.getDirtyParts().forEach(mPart ->
20 {
21 if(mPart.getObject() instanceof CompatibilityPart){
22 //FIXME E4 remove when fully migrated
23 Command command = commandService.getCommand("org.eclipse.ui.file.save");
24 ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP);
25 handlerService.executeHandler(parameterizedCommand);
26 }
27 else{
28 partService.savePart(mPart, false);
29 }
30 });
31 }
32
33
34 @CanExecute
35 public boolean canExecute(EPartService partService) {
36 return !partService.getDirtyParts().isEmpty();
37 }
38
39 }