svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 10626
History | View | Annotate | Download (11.7 KB)
1 |
/* 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 |
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 |
import java.util.HashMap; |
49 |
import java.util.Iterator; |
50 |
|
51 |
import com.hardcode.driverManager.DriverLoadException; |
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
53 |
import com.iver.andami.messages.NotificationManager; |
54 |
import com.iver.andami.ui.mdiManager.IWindow; |
55 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
56 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
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 |
import com.iver.cit.gvsig.project.documents.gui.WindowData; |
62 |
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 |
public static HashMap NUMS = new HashMap(); |
75 |
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 |
protected WindowData windowData = null; |
84 |
private boolean isModified=false; |
85 |
private ProjectDocumentFactory projectDocumentFactory;
|
86 |
/**
|
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 |
xml.putProperty("className", projectDocumentFactory.getRegisterName());
|
200 |
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 |
* @throws DriverException
|
219 |
* @throws DriverIOException
|
220 |
* @throws CancelationException
|
221 |
* @throws ClassNotFoundException
|
222 |
* @throws InstantiationException
|
223 |
* @throws IllegalAccessException
|
224 |
* @throws DriverIOException
|
225 |
* @throws DriverLoadException
|
226 |
*/
|
227 |
public static ProjectDocument createFromXML03(XMLEntity xml, Project p) throws XMLException{ |
228 |
ProjectDocument pe = null;
|
229 |
|
230 |
Class clase;
|
231 |
try {
|
232 |
clase = Class.forName(xml.getStringProperty("className")); |
233 |
pe = (ProjectDocument) clase.newInstance(); |
234 |
} catch (ClassNotFoundException e) { |
235 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
236 |
e); |
237 |
} catch (InstantiationException e) { |
238 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
239 |
e); |
240 |
} catch (IllegalAccessException e) { |
241 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
242 |
e); |
243 |
} |
244 |
|
245 |
return pe;
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* DOCUMENT ME!
|
250 |
*
|
251 |
* @param xml DOCUMENT ME!
|
252 |
* @param p DOCUMENT ME!
|
253 |
*
|
254 |
* @return DOCUMENT ME!
|
255 |
*
|
256 |
* @throws XMLException
|
257 |
* @throws DriverException
|
258 |
* @throws DriverIOException
|
259 |
* @throws OpenException
|
260 |
*/
|
261 |
public static ProjectDocument createFromXML(XMLEntity xml, Project p) |
262 |
throws XMLException, OpenException {
|
263 |
ProjectDocumentFactory pde = null;
|
264 |
try{
|
265 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
266 |
ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
|
267 |
try {
|
268 |
pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
|
269 |
} catch (InstantiationException e) { |
270 |
NotificationManager.addError("Clase de ProjectDocument no reconocida",
|
271 |
e); |
272 |
} catch (IllegalAccessException e) { |
273 |
NotificationManager.addError("Clase de ProjectDocument no reconocida",
|
274 |
e); |
275 |
} |
276 |
ProjectDocument pe=pde.create(p); |
277 |
pe.setProjectDocumentFactory(pde); |
278 |
return pe;
|
279 |
}catch (Exception e) { |
280 |
throw new OpenException(e,pde.getNameType()); |
281 |
} |
282 |
} |
283 |
|
284 |
/**
|
285 |
* DOCUMENT ME!
|
286 |
*
|
287 |
* @param xml DOCUMENT ME!
|
288 |
* @param p DOCUMENT ME!
|
289 |
*
|
290 |
* @throws XMLException
|
291 |
* @throws DriverException
|
292 |
* @throws DriverIOException
|
293 |
* @throws OpenException
|
294 |
* @throws ReadDriverException
|
295 |
*/
|
296 |
public void setXMLEntity(XMLEntity xml) |
297 |
throws XMLException, OpenException, ReadDriverException{
|
298 |
|
299 |
this.setComment(xml.getStringProperty("comment")); |
300 |
this.setCreationDate(xml.getStringProperty("creationDate")); |
301 |
this.setName(xml.getStringProperty("name")); |
302 |
this.setOwner(xml.getStringProperty("owner")); |
303 |
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* DOCUMENT ME!
|
308 |
*
|
309 |
* @param xml DOCUMENT ME!
|
310 |
* @param p DOCUMENT ME!
|
311 |
*
|
312 |
* @throws XMLException
|
313 |
* @throws DriverException
|
314 |
* @throws ReadDriverException
|
315 |
* @throws DriverIOException
|
316 |
*/
|
317 |
public void setXMLEntity03(XMLEntity xml) |
318 |
throws XMLException, ReadDriverException{
|
319 |
|
320 |
this.setComment(xml.getStringProperty("comment")); |
321 |
this.setCreationDate(xml.getStringProperty("creationDate")); |
322 |
this.setName(xml.getStringProperty("name")); |
323 |
this.setOwner(xml.getStringProperty("owner")); |
324 |
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* DOCUMENT ME!
|
329 |
*
|
330 |
* @return DOCUMENT ME!
|
331 |
*/
|
332 |
public Project getProject() {
|
333 |
return project;
|
334 |
} |
335 |
/**
|
336 |
* DOCUMENT ME!
|
337 |
*
|
338 |
* @param project DOCUMENT ME!
|
339 |
*/
|
340 |
public void setProject(Project project, int index) { |
341 |
this.project = project;
|
342 |
this.index = index;
|
343 |
} |
344 |
public int getIndex() { |
345 |
return index;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* Locks this project element protecting it from deleting from the project.
|
350 |
*/
|
351 |
public void lock() { |
352 |
locked = true;
|
353 |
} |
354 |
|
355 |
/**
|
356 |
* Unlocks this element. So, from now on, it can be removed from the project.
|
357 |
*/
|
358 |
public void unlock() { |
359 |
locked = false;
|
360 |
} |
361 |
|
362 |
/**
|
363 |
* Tells whether if this project's element is locked/protected or not. A protected
|
364 |
* element cannot be removed from the current project.
|
365 |
*
|
366 |
* @see <b>lock()</b> and <b>unlock()</b> methods.
|
367 |
*
|
368 |
* @return true if it is locked, false otherwise
|
369 |
*/
|
370 |
public boolean isLocked() { |
371 |
return locked;
|
372 |
} |
373 |
|
374 |
public abstract IWindow createWindow(); |
375 |
public abstract IWindow getProperties(); |
376 |
public abstract void afterRemove(); |
377 |
public abstract void afterAdd(); |
378 |
|
379 |
|
380 |
public void setProjectDocumentFactory( |
381 |
ProjectDocumentFactory projectDocumentFactory) { |
382 |
this.projectDocumentFactory = projectDocumentFactory;
|
383 |
} |
384 |
|
385 |
public ProjectDocumentFactory getProjectDocumentFactory() {
|
386 |
return projectDocumentFactory;
|
387 |
} |
388 |
|
389 |
public abstract void exportToXML(XMLEntity root, Project project) throws SaveException ; |
390 |
|
391 |
public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, OpenException, ReadDriverException; |
392 |
|
393 |
|
394 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, OpenException, ReadDriverException{ |
395 |
importFromXML(root,typeRoot, elementIndex,project,false);
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* Get the layout properties (size, position, state of the components)
|
400 |
* of the window associated with this ProjectDocument.
|
401 |
* This is used to re-open the window with the same properties it had
|
402 |
* when it was closed.
|
403 |
*
|
404 |
* @return A WindowData object storing the properties of the window.
|
405 |
*/
|
406 |
public WindowData getWindowData() {
|
407 |
return windowData;
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* Store the layout properties (size, position, state of the components)
|
412 |
* of the window associated with this ProjectDocument.
|
413 |
* This is used to re-open the window with the same properties it had
|
414 |
* when it was closed.
|
415 |
*/
|
416 |
public void storeWindowData(WindowData data) { |
417 |
windowData = data; |
418 |
} |
419 |
|
420 |
public boolean isModified() { |
421 |
return isModified;
|
422 |
} |
423 |
|
424 |
public void setModified(boolean modified) { |
425 |
isModified=modified; |
426 |
} |
427 |
|
428 |
public static void initializeNUMS() { |
429 |
NUMS.clear(); |
430 |
ExtensionPoints extensionPoints = |
431 |
ExtensionPointsSingleton.getInstance(); |
432 |
ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("Documents");
|
433 |
Iterator iterator = extensionPoint.keySet().iterator();
|
434 |
while (iterator.hasNext()) {
|
435 |
try {
|
436 |
ProjectDocumentFactory documentFactory = (ProjectDocumentFactory)extensionPoint.create((String)iterator.next());
|
437 |
NUMS.put(documentFactory.getRegisterName(),new Integer(0)); |
438 |
} catch (InstantiationException e) { |
439 |
e.printStackTrace(); |
440 |
} catch (IllegalAccessException e) { |
441 |
e.printStackTrace(); |
442 |
} catch (ClassCastException e) { |
443 |
e.printStackTrace(); |
444 |
} |
445 |
} |
446 |
|
447 |
|
448 |
} |
449 |
} |