root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 8120
History | View | Annotate | Download (10 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 |
|
49 |
import com.hardcode.driverManager.DriverLoadException; |
50 |
import com.iver.andami.messages.NotificationManager; |
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
52 |
import com.iver.cit.gvsig.fmap.DriverException; |
53 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
54 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
55 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
56 |
import com.iver.cit.gvsig.project.Project; |
57 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
58 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
59 |
import com.iver.utiles.XMLEntity; |
60 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
61 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
62 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Clase base de los elementos del proyecto (mapas, tablas y vistas)
|
67 |
*
|
68 |
* @author Fernando Gonz?lez Cort?s
|
69 |
*/
|
70 |
public abstract class ProjectDocument implements Serializable { |
71 |
protected PropertyChangeSupport change; |
72 |
protected Project project;
|
73 |
protected int index; |
74 |
protected String name; |
75 |
protected String creationDate; |
76 |
protected String owner; |
77 |
protected String comment; |
78 |
private boolean locked = false; |
79 |
|
80 |
private ProjectDocumentFactory projectDocumentFactory;
|
81 |
/**
|
82 |
* Creates a new ProjectElement object.
|
83 |
*/
|
84 |
public ProjectDocument() {
|
85 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
86 |
change = new PropertyChangeSupport(this); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* @see java.lang.Object#toString()
|
91 |
*/
|
92 |
public String toString() { |
93 |
return name;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Obtiene el nombre del elemento
|
98 |
*
|
99 |
* @return
|
100 |
*/
|
101 |
public String getName() { |
102 |
return name;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Establece el nombre del elemento
|
107 |
*
|
108 |
* @param string
|
109 |
*/
|
110 |
public void setName(String string) { |
111 |
String oldValue = name;
|
112 |
name = string; |
113 |
change.firePropertyChange("name", oldValue, name);
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Obtiene la fecha de creaci?n del elemento
|
118 |
*
|
119 |
* @return
|
120 |
*/
|
121 |
public String getCreationDate() { |
122 |
return creationDate;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Obtiene el propietario del elemento
|
127 |
*
|
128 |
* @return
|
129 |
*/
|
130 |
public String getOwner() { |
131 |
return owner;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Establece la fecha de creaci?n del elemento.
|
136 |
*
|
137 |
* @param string
|
138 |
*/
|
139 |
public void setCreationDate(String string) { |
140 |
creationDate = string; |
141 |
change.firePropertyChange("creationDate", creationDate, creationDate);
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* Establece el propietario del elemento
|
146 |
*
|
147 |
* @param string
|
148 |
*/
|
149 |
public void setOwner(String string) { |
150 |
owner = string; |
151 |
change.firePropertyChange("owner", owner, owner);
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Obtiene los comentarios del proyecto
|
156 |
*
|
157 |
* @return
|
158 |
*/
|
159 |
public String getComment() { |
160 |
return comment;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Establece los comentarios del proyecto
|
165 |
*
|
166 |
* @param string
|
167 |
*/
|
168 |
public void setComment(String string) { |
169 |
comment = string; |
170 |
change.firePropertyChange("comment", comment, comment);
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* A?ade un listener para los cambios en las bounded properties
|
175 |
*
|
176 |
* @param listener
|
177 |
*/
|
178 |
public synchronized void addPropertyChangeListener( |
179 |
PropertyChangeListener listener) {
|
180 |
change.addPropertyChangeListener(listener); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* DOCUMENT ME!
|
185 |
*
|
186 |
* @return DOCUMENT ME!
|
187 |
* @throws XMLException
|
188 |
* @throws SaveException
|
189 |
*/
|
190 |
public XMLEntity getXMLEntity() throws SaveException { |
191 |
XMLEntity xml = new XMLEntity();
|
192 |
try{
|
193 |
//xml.putProperty("nameRegister",this.getRegisterName());
|
194 |
xml.putProperty("className", projectDocumentFactory.getRegisterName());
|
195 |
xml.putProperty("comment", comment);
|
196 |
xml.putProperty("creationDate", creationDate);
|
197 |
xml.putProperty("name", name);
|
198 |
xml.putProperty("owner", owner);
|
199 |
}catch (Exception e) { |
200 |
throw new SaveException(e,this.getClass().getName()); |
201 |
} |
202 |
return xml;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* DOCUMENT ME!
|
207 |
*
|
208 |
* @param xml DOCUMENT ME!
|
209 |
* @param p DOCUMENT ME!
|
210 |
*
|
211 |
* @return DOCUMENT ME!
|
212 |
* @throws XMLException
|
213 |
* @throws DriverException
|
214 |
* @throws DriverIOException
|
215 |
* @throws CancelationException
|
216 |
* @throws ClassNotFoundException
|
217 |
* @throws InstantiationException
|
218 |
* @throws IllegalAccessException
|
219 |
* @throws DriverIOException
|
220 |
* @throws DriverLoadException
|
221 |
*/
|
222 |
public static ProjectDocument createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{ |
223 |
ProjectDocument pe = null;
|
224 |
|
225 |
Class clase;
|
226 |
try {
|
227 |
clase = Class.forName(xml.getStringProperty("className")); |
228 |
pe = (ProjectDocument) clase.newInstance(); |
229 |
} catch (ClassNotFoundException e) { |
230 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
231 |
e); |
232 |
} catch (InstantiationException e) { |
233 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
234 |
e); |
235 |
} catch (IllegalAccessException e) { |
236 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
237 |
e); |
238 |
} |
239 |
|
240 |
return pe;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* DOCUMENT ME!
|
245 |
*
|
246 |
* @param xml DOCUMENT ME!
|
247 |
* @param p DOCUMENT ME!
|
248 |
*
|
249 |
* @return DOCUMENT ME!
|
250 |
*
|
251 |
* @throws XMLException
|
252 |
* @throws DriverException
|
253 |
* @throws DriverIOException
|
254 |
* @throws OpenException
|
255 |
*/
|
256 |
public static ProjectDocument createFromXML(XMLEntity xml, Project p) |
257 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
258 |
ProjectDocumentFactory pde = null;
|
259 |
try{
|
260 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
261 |
ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
|
262 |
try {
|
263 |
pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
|
264 |
} catch (InstantiationException e) { |
265 |
NotificationManager.addError("Clase de ProjectDocument no reconocida",
|
266 |
e); |
267 |
} catch (IllegalAccessException e) { |
268 |
NotificationManager.addError("Clase de ProjectDocument no reconocida",
|
269 |
e); |
270 |
} |
271 |
ProjectDocument pe=pde.create(p); |
272 |
pe.setProjectDocumentFactory(pde); |
273 |
return pe;
|
274 |
}catch (Exception e) { |
275 |
throw new OpenException(e,pde.getNameType()); |
276 |
} |
277 |
} |
278 |
|
279 |
/**
|
280 |
* DOCUMENT ME!
|
281 |
*
|
282 |
* @param xml DOCUMENT ME!
|
283 |
* @param p DOCUMENT ME!
|
284 |
*
|
285 |
* @throws XMLException
|
286 |
* @throws DriverException
|
287 |
* @throws DriverIOException
|
288 |
* @throws OpenException
|
289 |
*/
|
290 |
public void setXMLEntity(XMLEntity xml) |
291 |
throws XMLException, DriverException, DriverIOException, OpenException{
|
292 |
|
293 |
this.setComment(xml.getStringProperty("comment")); |
294 |
this.setCreationDate(xml.getStringProperty("creationDate")); |
295 |
this.setName(xml.getStringProperty("name")); |
296 |
this.setOwner(xml.getStringProperty("owner")); |
297 |
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* DOCUMENT ME!
|
302 |
*
|
303 |
* @param xml DOCUMENT ME!
|
304 |
* @param p DOCUMENT ME!
|
305 |
*
|
306 |
* @throws XMLException
|
307 |
* @throws DriverException
|
308 |
* @throws DriverIOException
|
309 |
*/
|
310 |
public void setXMLEntity03(XMLEntity xml) |
311 |
throws XMLException, DriverException, DriverIOException{
|
312 |
|
313 |
this.setComment(xml.getStringProperty("comment")); |
314 |
this.setCreationDate(xml.getStringProperty("creationDate")); |
315 |
this.setName(xml.getStringProperty("name")); |
316 |
this.setOwner(xml.getStringProperty("owner")); |
317 |
|
318 |
} |
319 |
|
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 |
public abstract void afterRemove(); |
370 |
public abstract void afterAdd(); |
371 |
|
372 |
|
373 |
public void setProjectDocumentFactory( |
374 |
ProjectDocumentFactory projectDocumentFactory) { |
375 |
this.projectDocumentFactory = projectDocumentFactory;
|
376 |
} |
377 |
|
378 |
public ProjectDocumentFactory getProjectDocumentFactory() {
|
379 |
return projectDocumentFactory;
|
380 |
} |
381 |
|
382 |
public abstract void exportToXML(XMLEntity root, Project project) throws SaveException ; |
383 |
|
384 |
public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, DriverException, OpenException; |
385 |
|
386 |
|
387 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, DriverException, OpenException{ |
388 |
importFromXML(root,typeRoot, elementIndex,project,false);
|
389 |
} |
390 |
|
391 |
|
392 |
} |