svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectElement.java @ 5222
History | View | Annotate | Download (10.5 KB)
1 | 1222 | fernando | /* 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; |
||
42 | |||
43 | 1830 | fernando | import com.hardcode.driverManager.DriverLoadException; |
44 | 1222 | fernando | |
45 | 5053 | cesar | import com.iver.andami.PluginServices; |
46 | 1222 | fernando | import com.iver.andami.messages.NotificationManager; |
47 | 5053 | cesar | import com.iver.andami.ui.mdiManager.ViewInfo; |
48 | 1830 | fernando | |
49 | 1222 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
50 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
51 | import com.iver.cit.gvsig.fmap.layers.CancelationException; |
||
52 | import com.iver.cit.gvsig.fmap.layers.DifferentVersionException; |
||
53 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
54 | 3183 | caballero | import com.iver.cit.gvsig.gui.project.OpenException; |
55 | import com.iver.cit.gvsig.gui.project.SaveException; |
||
56 | 1830 | fernando | |
57 | 1222 | fernando | import com.iver.utiles.XMLEntity; |
58 | |||
59 | 1830 | fernando | import java.beans.PropertyChangeListener; |
60 | import java.beans.PropertyChangeSupport; |
||
61 | 1222 | fernando | |
62 | 1830 | fernando | import java.io.Serializable; |
63 | |||
64 | import java.text.DateFormat; |
||
65 | |||
66 | import java.util.Date; |
||
67 | |||
68 | |||
69 | 1222 | fernando | /**
|
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 ProjectElement implements Serializable { |
||
75 | 1830 | fernando | 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 | 5053 | cesar | protected com.iver.andami.ui.mdiManager.View view = null; |
83 | // El viewInfo que 'levanto' desde el disco (.gvp)
|
||
84 | protected ViewInfo seedViewInfo=null; |
||
85 | 1222 | fernando | |
86 | 1830 | fernando | /**
|
87 | * Creates a new ProjectElement object.
|
||
88 | */
|
||
89 | public ProjectElement() {
|
||
90 | creationDate = DateFormat.getDateInstance().format(new Date()); |
||
91 | change = new PropertyChangeSupport(this); |
||
92 | } |
||
93 | 1222 | fernando | |
94 | 1830 | fernando | /**
|
95 | * @see java.lang.Object#toString()
|
||
96 | */
|
||
97 | public String toString() { |
||
98 | return name;
|
||
99 | } |
||
100 | 1222 | fernando | |
101 | 1830 | fernando | /**
|
102 | * Obtiene el nombre del elemento
|
||
103 | *
|
||
104 | * @return
|
||
105 | */
|
||
106 | public String getName() { |
||
107 | return name;
|
||
108 | } |
||
109 | 1222 | fernando | |
110 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
121 | 1830 | fernando | /**
|
122 | * Obtiene la fecha de creaci?n del elemento
|
||
123 | *
|
||
124 | * @return
|
||
125 | */
|
||
126 | public String getCreationDate() { |
||
127 | return creationDate;
|
||
128 | } |
||
129 | 1222 | fernando | |
130 | 1830 | fernando | /**
|
131 | * Obtiene el propietario del elemento
|
||
132 | *
|
||
133 | * @return
|
||
134 | */
|
||
135 | public String getOwner() { |
||
136 | return owner;
|
||
137 | } |
||
138 | 1222 | fernando | |
139 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
149 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
159 | 1830 | fernando | /**
|
160 | * Obtiene los comentarios del proyecto
|
||
161 | *
|
||
162 | * @return
|
||
163 | */
|
||
164 | public String getComment() { |
||
165 | return comment;
|
||
166 | } |
||
167 | 1222 | fernando | |
168 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
178 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
188 | 1830 | fernando | /**
|
189 | * DOCUMENT ME!
|
||
190 | *
|
||
191 | * @return DOCUMENT ME!
|
||
192 | * @throws XMLException
|
||
193 | 3183 | caballero | * @throws SaveException
|
194 | 1830 | fernando | */
|
195 | 3183 | caballero | public XMLEntity getXMLEntity() throws SaveException { |
196 | 1830 | fernando | XMLEntity xml = new XMLEntity();
|
197 | 3183 | caballero | try{
|
198 | 1830 | fernando | xml.putProperty("className", this.getClass().getName()); |
199 | xml.putProperty("comment", comment);
|
||
200 | xml.putProperty("creationDate", creationDate);
|
||
201 | xml.putProperty("name", name);
|
||
202 | xml.putProperty("owner", owner);
|
||
203 | 1222 | fernando | |
204 | 1830 | fernando | //xml.addChild(mapContext.getXMLEntity);
|
205 | 3183 | caballero | }catch (Exception e) { |
206 | throw new SaveException(e,this.getClass().getName()); |
||
207 | } |
||
208 | 1830 | fernando | return xml;
|
209 | } |
||
210 | 1222 | fernando | |
211 | 2183 | fernando | /**
|
212 | * DOCUMENT ME!
|
||
213 | *
|
||
214 | * @param xml DOCUMENT ME!
|
||
215 | * @param p DOCUMENT ME!
|
||
216 | *
|
||
217 | * @return DOCUMENT ME!
|
||
218 | * @throws XMLException
|
||
219 | * @throws DriverException
|
||
220 | * @throws DriverIOException
|
||
221 | * @throws DifferentVersionException
|
||
222 | * @throws CancelationException
|
||
223 | * @throws DifferentVersionException
|
||
224 | * @throws ClassNotFoundException
|
||
225 | * @throws InstantiationException
|
||
226 | * @throws IllegalAccessException
|
||
227 | * @throws DriverIOException
|
||
228 | * @throws DriverLoadException
|
||
229 | */
|
||
230 | public static ProjectElement createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{ |
||
231 | ProjectElement pe = null;
|
||
232 | |||
233 | Class clase;
|
||
234 | try {
|
||
235 | clase = Class.forName(xml.getStringProperty("className")); |
||
236 | pe = (ProjectElement) clase.newInstance(); |
||
237 | } catch (ClassNotFoundException e) { |
||
238 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
239 | e); |
||
240 | } catch (InstantiationException e) { |
||
241 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
242 | e); |
||
243 | } catch (IllegalAccessException e) { |
||
244 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
245 | e); |
||
246 | } |
||
247 | |||
248 | pe.setComment(xml.getStringProperty("comment"));
|
||
249 | pe.setCreationDate(xml.getStringProperty("creationDate"));
|
||
250 | pe.setName(xml.getStringProperty("name"));
|
||
251 | pe.setOwner(xml.getStringProperty("owner"));
|
||
252 | pe.project = p; |
||
253 | |||
254 | pe.setXMLEntity03(xml,p); |
||
255 | |||
256 | return pe;
|
||
257 | } |
||
258 | |||
259 | 1830 | fernando | /**
|
260 | * DOCUMENT ME!
|
||
261 | *
|
||
262 | * @param xml DOCUMENT ME!
|
||
263 | * @param p DOCUMENT ME!
|
||
264 | *
|
||
265 | * @return DOCUMENT ME!
|
||
266 | *
|
||
267 | * @throws XMLException
|
||
268 | * @throws DriverException
|
||
269 | * @throws DriverIOException
|
||
270 | 3183 | caballero | * @throws OpenException
|
271 | 1830 | fernando | */
|
272 | public static ProjectElement createFromXML(XMLEntity xml, Project p) |
||
273 | 3183 | caballero | throws XMLException, DriverException, DriverIOException, OpenException {
|
274 | 1830 | fernando | ProjectElement pe = null;
|
275 | 3183 | caballero | try{
|
276 | 1830 | fernando | Class clase;
|
277 | |||
278 | try {
|
||
279 | clase = Class.forName(xml.getStringProperty("className")); |
||
280 | 1222 | fernando | pe = (ProjectElement) clase.newInstance(); |
281 | 1830 | fernando | } catch (ClassNotFoundException e) { |
282 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
283 | e); |
||
284 | } catch (InstantiationException e) { |
||
285 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
286 | e); |
||
287 | } catch (IllegalAccessException e) { |
||
288 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
289 | e); |
||
290 | } |
||
291 | 1222 | fernando | |
292 | 1830 | fernando | pe.setComment(xml.getStringProperty("comment"));
|
293 | pe.setCreationDate(xml.getStringProperty("creationDate"));
|
||
294 | pe.setName(xml.getStringProperty("name"));
|
||
295 | pe.setOwner(xml.getStringProperty("owner"));
|
||
296 | pe.project = p; |
||
297 | 3183 | caballero | }catch (Exception e) { |
298 | throw new OpenException(e,pe.getClass().getName()); |
||
299 | } |
||
300 | 1830 | fernando | pe.setXMLEntity(xml, p); |
301 | 1222 | fernando | |
302 | 1830 | fernando | return pe;
|
303 | } |
||
304 | 1222 | fernando | |
305 | 1830 | fernando | /**
|
306 | * DOCUMENT ME!
|
||
307 | *
|
||
308 | * @param xml DOCUMENT ME!
|
||
309 | * @param p DOCUMENT ME!
|
||
310 | *
|
||
311 | * @throws XMLException
|
||
312 | * @throws DriverException
|
||
313 | * @throws DriverIOException
|
||
314 | 3183 | caballero | * @throws OpenException
|
315 | 1830 | fernando | */
|
316 | public abstract void setXMLEntity(XMLEntity xml, Project p) |
||
317 | 3183 | caballero | throws XMLException, DriverException, DriverIOException, OpenException;
|
318 | 1830 | fernando | |
319 | /**
|
||
320 | * DOCUMENT ME!
|
||
321 | *
|
||
322 | 2183 | fernando | * @param xml DOCUMENT ME!
|
323 | * @param p DOCUMENT ME!
|
||
324 | *
|
||
325 | * @throws XMLException
|
||
326 | * @throws DriverException
|
||
327 | * @throws DriverIOException
|
||
328 | */
|
||
329 | public abstract void setXMLEntity03(XMLEntity xml, Project p) |
||
330 | throws XMLException, DriverException, DriverIOException;
|
||
331 | |||
332 | /**
|
||
333 | * DOCUMENT ME!
|
||
334 | *
|
||
335 | 1830 | fernando | * @return DOCUMENT ME!
|
336 | */
|
||
337 | 1222 | fernando | public Project getProject() {
|
338 | return project;
|
||
339 | } |
||
340 | 1830 | fernando | |
341 | /**
|
||
342 | * DOCUMENT ME!
|
||
343 | *
|
||
344 | * @param project DOCUMENT ME!
|
||
345 | */
|
||
346 | public void setProject(Project project, int index) { |
||
347 | 1222 | fernando | this.project = project;
|
348 | 1830 | fernando | this.index = index;
|
349 | 1222 | fernando | } |
350 | 1830 | fernando | public int getIndex() { |
351 | return index;
|
||
352 | } |
||
353 | 5053 | cesar | |
354 | public ViewInfo getViewInfo() {
|
||
355 | if (view==null) |
||
356 | return null; |
||
357 | return PluginServices.getMDIManager().getViewInfo(view);
|
||
358 | } |
||
359 | |||
360 | public com.iver.andami.ui.mdiManager.View getAndamiView() {
|
||
361 | return view;
|
||
362 | } |
||
363 | |||
364 | public void setAndamiView(com.iver.andami.ui.mdiManager.View view) { |
||
365 | this.view = view;
|
||
366 | } |
||
367 | |||
368 | /**
|
||
369 | * DOCUMENT ME!
|
||
370 | *
|
||
371 | * @return DOCUMENT ME!
|
||
372 | * @throws SaveException
|
||
373 | * @throws XMLException
|
||
374 | * @throws SaveException
|
||
375 | */
|
||
376 | public XMLEntity getViewInfoXMLEntity() throws SaveException { |
||
377 | if (view!=null && PluginServices.getMDIManager().getViewInfo(view)!=null) { |
||
378 | ViewInfo vi = PluginServices.getMDIManager().getViewInfo(view); |
||
379 | XMLEntity xml = new XMLEntity();
|
||
380 | //xml.putProperty("nameClass", this.getClass().getName());
|
||
381 | try{
|
||
382 | xml.setName("ViewInfoProperties");
|
||
383 | xml.putProperty("className", this.getClass().getName()); |
||
384 | xml.putProperty("X", vi.getX());
|
||
385 | xml.putProperty("Y", vi.getY());
|
||
386 | xml.putProperty("Width", vi.getWidth());
|
||
387 | xml.putProperty("Height", vi.getHeight());
|
||
388 | xml.putProperty("isVisible", vi.isVisible());
|
||
389 | xml.putProperty("isResizable", vi.isResizable());
|
||
390 | xml.putProperty("isMaximizable", vi.isMaximizable());
|
||
391 | xml.putProperty("isModal", vi.isModal());
|
||
392 | xml.putProperty("isModeless", vi.isModeless());
|
||
393 | xml.putProperty("isClosed", vi.isClosed());
|
||
394 | if (vi.isMaximized()==true) { |
||
395 | xml.putProperty("isMaximized", vi.isMaximized());
|
||
396 | xml.putProperty("normalX", vi.getNormalX());
|
||
397 | xml.putProperty("normalY", vi.getNormalY());
|
||
398 | xml.putProperty("normalWidth", vi.getNormalWidth());
|
||
399 | xml.putProperty("normalHeight", vi.getNormalHeight());
|
||
400 | } |
||
401 | }catch (Exception e) { |
||
402 | throw new SaveException(e,this.getClass().getName()); |
||
403 | } |
||
404 | return xml;
|
||
405 | } |
||
406 | else
|
||
407 | return null; |
||
408 | } |
||
409 | |||
410 | public static ViewInfo createViewInfoFromXMLEntity(XMLEntity xml) |
||
411 | { |
||
412 | return Project.createViewInfoFromXMLEntity(xml);
|
||
413 | } |
||
414 | |||
415 | public ViewInfo getSeedViewInfo() {
|
||
416 | return seedViewInfo;
|
||
417 | } |
||
418 | |||
419 | 1222 | fernando | } |