svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectElement.java @ 8745
History | View | Annotate | Download (9.29 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 | 5029 | cesar | import com.iver.andami.PluginServices; |
46 | 1222 | fernando | import com.iver.andami.messages.NotificationManager; |
47 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
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.XMLException; |
||
53 | 3183 | caballero | import com.iver.cit.gvsig.gui.project.OpenException; |
54 | import com.iver.cit.gvsig.gui.project.SaveException; |
||
55 | 1830 | fernando | |
56 | 1222 | fernando | import com.iver.utiles.XMLEntity; |
57 | |||
58 | 1830 | fernando | import java.beans.PropertyChangeListener; |
59 | import java.beans.PropertyChangeSupport; |
||
60 | 1222 | fernando | |
61 | 1830 | fernando | import java.io.Serializable; |
62 | |||
63 | import java.text.DateFormat; |
||
64 | |||
65 | import java.util.Date; |
||
66 | |||
67 | |||
68 | 1222 | fernando | /**
|
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 ProjectElement implements Serializable { |
||
74 | 1830 | fernando | 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 | 5870 | jaume | private boolean locked = false; |
82 | 7422 | cesar | // the window associated to this project element (if any)
|
83 | protected com.iver.andami.ui.mdiManager.IWindow window = null; |
||
84 | 1222 | fernando | |
85 | 1830 | fernando | /**
|
86 | * Creates a new ProjectElement object.
|
||
87 | */
|
||
88 | public ProjectElement() {
|
||
89 | creationDate = DateFormat.getDateInstance().format(new Date()); |
||
90 | change = new PropertyChangeSupport(this); |
||
91 | } |
||
92 | 1222 | fernando | |
93 | 1830 | fernando | /**
|
94 | * @see java.lang.Object#toString()
|
||
95 | */
|
||
96 | public String toString() { |
||
97 | return name;
|
||
98 | } |
||
99 | 1222 | fernando | |
100 | 1830 | fernando | /**
|
101 | * Obtiene el nombre del elemento
|
||
102 | *
|
||
103 | * @return
|
||
104 | */
|
||
105 | public String getName() { |
||
106 | return name;
|
||
107 | } |
||
108 | 1222 | fernando | |
109 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
120 | 1830 | fernando | /**
|
121 | * Obtiene la fecha de creaci?n del elemento
|
||
122 | *
|
||
123 | * @return
|
||
124 | */
|
||
125 | public String getCreationDate() { |
||
126 | return creationDate;
|
||
127 | } |
||
128 | 1222 | fernando | |
129 | 1830 | fernando | /**
|
130 | * Obtiene el propietario del elemento
|
||
131 | *
|
||
132 | * @return
|
||
133 | */
|
||
134 | public String getOwner() { |
||
135 | return owner;
|
||
136 | } |
||
137 | 1222 | fernando | |
138 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
148 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
158 | 1830 | fernando | /**
|
159 | * Obtiene los comentarios del proyecto
|
||
160 | *
|
||
161 | * @return
|
||
162 | */
|
||
163 | public String getComment() { |
||
164 | return comment;
|
||
165 | } |
||
166 | 1222 | fernando | |
167 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
177 | 1830 | fernando | /**
|
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 | 1222 | fernando | |
187 | 1830 | fernando | /**
|
188 | * DOCUMENT ME!
|
||
189 | *
|
||
190 | * @return DOCUMENT ME!
|
||
191 | * @throws XMLException
|
||
192 | 3183 | caballero | * @throws SaveException
|
193 | 1830 | fernando | */
|
194 | 3183 | caballero | public XMLEntity getXMLEntity() throws SaveException { |
195 | 1830 | fernando | XMLEntity xml = new XMLEntity();
|
196 | 3183 | caballero | try{
|
197 | 1830 | fernando | xml.putProperty("className", this.getClass().getName()); |
198 | xml.putProperty("comment", comment);
|
||
199 | xml.putProperty("creationDate", creationDate);
|
||
200 | xml.putProperty("name", name);
|
||
201 | xml.putProperty("owner", owner);
|
||
202 | 3183 | caballero | }catch (Exception e) { |
203 | throw new SaveException(e,this.getClass().getName()); |
||
204 | } |
||
205 | 1830 | fernando | return xml;
|
206 | } |
||
207 | 1222 | fernando | |
208 | 2183 | fernando | /**
|
209 | * DOCUMENT ME!
|
||
210 | *
|
||
211 | * @param xml DOCUMENT ME!
|
||
212 | * @param p DOCUMENT ME!
|
||
213 | *
|
||
214 | * @return DOCUMENT ME!
|
||
215 | * @throws XMLException
|
||
216 | * @throws DriverException
|
||
217 | * @throws DriverIOException
|
||
218 | * @throws CancelationException
|
||
219 | * @throws ClassNotFoundException
|
||
220 | * @throws InstantiationException
|
||
221 | * @throws IllegalAccessException
|
||
222 | * @throws DriverIOException
|
||
223 | * @throws DriverLoadException
|
||
224 | */
|
||
225 | public static ProjectElement createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{ |
||
226 | ProjectElement pe = null;
|
||
227 | |||
228 | Class clase;
|
||
229 | try {
|
||
230 | clase = Class.forName(xml.getStringProperty("className")); |
||
231 | pe = (ProjectElement) clase.newInstance(); |
||
232 | } catch (ClassNotFoundException e) { |
||
233 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
234 | e); |
||
235 | } catch (InstantiationException e) { |
||
236 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
237 | e); |
||
238 | } catch (IllegalAccessException e) { |
||
239 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
240 | e); |
||
241 | } |
||
242 | |||
243 | pe.setComment(xml.getStringProperty("comment"));
|
||
244 | pe.setCreationDate(xml.getStringProperty("creationDate"));
|
||
245 | pe.setName(xml.getStringProperty("name"));
|
||
246 | pe.setOwner(xml.getStringProperty("owner"));
|
||
247 | pe.project = p; |
||
248 | |||
249 | pe.setXMLEntity03(xml,p); |
||
250 | |||
251 | return pe;
|
||
252 | } |
||
253 | |||
254 | 1830 | fernando | /**
|
255 | * DOCUMENT ME!
|
||
256 | *
|
||
257 | * @param xml DOCUMENT ME!
|
||
258 | * @param p DOCUMENT ME!
|
||
259 | *
|
||
260 | * @return DOCUMENT ME!
|
||
261 | *
|
||
262 | * @throws XMLException
|
||
263 | * @throws DriverException
|
||
264 | * @throws DriverIOException
|
||
265 | 3183 | caballero | * @throws OpenException
|
266 | 1830 | fernando | */
|
267 | public static ProjectElement createFromXML(XMLEntity xml, Project p) |
||
268 | 3183 | caballero | throws XMLException, DriverException, DriverIOException, OpenException {
|
269 | 1830 | fernando | ProjectElement pe = null;
|
270 | 3183 | caballero | try{
|
271 | 1830 | fernando | Class clase;
|
272 | |||
273 | try {
|
||
274 | clase = Class.forName(xml.getStringProperty("className")); |
||
275 | 1222 | fernando | pe = (ProjectElement) clase.newInstance(); |
276 | 1830 | fernando | } catch (ClassNotFoundException e) { |
277 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
278 | e); |
||
279 | } catch (InstantiationException e) { |
||
280 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
281 | e); |
||
282 | } catch (IllegalAccessException e) { |
||
283 | NotificationManager.addError("Clase de ProjectElement no reconocida",
|
||
284 | e); |
||
285 | } |
||
286 | 1222 | fernando | |
287 | 1830 | fernando | pe.setComment(xml.getStringProperty("comment"));
|
288 | pe.setCreationDate(xml.getStringProperty("creationDate"));
|
||
289 | pe.setName(xml.getStringProperty("name"));
|
||
290 | pe.setOwner(xml.getStringProperty("owner"));
|
||
291 | pe.project = p; |
||
292 | 3183 | caballero | }catch (Exception e) { |
293 | throw new OpenException(e,pe.getClass().getName()); |
||
294 | } |
||
295 | 1830 | fernando | pe.setXMLEntity(xml, p); |
296 | 1222 | fernando | |
297 | 1830 | fernando | return pe;
|
298 | } |
||
299 | 1222 | fernando | |
300 | 1830 | fernando | /**
|
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 | 3183 | caballero | * @throws OpenException
|
310 | 1830 | fernando | */
|
311 | public abstract void setXMLEntity(XMLEntity xml, Project p) |
||
312 | 3183 | caballero | throws XMLException, DriverException, DriverIOException, OpenException;
|
313 | 1830 | fernando | |
314 | /**
|
||
315 | * DOCUMENT ME!
|
||
316 | *
|
||
317 | 2183 | fernando | * @param xml DOCUMENT ME!
|
318 | * @param p DOCUMENT ME!
|
||
319 | *
|
||
320 | * @throws XMLException
|
||
321 | * @throws DriverException
|
||
322 | * @throws DriverIOException
|
||
323 | */
|
||
324 | public abstract void setXMLEntity03(XMLEntity xml, Project p) |
||
325 | throws XMLException, DriverException, DriverIOException;
|
||
326 | |||
327 | /**
|
||
328 | * DOCUMENT ME!
|
||
329 | *
|
||
330 | 1830 | fernando | * @return DOCUMENT ME!
|
331 | */
|
||
332 | 1222 | fernando | public Project getProject() {
|
333 | return project;
|
||
334 | } |
||
335 | 1830 | fernando | |
336 | /**
|
||
337 | * DOCUMENT ME!
|
||
338 | *
|
||
339 | * @param project DOCUMENT ME!
|
||
340 | */
|
||
341 | public void setProject(Project project, int index) { |
||
342 | 1222 | fernando | this.project = project;
|
343 | 1830 | fernando | this.index = index;
|
344 | 1222 | fernando | } |
345 | 1830 | fernando | public int getIndex() { |
346 | return index;
|
||
347 | } |
||
348 | 7422 | cesar | |
349 | /**
|
||
350 | * Gets the window associated to this project element.
|
||
351 | */
|
||
352 | public com.iver.andami.ui.mdiManager.IWindow getAndamiWindow() {
|
||
353 | return window;
|
||
354 | 5029 | cesar | } |
355 | |||
356 | 7422 | cesar | /**
|
357 | * Sets the window associated to this project element.
|
||
358 | * @param view
|
||
359 | */
|
||
360 | public void setAndamiWindow(com.iver.andami.ui.mdiManager.IWindow window) { |
||
361 | this.window = window;
|
||
362 | 5029 | cesar | } |
363 | |||
364 | 5870 | jaume | /**
|
365 | * Locks this project element protecting it from deleting from the project.
|
||
366 | */
|
||
367 | public void lock() { |
||
368 | locked = true;
|
||
369 | } |
||
370 | |||
371 | /**
|
||
372 | * Unlocks this element. So, from now on, it can be removed from the project.
|
||
373 | */
|
||
374 | public void unlock() { |
||
375 | locked = false;
|
||
376 | } |
||
377 | |||
378 | /**
|
||
379 | * Tells whether if this project's element is locked/protected or not. A protected
|
||
380 | * element cannot be removed from the current project.
|
||
381 | *
|
||
382 | * @see <b>lock()</b> and <b>unlock()</b> methods.
|
||
383 | *
|
||
384 | * @return true if it is locked, false otherwise
|
||
385 | */
|
||
386 | public boolean isLocked() { |
||
387 | return locked;
|
||
388 | } |
||
389 | 1222 | fernando | } |