1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.editor.action;
19
20 import org.eclipse.gef.ui.actions.UpdateAction;
21 import org.eclipse.jface.action.Action;
22 import org.eclipse.ui.IEditorPart;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.actions.ActionFactory;
25
26 import pl.edu.agh.cast.util.Messages;
27
28
29
30
31
32
33 public class SaveAllAction extends Action implements UpdateAction {
34
35
36
37
38 public SaveAllAction() {
39 setId(ActionFactory.SAVE_ALL.getId());
40 setText(Messages.SaveAllAction_0);
41 setToolTipText(Messages.SaveAllAction_1);
42 }
43
44
45
46
47
48
49
50 @Override
51 public void run() {
52 IEditorPart[] editors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getDirtyEditors();
53 if (editors != null) {
54 for (IEditorPart editor : editors) {
55 editor.doSave(null);
56 }
57 }
58 }
59
60
61
62
63
64
65 @Override
66 public void update() {
67 IEditorPart[] editors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getDirtyEditors();
68 if (editors == null || editors.length == 0) {
69 setEnabled(false);
70 } else {
71 setEnabled(true);
72 }
73
74 }
75 }