root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 24524
History | View | Annotate | Download (11.8 KB)
1 | 7304 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.project.documents; |
||
42 | |||
43 | 7343 | caballero | import java.beans.PropertyChangeListener; |
44 | import java.beans.PropertyChangeSupport; |
||
45 | import java.io.Serializable; |
||
46 | import java.text.DateFormat; |
||
47 | import java.util.Date; |
||
48 | 9690 | caballero | import java.util.HashMap; |
49 | import java.util.Iterator; |
||
50 | 7304 | caballero | |
51 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
52 | 12826 | jaume | import com.hardcode.gdbms.engine.data.driver.DriverException; |
53 | 17093 | vcaballero | import com.iver.andami.PluginServices; |
54 | 7304 | caballero | import com.iver.andami.messages.NotificationManager; |
55 | import com.iver.andami.ui.mdiManager.IWindow; |
||
56 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
57 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
58 | import com.iver.cit.gvsig.project.Project; |
||
59 | import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
||
60 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
61 | 9044 | cesar | import com.iver.cit.gvsig.project.documents.gui.WindowData; |
62 | 7304 | caballero | import com.iver.utiles.XMLEntity; |
63 | import com.iver.utiles.extensionPoints.ExtensionPoint; |
||
64 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
65 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
66 | |||
67 | |||
68 | /**
|
||
69 | * Clase base de los elementos del proyecto (mapas, tablas y vistas)
|
||
70 | *
|
||
71 | * @author Fernando Gonz?lez Cort?s
|
||
72 | */
|
||
73 | public abstract class ProjectDocument implements Serializable { |
||
74 | 17093 | vcaballero | public static HashMap<String,Integer> NUMS = new HashMap<String,Integer>(); |
75 | 7304 | caballero | protected PropertyChangeSupport change; |
76 | protected Project project;
|
||
77 | protected int index; |
||
78 | protected String name; |
||
79 | protected String creationDate; |
||
80 | protected String owner; |
||
81 | protected String comment; |
||
82 | private boolean locked = false; |
||
83 | 9044 | cesar | protected WindowData windowData = null; |
84 | 10162 | caballero | private boolean isModified=false; |
85 | 7343 | caballero | private ProjectDocumentFactory projectDocumentFactory;
|
86 | 7304 | caballero | /**
|
87 | * Creates a new ProjectElement object.
|
||
88 | */
|
||
89 | public ProjectDocument() {
|
||
90 | creationDate = DateFormat.getDateInstance().format(new Date()); |
||
91 | change = new PropertyChangeSupport(this); |
||
92 | } |
||
93 | |||
94 | /**
|
||
95 | * @see java.lang.Object#toString()
|
||
96 | */
|
||
97 | public String toString() { |
||
98 | return name;
|
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Obtiene el nombre del elemento
|
||
103 | *
|
||
104 | * @return
|
||
105 | */
|
||
106 | public String getName() { |
||
107 | return name;
|
||
108 | } |
||
109 | |||
110 | /**
|
||
111 | * Establece el nombre del elemento
|
||
112 | *
|
||
113 | * @param string
|
||
114 | */
|
||
115 | public void setName(String string) { |
||
116 | String oldValue = name;
|
||
117 | name = string; |
||
118 | change.firePropertyChange("name", oldValue, name);
|
||
119 | } |
||
120 | |||
121 | /**
|
||
122 | * Obtiene la fecha de creaci?n del elemento
|
||
123 | *
|
||
124 | * @return
|
||
125 | */
|
||
126 | public String getCreationDate() { |
||
127 | return creationDate;
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * Obtiene el propietario del elemento
|
||
132 | *
|
||
133 | * @return
|
||
134 | */
|
||
135 | public String getOwner() { |
||
136 | return owner;
|
||
137 | } |
||
138 | |||
139 | /**
|
||
140 | * Establece la fecha de creaci?n del elemento.
|
||
141 | *
|
||
142 | * @param string
|
||
143 | */
|
||
144 | public void setCreationDate(String string) { |
||
145 | creationDate = string; |
||
146 | change.firePropertyChange("creationDate", creationDate, creationDate);
|
||
147 | } |
||
148 | |||
149 | /**
|
||
150 | * Establece el propietario del elemento
|
||
151 | *
|
||
152 | * @param string
|
||
153 | */
|
||
154 | public void setOwner(String string) { |
||
155 | owner = string; |
||
156 | change.firePropertyChange("owner", owner, owner);
|
||
157 | } |
||
158 | |||
159 | /**
|
||
160 | * Obtiene los comentarios del proyecto
|
||
161 | *
|
||
162 | * @return
|
||
163 | */
|
||
164 | public String getComment() { |
||
165 | return comment;
|
||
166 | } |
||
167 | |||
168 | /**
|
||
169 | * Establece los comentarios del proyecto
|
||
170 | *
|
||
171 | * @param string
|
||
172 | */
|
||
173 | public void setComment(String string) { |
||
174 | comment = string; |
||
175 | change.firePropertyChange("comment", comment, comment);
|
||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * A?ade un listener para los cambios en las bounded properties
|
||
180 | *
|
||
181 | * @param listener
|
||
182 | */
|
||
183 | public synchronized void addPropertyChangeListener( |
||
184 | PropertyChangeListener listener) {
|
||
185 | change.addPropertyChangeListener(listener); |
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | * DOCUMENT ME!
|
||
190 | *
|
||
191 | * @return DOCUMENT ME!
|
||
192 | * @throws XMLException
|
||
193 | * @throws SaveException
|
||
194 | */
|
||
195 | public XMLEntity getXMLEntity() throws SaveException { |
||
196 | XMLEntity xml = new XMLEntity();
|
||
197 | try{
|
||
198 | //xml.putProperty("nameRegister",this.getRegisterName());
|
||
199 | 7343 | caballero | xml.putProperty("className", projectDocumentFactory.getRegisterName());
|
200 | 7304 | caballero | xml.putProperty("comment", comment);
|
201 | xml.putProperty("creationDate", creationDate);
|
||
202 | xml.putProperty("name", name);
|
||
203 | xml.putProperty("owner", owner);
|
||
204 | }catch (Exception e) { |
||
205 | throw new SaveException(e,this.getClass().getName()); |
||
206 | } |
||
207 | return xml;
|
||
208 | } |
||
209 | |||
210 | /**
|
||
211 | * DOCUMENT ME!
|
||
212 | *
|
||
213 | * @param xml DOCUMENT ME!
|
||
214 | * @param p DOCUMENT ME!
|
||
215 | *
|
||
216 | * @return DOCUMENT ME!
|
||
217 | * @throws XMLException
|
||
218 | */
|
||
219 | 10626 | caballero | public static ProjectDocument createFromXML03(XMLEntity xml, Project p) throws XMLException{ |
220 | 7304 | caballero | ProjectDocument pe = null;
|
221 | |||
222 | Class clase;
|
||
223 | try {
|
||
224 | clase = Class.forName(xml.getStringProperty("className")); |
||
225 | pe = (ProjectDocument) clase.newInstance(); |
||
226 | } catch (ClassNotFoundException e) { |
||
227 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
228 | e); |
||
229 | } catch (InstantiationException e) { |
||
230 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
231 | e); |
||
232 | } catch (IllegalAccessException e) { |
||
233 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
234 | e); |
||
235 | } |
||
236 | |||
237 | return pe;
|
||
238 | } |
||
239 | |||
240 | /**
|
||
241 | * DOCUMENT ME!
|
||
242 | *
|
||
243 | * @param xml DOCUMENT ME!
|
||
244 | * @param p DOCUMENT ME!
|
||
245 | *
|
||
246 | * @return DOCUMENT ME!
|
||
247 | *
|
||
248 | * @throws XMLException
|
||
249 | * @throws DriverException
|
||
250 | * @throws DriverIOException
|
||
251 | * @throws OpenException
|
||
252 | */
|
||
253 | public static ProjectDocument createFromXML(XMLEntity xml, Project p) |
||
254 | 10626 | caballero | throws XMLException, OpenException {
|
255 | 7343 | caballero | ProjectDocumentFactory pde = null;
|
256 | 7304 | caballero | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
257 | ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
|
||
258 | 7343 | caballero | try {
|
259 | pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
|
||
260 | } catch (InstantiationException e) { |
||
261 | 17093 | vcaballero | NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
262 | 7343 | caballero | e); |
263 | } catch (IllegalAccessException e) { |
||
264 | 17093 | vcaballero | NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
265 | e); |
||
266 | }catch (Exception e) { |
||
267 | throw new OpenException(e,xml.getStringProperty("className")); |
||
268 | 7343 | caballero | } |
269 | 17093 | vcaballero | if (pde==null){ |
270 | Exception e=new Exception(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className")); |
||
271 | NotificationManager.showMessageWarning(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"),e); |
||
272 | throw new OpenException(e,xml.getStringProperty("className")); |
||
273 | } |
||
274 | 7754 | jmvivo | ProjectDocument pe=pde.create(p); |
275 | 9532 | caballero | pe.setProjectDocumentFactory(pde); |
276 | 7754 | jmvivo | return pe;
|
277 | 17093 | vcaballero | |
278 | 7304 | caballero | } |
279 | |||
280 | /**
|
||
281 | * DOCUMENT ME!
|
||
282 | *
|
||
283 | * @param xml DOCUMENT ME!
|
||
284 | * @param p DOCUMENT ME!
|
||
285 | *
|
||
286 | * @throws XMLException
|
||
287 | * @throws OpenException
|
||
288 | 10626 | caballero | * @throws ReadDriverException
|
289 | 7304 | caballero | */
|
290 | 7754 | jmvivo | public void setXMLEntity(XMLEntity xml) |
291 | 10626 | caballero | throws XMLException, OpenException, ReadDriverException{
|
292 | 9532 | caballero | |
293 | 7754 | jmvivo | this.setComment(xml.getStringProperty("comment")); |
294 | this.setCreationDate(xml.getStringProperty("creationDate")); |
||
295 | this.setName(xml.getStringProperty("name")); |
||
296 | this.setOwner(xml.getStringProperty("owner")); |
||
297 | 9532 | caballero | |
298 | 7754 | jmvivo | } |
299 | 7304 | caballero | |
300 | /**
|
||
301 | * DOCUMENT ME!
|
||
302 | *
|
||
303 | * @param xml DOCUMENT ME!
|
||
304 | * @param p DOCUMENT ME!
|
||
305 | *
|
||
306 | * @throws XMLException
|
||
307 | 10626 | caballero | * @throws ReadDriverException
|
308 | 7304 | caballero | * @throws DriverIOException
|
309 | */
|
||
310 | 7754 | jmvivo | public void setXMLEntity03(XMLEntity xml) |
311 | 10626 | caballero | throws XMLException, ReadDriverException{
|
312 | 9532 | caballero | |
313 | 7754 | jmvivo | this.setComment(xml.getStringProperty("comment")); |
314 | this.setCreationDate(xml.getStringProperty("creationDate")); |
||
315 | this.setName(xml.getStringProperty("name")); |
||
316 | this.setOwner(xml.getStringProperty("owner")); |
||
317 | 9532 | caballero | |
318 | 7754 | jmvivo | } |
319 | 7304 | caballero | |
320 | /**
|
||
321 | * DOCUMENT ME!
|
||
322 | *
|
||
323 | * @return DOCUMENT ME!
|
||
324 | */
|
||
325 | public Project getProject() {
|
||
326 | return project;
|
||
327 | } |
||
328 | /**
|
||
329 | * DOCUMENT ME!
|
||
330 | *
|
||
331 | * @param project DOCUMENT ME!
|
||
332 | */
|
||
333 | public void setProject(Project project, int index) { |
||
334 | this.project = project;
|
||
335 | this.index = index;
|
||
336 | } |
||
337 | public int getIndex() { |
||
338 | return index;
|
||
339 | } |
||
340 | |||
341 | /**
|
||
342 | * Locks this project element protecting it from deleting from the project.
|
||
343 | */
|
||
344 | public void lock() { |
||
345 | locked = true;
|
||
346 | } |
||
347 | |||
348 | /**
|
||
349 | * Unlocks this element. So, from now on, it can be removed from the project.
|
||
350 | */
|
||
351 | public void unlock() { |
||
352 | locked = false;
|
||
353 | } |
||
354 | |||
355 | /**
|
||
356 | * Tells whether if this project's element is locked/protected or not. A protected
|
||
357 | * element cannot be removed from the current project.
|
||
358 | *
|
||
359 | * @see <b>lock()</b> and <b>unlock()</b> methods.
|
||
360 | *
|
||
361 | * @return true if it is locked, false otherwise
|
||
362 | */
|
||
363 | public boolean isLocked() { |
||
364 | return locked;
|
||
365 | } |
||
366 | |||
367 | public abstract IWindow createWindow(); |
||
368 | public abstract IWindow getProperties(); |
||
369 | 7343 | caballero | public abstract void afterRemove(); |
370 | public abstract void afterAdd(); |
||
371 | 7304 | caballero | |
372 | 7343 | caballero | |
373 | public void setProjectDocumentFactory( |
||
374 | ProjectDocumentFactory projectDocumentFactory) { |
||
375 | this.projectDocumentFactory = projectDocumentFactory;
|
||
376 | 7304 | caballero | } |
377 | |||
378 | 7343 | caballero | public ProjectDocumentFactory getProjectDocumentFactory() {
|
379 | return projectDocumentFactory;
|
||
380 | } |
||
381 | 9532 | caballero | |
382 | 7754 | jmvivo | public abstract void exportToXML(XMLEntity root, Project project) throws SaveException ; |
383 | 9532 | caballero | |
384 | 10626 | caballero | public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, OpenException, ReadDriverException; |
385 | 9532 | caballero | |
386 | |||
387 | 10626 | caballero | public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, OpenException, ReadDriverException{ |
388 | 7754 | jmvivo | importFromXML(root,typeRoot, elementIndex,project,false);
|
389 | } |
||
390 | 9532 | caballero | |
391 | 9044 | cesar | /**
|
392 | * Get the layout properties (size, position, state of the components)
|
||
393 | * of the window associated with this ProjectDocument.
|
||
394 | * This is used to re-open the window with the same properties it had
|
||
395 | * when it was closed.
|
||
396 | 9532 | caballero | *
|
397 | 9044 | cesar | * @return A WindowData object storing the properties of the window.
|
398 | */
|
||
399 | public WindowData getWindowData() {
|
||
400 | return windowData;
|
||
401 | } |
||
402 | 9532 | caballero | |
403 | 9044 | cesar | /**
|
404 | * Store the layout properties (size, position, state of the components)
|
||
405 | * of the window associated with this ProjectDocument.
|
||
406 | * This is used to re-open the window with the same properties it had
|
||
407 | * when it was closed.
|
||
408 | */
|
||
409 | public void storeWindowData(WindowData data) { |
||
410 | windowData = data; |
||
411 | } |
||
412 | 9532 | caballero | |
413 | 10162 | caballero | public boolean isModified() { |
414 | return isModified;
|
||
415 | } |
||
416 | 9690 | caballero | |
417 | 10162 | caballero | public void setModified(boolean modified) { |
418 | isModified=modified; |
||
419 | } |
||
420 | |||
421 | 9690 | caballero | public static void initializeNUMS() { |
422 | NUMS.clear(); |
||
423 | ExtensionPoints extensionPoints = |
||
424 | ExtensionPointsSingleton.getInstance(); |
||
425 | ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("Documents");
|
||
426 | Iterator iterator = extensionPoint.keySet().iterator();
|
||
427 | while (iterator.hasNext()) {
|
||
428 | try {
|
||
429 | ProjectDocumentFactory documentFactory = (ProjectDocumentFactory)extensionPoint.create((String)iterator.next());
|
||
430 | NUMS.put(documentFactory.getRegisterName(),new Integer(0)); |
||
431 | } catch (InstantiationException e) { |
||
432 | e.printStackTrace(); |
||
433 | } catch (IllegalAccessException e) { |
||
434 | e.printStackTrace(); |
||
435 | } catch (ClassCastException e) { |
||
436 | e.printStackTrace(); |
||
437 | } |
||
438 | } |
||
439 | } |
||
440 | 7304 | caballero | } |