1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.xmlhammer.gui.actions;
23
24 import java.awt.Toolkit;
25 import java.awt.event.InputEvent;
26 import java.awt.event.KeyEvent;
27 import java.io.File;
28 import java.net.URI;
29
30 import javax.swing.ImageIcon;
31 import javax.swing.KeyStroke;
32
33 import org.bounce.RunnableAction;
34 import org.xmlhammer.gui.ProjectView;
35 import org.xmlhammer.gui.ProjectsView;
36 import org.xmlhammer.gui.XMLHammer;
37
38 /***
39 * An action that can be used to save all open XML Hammer Projects.
40 *
41 * @version $Revision: 1.12 $, $Date: 2007/07/04 19:42:49 $
42 * @author Edwin Dankert <edankert@gmail.com>
43 */
44 public class SaveAllAction extends RunnableAction {
45 private static final long serialVersionUID = 877386686709976889L;
46
47 private XMLHammer parent = null;
48
49 /***
50 * The constructor for the action which allows saving all open projects.
51 *
52 * @param parent the XML Hammer parent.
53 */
54 public SaveAllAction( XMLHammer parent) {
55 super( "Save All");
56
57 putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_MASK, false));
58 putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/etool16/saveall_edit.gif")));
59 putValue( SHORT_DESCRIPTION, "Save all Projects");
60
61 this.parent = parent;
62
63 setEnabled( false);
64 }
65
66 /***
67 * The implementation of the save all action, called
68 * after a user action.
69 */
70 public void run() {
71 ProjectsView projects = parent.getProjectsView();
72
73 for ( int i = projects.getViewCount()-1; i >= 0; i--) {
74 ProjectView view = projects.getViewAt(i);
75 URI uri = view.getURI();
76 File file = null;
77
78 if ( uri != null) {
79 file = new File( uri);
80 }
81
82 if ( file == null) {
83 SaveAsAction.saveAs(parent);
84 } else {
85 SaveAction.save(parent, view, uri, file);
86 }
87 }
88 }
89 }