1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.xmlhammer.gui.actions;
22
23 import java.net.URI;
24
25 import javax.swing.SwingUtilities;
26 import javax.xml.bind.JAXBException;
27 import javax.xml.transform.TransformerException;
28
29 import org.apache.log4j.Logger;
30 import org.bounce.RunnableAction;
31 import org.bounce.util.URIUtils;
32 import org.xmlhammer.gui.XMLHammer;
33 import org.xmlhammer.model.project.Project;
34
35 /***
36 * An action that can be used to open previously opened XML Hammer projects.
37 *
38 * @version $Revision: 1.9 $, $Date: 2008/03/05 22:13:43 $
39 * @author Edwin Dankert <edankert@gmail.com>
40 */
41 public class OpenPreviousProjectAction extends RunnableAction {
42 private static final long serialVersionUID = -702933390366968177L;
43
44 private URI uri = null;
45 private XMLHammer parent = null;
46
47 /***
48 * The constructor for the open previous XML Hammer projects action.
49 *
50 * @param parent the parent that opens the project.
51 */
52 public OpenPreviousProjectAction( XMLHammer parent, URI uri, int index) {
53 super( index+" "+URIUtils.getName( uri));
54
55 char[] chars = String.valueOf( index).toCharArray();
56
57 putValue( MNEMONIC_KEY, new Integer( chars[0]));
58
59 this.parent = parent;
60 this.uri = uri;
61 }
62
63 /***
64 * The implementation of the copy action.
65 */
66 public void run() {
67 parent.setWait( true);
68 parent.getStatusPanel().showView(null);
69 parent.getStatusPanel().getBase().setStatus("Opening "+uri.toString()+" ...");
70
71
72
73 Runnable runner = new Runnable() {
74 public void run() {
75 Project project = null;
76
77 try {
78 project = OpenAction.open(uri);
79 } catch ( JAXBException e) {
80 Logger.getLogger(getClass()).error( "JAXB Error", e);
81 } catch (TransformerException e) {
82 Logger.getLogger(getClass()).error( "Transformer Error", e);
83 } finally {
84 openProject(uri, project);
85 }
86 }
87 };
88
89
90 Thread thread = new Thread( runner);
91 thread.start();
92 }
93
94 private void openProject(final URI uri, final Project project) {
95 SwingUtilities.invokeLater( new Runnable() {
96 public void run() {
97 try {
98 if (project != null) {
99 parent.openProject( uri, project);
100 }
101 } finally {
102 parent.getStatusPanel().getBase().setStatus("Done");
103 parent.getStatusPanel().showView(parent.getProjectsView().getSelectedView());
104 parent.setWait(false);
105 }
106 }
107 });
108 }
109 }