Revision 596 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ProjectExtension.java
ProjectExtension.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig; |
2 | 2 |
|
3 |
import java.awt.Component; |
|
3 | 4 |
import java.io.File; |
5 |
import java.io.FileNotFoundException; |
|
4 | 6 |
import java.io.FileReader; |
5 | 7 |
import java.io.FileWriter; |
6 | 8 |
import java.text.DateFormat; |
7 | 9 |
import java.util.ArrayList; |
8 | 10 |
import java.util.Date; |
9 | 11 |
|
12 |
import javax.swing.JFileChooser; |
|
10 | 13 |
import javax.swing.JOptionPane; |
11 | 14 |
|
15 |
import org.exolab.castor.xml.MarshalException; |
|
12 | 16 |
import org.exolab.castor.xml.Marshaller; |
17 |
import org.exolab.castor.xml.ValidationException; |
|
13 | 18 |
|
19 |
import com.iver.andami.PluginServices; |
|
20 |
import com.iver.andami.plugins.Extension; |
|
21 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
14 | 22 |
import com.iver.cit.gvsig.project.ProjectFactory; |
15 | 23 |
import com.iver.cit.gvsig.project.ProjectWindow; |
16 | 24 |
import com.iver.cit.gvsig.project.castor.Project; |
17 |
import com.iver.mdiApp.App; |
|
18 |
import com.iver.mdiApp.AppStatus; |
|
19 |
import com.iver.mdiApp.Utilities; |
|
20 |
import com.iver.mdiApp.plugins.AbstractExtension; |
|
21 |
import com.iver.mdiApp.plugins.files.FileExtension; |
|
22 |
import com.iver.mdiApp.plugins.files.SelectedFile; |
|
23 |
import com.iver.mdiApp.ui.MDIApplicationContext; |
|
25 |
import com.iver.utiles.GenericFileFilter; |
|
24 | 26 |
import com.iver.utiles.XMLEntity; |
25 | 27 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
26 | 28 |
|
... | ... | |
31 | 33 |
* |
32 | 34 |
* @author Fernando Gonz?lez Cort?s |
33 | 35 |
*/ |
34 |
public class ProjectExtension extends AbstractExtension implements FileExtension {
|
|
36 |
public class ProjectExtension implements Extension {
|
|
35 | 37 |
private ArrayList tableExtensions = new ArrayList(); |
36 | 38 |
private ProjectWindow projectFrame; |
37 | 39 |
private Project p; |
... | ... | |
42 | 44 |
*/ |
43 | 45 |
public void inicializar() { |
44 | 46 |
p = ProjectFactory.createProject(); |
45 |
p.setName(Utilities.getMessage(this, "untitled"));
|
|
47 |
p.setName(PluginServices.getText(this, "untitled"));
|
|
46 | 48 |
p.setModified(false); |
47 | 49 |
projectFrame = new ProjectWindow(this); |
48 | 50 |
projectFrame.setProject(p); |
49 | 51 |
showProjectWindow(); |
50 |
App.instance.getMDIFrame().setTitle("gvSIG: " + Utilities.getMessage(this,
|
|
52 |
PluginServices.getMainFrame().setTitle("gvSIG: " + PluginServices.getText(this,
|
|
51 | 53 |
"sin_titulo")); |
52 | 54 |
} |
53 | 55 |
|
54 | 56 |
public void showProjectWindow(){ |
55 |
App.instance.getMDIContext().addView(projectFrame);
|
|
57 |
PluginServices.getMDIManager().addView(projectFrame);
|
|
56 | 58 |
} |
57 | 59 |
|
58 | 60 |
private void guardar(){ |
59 | 61 |
if (p.getPath() == null) { |
60 |
SelectedFile s = App.instance.getMDIContext().showFileChooser(this, |
|
61 |
new String[] { "xml" }, |
|
62 |
new String[] {Utilities.getMessage(this, |
|
63 |
"tipo_fichero_proyecto")}, |
|
64 |
Utilities.getMessage(this, "guardar_proyecto"), |
|
65 |
true, MDIApplicationContext.FILES_ONLY); |
|
66 |
if (s != null) escribirProyecto(s.getFile(), p); |
|
62 |
JFileChooser jfc = new JFileChooser(); |
|
63 |
jfc.addChoosableFileFilter(new GenericFileFilter("xml", "tipo_fichero_proyecto")); |
|
64 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){ |
|
65 |
escribirProyecto(jfc.getSelectedFile(), p); |
|
66 |
} |
|
67 | 67 |
} else { |
68 | 68 |
escribirProyecto(new File(p.getPath()), p); |
69 | 69 |
} |
... | ... | |
71 | 71 |
|
72 | 72 |
private boolean modificado(){ |
73 | 73 |
if (p.isModified()) { |
74 |
int res = JOptionPane.showConfirmDialog(App.instance.getMDIFrame(),
|
|
75 |
Utilities.getMessage(this, "guardar_cambios"),
|
|
76 |
Utilities.getMessage(this, "nuevo_proyecto"),
|
|
74 |
int res = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
|
|
75 |
PluginServices.getText(this, "guardar_cambios"),
|
|
76 |
PluginServices.getText(this, "nuevo_proyecto"),
|
|
77 | 77 |
JOptionPane.YES_NO_CANCEL_OPTION, |
78 | 78 |
JOptionPane.INFORMATION_MESSAGE); |
79 | 79 |
|
... | ... | |
90 | 90 |
/** |
91 | 91 |
* @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String) |
92 | 92 |
*/ |
93 |
public void updateUI(AppStatus status, String actionCommand) { |
|
94 |
try { |
|
93 |
public void execute(String actionCommand) { |
|
95 | 94 |
if (actionCommand.equals("NUEVO")) { |
96 | 95 |
//Si est? modificado se pregunta si se quiere guardar el anterior |
97 | 96 |
if (!modificado()) return; |
98 | 97 |
|
99 |
App.instance.getMDIContext().closeAllViews();
|
|
98 |
PluginServices.getMDIManager().closeAllViews();
|
|
100 | 99 |
p = ProjectFactory.createProject(); |
101 |
p.setName(Utilities.getMessage(this, "untitled"));
|
|
100 |
p.setName(PluginServices.getText(this, "untitled"));
|
|
102 | 101 |
p.setModified(false); |
103 | 102 |
projectFrame.setProject(p); |
104 | 103 |
showProjectWindow(); |
105 |
App.instance.getMDIFrame().setTitle("gvSIG: " + Utilities.getMessage(this,
|
|
104 |
PluginServices.getMainFrame().setTitle("gvSIG: " + PluginServices.getText(this,
|
|
106 | 105 |
"sin_titulo")); |
107 | 106 |
|
108 | 107 |
} else if (actionCommand.equals("ABRIR")) { |
109 | 108 |
//Si est? modificado se pregunta si se quiere guardar el anterior |
110 | 109 |
if (!modificado()) return; |
111 | 110 |
|
112 |
SelectedFile sf = App.instance.getMDIContext().showFileChooser(this, |
|
113 |
new String[] { "xml" }, |
|
114 |
new String[] { Utilities.getMessage(this, "tipo_fichero_proyecto")}, |
|
115 |
Utilities.getMessage(this, "abrir_proyecto"), false, |
|
116 |
MDIApplicationContext.FILES_ONLY); |
|
117 |
|
|
118 |
if (sf != null){ |
|
119 |
App.instance.getMDIContext().closeAllViews(); |
|
120 |
Object o = sf.read(); |
|
111 |
JFileChooser jfc = new JFileChooser(); |
|
112 |
jfc.addChoosableFileFilter(new GenericFileFilter("xml", "tipo_fichero_proyecto")); |
|
113 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){ |
|
114 |
PluginServices.getMDIManager().closeAllViews(); |
|
115 |
Project o = leerProyecto(jfc.getSelectedFile()); |
|
121 | 116 |
if (o != null){ |
122 |
p = (Project) o;
|
|
117 |
p = o; |
|
123 | 118 |
} |
124 | 119 |
projectFrame.setProject(p); |
125 | 120 |
projectFrame.refreshControls(); |
126 | 121 |
showProjectWindow(); |
127 |
}
|
|
122 |
}
|
|
128 | 123 |
} else if (actionCommand.equals("GUARDAR")) { |
129 | 124 |
guardar(); |
130 | 125 |
} |
131 |
} catch (Exception e) { |
|
132 |
App.instance.getNm().addError(e.getLocalizedMessage(), e); |
|
133 |
} |
|
134 | 126 |
} |
135 | 127 |
|
136 |
/** |
|
137 |
* @see com.iver.mdiApp.FileExtension#readFile(java.io.File) |
|
138 |
*/ |
|
139 |
public void write(File file, Object object) { |
|
140 |
escribirProyecto(file, (Project) object); |
|
141 |
} |
|
142 |
|
|
143 | 128 |
private void escribirProyecto(File file, Project p){ |
144 |
try { |
|
145 | 129 |
p.setPath(file.toString()); |
146 | 130 |
p.setModificationDate(DateFormat.getDateInstance().format(new Date())); |
147 | 131 |
p.setModified(false); |
... | ... | |
155 | 139 |
} catch (Exception e) { |
156 | 140 |
System.out.println("Exception marshal Proyecto " + e); |
157 | 141 |
} |
158 |
App.instance.getMDIFrame().setTitle("gvSIG: " + file.getName());
|
|
142 |
PluginServices.getMainFrame().setTitle("gvSIG: " + file.getName());
|
|
159 | 143 |
projectFrame.refreshControls(); |
160 |
} catch (Exception e) { |
|
161 |
e.printStackTrace(); |
|
162 |
App.instance.getNm().addError(Utilities.getMessage(this, |
|
163 |
"error_escritura"), e); |
|
164 |
} |
|
165 | 144 |
} |
166 | 145 |
|
167 | 146 |
/** |
168 | 147 |
* @see com.iver.mdiApp.FileExtension#writeFile(java.io.File) |
169 | 148 |
*/ |
170 |
public Object read(File file) {
|
|
149 |
public Project leerProyecto(File file) {
|
|
171 | 150 |
Project proj = null; |
172 |
try {
|
|
151 |
try {
|
|
173 | 152 |
File xmlFile = new File(file.getAbsolutePath()); |
174 |
FileReader reader = new FileReader(xmlFile); |
|
175 |
XmlTag tag=(XmlTag)XmlTag.unmarshal(reader); |
|
176 |
p=Project.createFromXML(new XMLEntity(tag)); |
|
177 |
} catch (Exception e) { |
|
178 |
App.instance.getNm().addError(Utilities.getMessage(this, |
|
179 |
"error_lectura"), e); |
|
180 |
e.printStackTrace(); |
|
181 |
} |
|
153 |
FileReader reader; |
|
154 |
reader = new FileReader(xmlFile); |
|
155 |
XmlTag tag=(XmlTag)XmlTag.unmarshal(reader); |
|
156 |
p=Project.createFromXML(new XMLEntity(tag)); |
|
157 |
} catch (FileNotFoundException e) { |
|
158 |
} catch (MarshalException e) { |
|
159 |
} catch (ValidationException e) { |
|
160 |
} catch (XMLException e) { |
|
161 |
} |
|
182 | 162 |
|
183 | 163 |
return proj; |
184 | 164 |
} |
185 | 165 |
|
186 | 166 |
/** |
187 |
* Registra un tipo de Tabla |
|
188 |
* |
|
189 |
* @param ext Clase con la informaci?n para leer el fichero y con la |
|
190 |
* descripci?n del tipo de fichero que es. |
|
191 |
*/ |
|
192 |
public void registerTableExtension(FileExtension ext) { |
|
193 |
tableExtensions.add(ext); |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* Obtiene todas las FileExtension's registradas hasta el momento |
|
198 |
* |
|
199 |
* @return array de FileExtension |
|
200 |
*/ |
|
201 |
public FileExtension[] getTableExtensions() { |
|
202 |
return (FileExtension[]) tableExtensions.toArray(new FileExtension[0]); |
|
203 |
} |
|
204 |
|
|
205 |
/* |
|
206 |
* @see com.iver.mdiApp.plugins.Extension#isVisible() |
|
207 |
* |
|
208 |
public boolean isVisible() { |
|
209 |
View f = App.instance.getMDIContext().getLastActiveView(); |
|
210 |
|
|
211 |
if (f == null) { |
|
212 |
return false; |
|
213 |
} |
|
214 |
|
|
215 |
return (f.getClass() == ProjectWindow.class); |
|
216 |
}*/ |
|
217 |
/** |
|
218 | 167 |
* @return |
219 | 168 |
*/ |
220 | 169 |
public Project getProject() { |
221 | 170 |
return p; |
222 | 171 |
} |
223 | 172 |
|
173 |
/** |
|
174 |
* @see com.iver.andami.plugins.Extension#isEnabled() |
|
175 |
*/ |
|
176 |
public boolean isEnabled() { |
|
177 |
return true; |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* @see com.iver.andami.plugins.Extension#isVisible() |
|
182 |
*/ |
|
183 |
public boolean isVisible() { |
|
184 |
return true; |
|
185 |
} |
|
186 |
|
|
224 | 187 |
} |
Also available in: Unified diff