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