svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 35756
History | View | Annotate | Download (12.5 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 | 24529 | vcaballero | import java.util.ArrayList; |
48 | 7343 | caballero | import java.util.Date; |
49 | 9690 | caballero | import java.util.HashMap; |
50 | import java.util.Iterator; |
||
51 | 7304 | caballero | |
52 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
53 | 12826 | jaume | import com.hardcode.gdbms.engine.data.driver.DriverException; |
54 | 17093 | vcaballero | import com.iver.andami.PluginServices; |
55 | 7304 | caballero | import com.iver.andami.messages.NotificationManager; |
56 | import com.iver.andami.ui.mdiManager.IWindow; |
||
57 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
58 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
59 | import com.iver.cit.gvsig.project.Project; |
||
60 | import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
||
61 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
62 | 9044 | cesar | import com.iver.cit.gvsig.project.documents.gui.WindowData; |
63 | 7304 | caballero | import com.iver.utiles.XMLEntity; |
64 | import com.iver.utiles.extensionPoints.ExtensionPoint; |
||
65 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
66 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
67 | |||
68 | |||
69 | /**
|
||
70 | * Clase base de los elementos del proyecto (mapas, tablas y vistas)
|
||
71 | *
|
||
72 | * @author Fernando Gonz?lez Cort?s
|
||
73 | */
|
||
74 | public abstract class ProjectDocument implements Serializable { |
||
75 | 17093 | vcaballero | public static HashMap<String,Integer> NUMS = new HashMap<String,Integer>(); |
76 | 7304 | caballero | protected PropertyChangeSupport change; |
77 | protected Project project;
|
||
78 | protected int index; |
||
79 | protected String name; |
||
80 | protected String creationDate; |
||
81 | protected String owner; |
||
82 | protected String comment; |
||
83 | private boolean locked = false; |
||
84 | 9044 | cesar | protected WindowData windowData = null; |
85 | 10162 | caballero | private boolean isModified=false; |
86 | 7343 | caballero | private ProjectDocumentFactory projectDocumentFactory;
|
87 | 24529 | vcaballero | |
88 | private ArrayList<ProjectDocumentListener> projectDocListener = new ArrayList<ProjectDocumentListener>(); |
||
89 | |||
90 | 7304 | caballero | /**
|
91 | * Creates a new ProjectElement object.
|
||
92 | */
|
||
93 | public ProjectDocument() {
|
||
94 | creationDate = DateFormat.getDateInstance().format(new Date()); |
||
95 | change = new PropertyChangeSupport(this); |
||
96 | } |
||
97 | |||
98 | /**
|
||
99 | * @see java.lang.Object#toString()
|
||
100 | */
|
||
101 | public String toString() { |
||
102 | return name;
|
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | * Obtiene el nombre del elemento
|
||
107 | *
|
||
108 | * @return
|
||
109 | */
|
||
110 | public String getName() { |
||
111 | return name;
|
||
112 | } |
||
113 | |||
114 | /**
|
||
115 | * Establece el nombre del elemento
|
||
116 | *
|
||
117 | * @param string
|
||
118 | */
|
||
119 | public void setName(String string) { |
||
120 | String oldValue = name;
|
||
121 | name = string; |
||
122 | change.firePropertyChange("name", oldValue, name);
|
||
123 | } |
||
124 | |||
125 | /**
|
||
126 | * Obtiene la fecha de creaci?n del elemento
|
||
127 | *
|
||
128 | * @return
|
||
129 | */
|
||
130 | public String getCreationDate() { |
||
131 | return creationDate;
|
||
132 | } |
||
133 | |||
134 | /**
|
||
135 | * Obtiene el propietario del elemento
|
||
136 | *
|
||
137 | * @return
|
||
138 | */
|
||
139 | public String getOwner() { |
||
140 | return owner;
|
||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * Establece la fecha de creaci?n del elemento.
|
||
145 | *
|
||
146 | * @param string
|
||
147 | */
|
||
148 | public void setCreationDate(String string) { |
||
149 | creationDate = string; |
||
150 | change.firePropertyChange("creationDate", creationDate, creationDate);
|
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * Establece el propietario del elemento
|
||
155 | *
|
||
156 | * @param string
|
||
157 | */
|
||
158 | public void setOwner(String string) { |
||
159 | owner = string; |
||
160 | change.firePropertyChange("owner", owner, owner);
|
||
161 | } |
||
162 | |||
163 | /**
|
||
164 | * Obtiene los comentarios del proyecto
|
||
165 | *
|
||
166 | * @return
|
||
167 | */
|
||
168 | public String getComment() { |
||
169 | return comment;
|
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * Establece los comentarios del proyecto
|
||
174 | *
|
||
175 | * @param string
|
||
176 | */
|
||
177 | public void setComment(String string) { |
||
178 | comment = string; |
||
179 | change.firePropertyChange("comment", comment, comment);
|
||
180 | } |
||
181 | |||
182 | /**
|
||
183 | * A?ade un listener para los cambios en las bounded properties
|
||
184 | *
|
||
185 | * @param listener
|
||
186 | */
|
||
187 | public synchronized void addPropertyChangeListener( |
||
188 | PropertyChangeListener listener) {
|
||
189 | change.addPropertyChangeListener(listener); |
||
190 | } |
||
191 | |||
192 | /**
|
||
193 | * DOCUMENT ME!
|
||
194 | *
|
||
195 | * @return DOCUMENT ME!
|
||
196 | * @throws XMLException
|
||
197 | * @throws SaveException
|
||
198 | */
|
||
199 | public XMLEntity getXMLEntity() throws SaveException { |
||
200 | XMLEntity xml = new XMLEntity();
|
||
201 | try{
|
||
202 | //xml.putProperty("nameRegister",this.getRegisterName());
|
||
203 | 7343 | caballero | xml.putProperty("className", projectDocumentFactory.getRegisterName());
|
204 | 7304 | caballero | xml.putProperty("comment", comment);
|
205 | xml.putProperty("creationDate", creationDate);
|
||
206 | xml.putProperty("name", name);
|
||
207 | xml.putProperty("owner", owner);
|
||
208 | }catch (Exception e) { |
||
209 | throw new SaveException(e,this.getClass().getName()); |
||
210 | } |
||
211 | return xml;
|
||
212 | } |
||
213 | |||
214 | /**
|
||
215 | * DOCUMENT ME!
|
||
216 | *
|
||
217 | * @param xml DOCUMENT ME!
|
||
218 | * @param p DOCUMENT ME!
|
||
219 | *
|
||
220 | * @return DOCUMENT ME!
|
||
221 | * @throws XMLException
|
||
222 | */
|
||
223 | 10626 | caballero | public static ProjectDocument createFromXML03(XMLEntity xml, Project p) throws XMLException{ |
224 | 7304 | caballero | ProjectDocument pe = null;
|
225 | |||
226 | Class clase;
|
||
227 | try {
|
||
228 | clase = Class.forName(xml.getStringProperty("className")); |
||
229 | pe = (ProjectDocument) clase.newInstance(); |
||
230 | } catch (ClassNotFoundException e) { |
||
231 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
232 | e); |
||
233 | } catch (InstantiationException e) { |
||
234 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
235 | e); |
||
236 | } catch (IllegalAccessException e) { |
||
237 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
238 | e); |
||
239 | } |
||
240 | |||
241 | return pe;
|
||
242 | } |
||
243 | |||
244 | /**
|
||
245 | * DOCUMENT ME!
|
||
246 | *
|
||
247 | * @param xml DOCUMENT ME!
|
||
248 | * @param p DOCUMENT ME!
|
||
249 | *
|
||
250 | * @return DOCUMENT ME!
|
||
251 | *
|
||
252 | * @throws XMLException
|
||
253 | * @throws DriverException
|
||
254 | * @throws DriverIOException
|
||
255 | * @throws OpenException
|
||
256 | */
|
||
257 | public static ProjectDocument createFromXML(XMLEntity xml, Project p) |
||
258 | 10626 | caballero | throws XMLException, OpenException {
|
259 | 7343 | caballero | ProjectDocumentFactory pde = null;
|
260 | 7304 | caballero | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
261 | ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
|
||
262 | 7343 | caballero | try {
|
263 | pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
|
||
264 | } catch (InstantiationException e) { |
||
265 | 17093 | vcaballero | NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
266 | 7343 | caballero | e); |
267 | } catch (IllegalAccessException e) { |
||
268 | 17093 | vcaballero | NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
269 | e); |
||
270 | }catch (Exception e) { |
||
271 | throw new OpenException(e,xml.getStringProperty("className")); |
||
272 | 7343 | caballero | } |
273 | 17093 | vcaballero | if (pde==null){ |
274 | Exception e=new Exception(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className")); |
||
275 | NotificationManager.showMessageWarning(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"),e); |
||
276 | throw new OpenException(e,xml.getStringProperty("className")); |
||
277 | } |
||
278 | 7754 | jmvivo | ProjectDocument pe=pde.create(p); |
279 | 9532 | caballero | pe.setProjectDocumentFactory(pde); |
280 | 7754 | jmvivo | return pe;
|
281 | 17093 | vcaballero | |
282 | 7304 | caballero | } |
283 | |||
284 | /**
|
||
285 | * DOCUMENT ME!
|
||
286 | *
|
||
287 | * @param xml DOCUMENT ME!
|
||
288 | * @param p DOCUMENT ME!
|
||
289 | *
|
||
290 | * @throws XMLException
|
||
291 | * @throws OpenException
|
||
292 | 10626 | caballero | * @throws ReadDriverException
|
293 | 7304 | caballero | */
|
294 | 7754 | jmvivo | public void setXMLEntity(XMLEntity xml) |
295 | 10626 | caballero | throws XMLException, OpenException, ReadDriverException{
|
296 | 9532 | caballero | |
297 | 7754 | jmvivo | this.setComment(xml.getStringProperty("comment")); |
298 | this.setCreationDate(xml.getStringProperty("creationDate")); |
||
299 | this.setName(xml.getStringProperty("name")); |
||
300 | this.setOwner(xml.getStringProperty("owner")); |
||
301 | 9532 | caballero | |
302 | 7754 | jmvivo | } |
303 | 7304 | caballero | |
304 | /**
|
||
305 | * DOCUMENT ME!
|
||
306 | *
|
||
307 | * @param xml DOCUMENT ME!
|
||
308 | * @param p DOCUMENT ME!
|
||
309 | *
|
||
310 | * @throws XMLException
|
||
311 | 10626 | caballero | * @throws ReadDriverException
|
312 | 7304 | caballero | * @throws DriverIOException
|
313 | */
|
||
314 | 7754 | jmvivo | public void setXMLEntity03(XMLEntity xml) |
315 | 10626 | caballero | throws XMLException, ReadDriverException{
|
316 | 9532 | caballero | |
317 | 7754 | jmvivo | this.setComment(xml.getStringProperty("comment")); |
318 | this.setCreationDate(xml.getStringProperty("creationDate")); |
||
319 | this.setName(xml.getStringProperty("name")); |
||
320 | this.setOwner(xml.getStringProperty("owner")); |
||
321 | 9532 | caballero | |
322 | 7754 | jmvivo | } |
323 | 7304 | caballero | |
324 | /**
|
||
325 | * DOCUMENT ME!
|
||
326 | *
|
||
327 | * @return DOCUMENT ME!
|
||
328 | */
|
||
329 | public Project getProject() {
|
||
330 | return project;
|
||
331 | } |
||
332 | /**
|
||
333 | * DOCUMENT ME!
|
||
334 | *
|
||
335 | * @param project DOCUMENT ME!
|
||
336 | */
|
||
337 | public void setProject(Project project, int index) { |
||
338 | this.project = project;
|
||
339 | this.index = index;
|
||
340 | } |
||
341 | public int getIndex() { |
||
342 | return index;
|
||
343 | } |
||
344 | |||
345 | /**
|
||
346 | * Locks this project element protecting it from deleting from the project.
|
||
347 | */
|
||
348 | public void lock() { |
||
349 | locked = true;
|
||
350 | } |
||
351 | |||
352 | /**
|
||
353 | * Unlocks this element. So, from now on, it can be removed from the project.
|
||
354 | */
|
||
355 | public void unlock() { |
||
356 | locked = false;
|
||
357 | } |
||
358 | |||
359 | /**
|
||
360 | * Tells whether if this project's element is locked/protected or not. A protected
|
||
361 | * element cannot be removed from the current project.
|
||
362 | *
|
||
363 | * @see <b>lock()</b> and <b>unlock()</b> methods.
|
||
364 | *
|
||
365 | * @return true if it is locked, false otherwise
|
||
366 | */
|
||
367 | public boolean isLocked() { |
||
368 | return locked;
|
||
369 | } |
||
370 | |||
371 | 24529 | vcaballero | /**
|
372 | * Register a ProjectViewListener.
|
||
373 | * @param listener
|
||
374 | * ProjectViewListener
|
||
375 | */
|
||
376 | public void addProjectViewListener(ProjectDocumentListener listener) { |
||
377 | if(this.projectDocListener.indexOf(listener) == -1) |
||
378 | this.projectDocListener.add(listener);
|
||
379 | } |
||
380 | |||
381 | /**
|
||
382 | * Throw this event when a new window is created
|
||
383 | * @param window
|
||
384 | * IWindow created
|
||
385 | */
|
||
386 | protected void callCreateWindow(IWindow window) { |
||
387 | for (int i = 0; i < projectDocListener.size(); i++) |
||
388 | projectDocListener.get(i).windowCreated(window); |
||
389 | } |
||
390 | |||
391 | 7304 | caballero | public abstract IWindow createWindow(); |
392 | public abstract IWindow getProperties(); |
||
393 | 7343 | caballero | public abstract void afterRemove(); |
394 | public abstract void afterAdd(); |
||
395 | 7304 | caballero | |
396 | 7343 | caballero | |
397 | public void setProjectDocumentFactory( |
||
398 | ProjectDocumentFactory projectDocumentFactory) { |
||
399 | this.projectDocumentFactory = projectDocumentFactory;
|
||
400 | 7304 | caballero | } |
401 | |||
402 | 7343 | caballero | public ProjectDocumentFactory getProjectDocumentFactory() {
|
403 | return projectDocumentFactory;
|
||
404 | } |
||
405 | 9532 | caballero | |
406 | 7754 | jmvivo | public abstract void exportToXML(XMLEntity root, Project project) throws SaveException ; |
407 | 9532 | caballero | |
408 | 10626 | caballero | public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, OpenException, ReadDriverException; |
409 | 9532 | caballero | |
410 | |||
411 | 10626 | caballero | public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, OpenException, ReadDriverException{ |
412 | 7754 | jmvivo | importFromXML(root,typeRoot, elementIndex,project,false);
|
413 | } |
||
414 | 9532 | caballero | |
415 | 9044 | cesar | /**
|
416 | * Get the layout properties (size, position, state of the components)
|
||
417 | * of the window associated with this ProjectDocument.
|
||
418 | * This is used to re-open the window with the same properties it had
|
||
419 | * when it was closed.
|
||
420 | 9532 | caballero | *
|
421 | 9044 | cesar | * @return A WindowData object storing the properties of the window.
|
422 | */
|
||
423 | public WindowData getWindowData() {
|
||
424 | return windowData;
|
||
425 | } |
||
426 | 9532 | caballero | |
427 | 9044 | cesar | /**
|
428 | * Store the layout properties (size, position, state of the components)
|
||
429 | * of the window associated with this ProjectDocument.
|
||
430 | * This is used to re-open the window with the same properties it had
|
||
431 | * when it was closed.
|
||
432 | */
|
||
433 | public void storeWindowData(WindowData data) { |
||
434 | windowData = data; |
||
435 | } |
||
436 | 9532 | caballero | |
437 | 10162 | caballero | public boolean isModified() { |
438 | return isModified;
|
||
439 | } |
||
440 | 9690 | caballero | |
441 | 10162 | caballero | public void setModified(boolean modified) { |
442 | isModified=modified; |
||
443 | } |
||
444 | |||
445 | 9690 | caballero | public static void initializeNUMS() { |
446 | NUMS.clear(); |
||
447 | ExtensionPoints extensionPoints = |
||
448 | ExtensionPointsSingleton.getInstance(); |
||
449 | ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("Documents");
|
||
450 | Iterator iterator = extensionPoint.keySet().iterator();
|
||
451 | while (iterator.hasNext()) {
|
||
452 | try {
|
||
453 | ProjectDocumentFactory documentFactory = (ProjectDocumentFactory)extensionPoint.create((String)iterator.next());
|
||
454 | NUMS.put(documentFactory.getRegisterName(),new Integer(0)); |
||
455 | } catch (InstantiationException e) { |
||
456 | e.printStackTrace(); |
||
457 | } catch (IllegalAccessException e) { |
||
458 | e.printStackTrace(); |
||
459 | } catch (ClassCastException e) { |
||
460 | e.printStackTrace(); |
||
461 | } |
||
462 | } |
||
463 | } |
||
464 | 7304 | caballero | } |