View Javadoc

1   /*
2    * $Id: SaveAllAction.java,v 1.12 2007/07/04 19:42:49 edankert Exp $
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
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   }