svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectElement.java @ 7422
History | View | Annotate | Download (10.9 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; |
42 |
|
43 |
import com.hardcode.driverManager.DriverLoadException; |
44 |
|
45 |
import com.iver.andami.PluginServices; |
46 |
import com.iver.andami.messages.NotificationManager; |
47 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
48 |
|
49 |
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 |
import com.iver.cit.gvsig.gui.project.OpenException; |
54 |
import com.iver.cit.gvsig.gui.project.SaveException; |
55 |
|
56 |
import com.iver.utiles.XMLEntity; |
57 |
|
58 |
import java.beans.PropertyChangeListener; |
59 |
import java.beans.PropertyChangeSupport; |
60 |
|
61 |
import java.io.Serializable; |
62 |
|
63 |
import java.text.DateFormat; |
64 |
|
65 |
import java.util.Date; |
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 ProjectElement implements Serializable { |
74 |
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 |
// the window associated to this project element (if any)
|
83 |
protected com.iver.andami.ui.mdiManager.IWindow window = null; |
84 |
// El viewInfo que 'levanto' desde el disco (.gvp)
|
85 |
protected WindowInfo seedViewInfo=null; |
86 |
|
87 |
/**
|
88 |
* Creates a new ProjectElement object.
|
89 |
*/
|
90 |
public ProjectElement() {
|
91 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
92 |
change = new PropertyChangeSupport(this); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* @see java.lang.Object#toString()
|
97 |
*/
|
98 |
public String toString() { |
99 |
return name;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Obtiene el nombre del elemento
|
104 |
*
|
105 |
* @return
|
106 |
*/
|
107 |
public String getName() { |
108 |
return name;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Establece el nombre del elemento
|
113 |
*
|
114 |
* @param string
|
115 |
*/
|
116 |
public void setName(String string) { |
117 |
String oldValue = name;
|
118 |
name = string; |
119 |
change.firePropertyChange("name", oldValue, name);
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* Obtiene la fecha de creaci?n del elemento
|
124 |
*
|
125 |
* @return
|
126 |
*/
|
127 |
public String getCreationDate() { |
128 |
return creationDate;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Obtiene el propietario del elemento
|
133 |
*
|
134 |
* @return
|
135 |
*/
|
136 |
public String getOwner() { |
137 |
return owner;
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* Establece la fecha de creaci?n del elemento.
|
142 |
*
|
143 |
* @param string
|
144 |
*/
|
145 |
public void setCreationDate(String string) { |
146 |
creationDate = string; |
147 |
change.firePropertyChange("creationDate", creationDate, creationDate);
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* Establece el propietario del elemento
|
152 |
*
|
153 |
* @param string
|
154 |
*/
|
155 |
public void setOwner(String string) { |
156 |
owner = string; |
157 |
change.firePropertyChange("owner", owner, owner);
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* Obtiene los comentarios del proyecto
|
162 |
*
|
163 |
* @return
|
164 |
*/
|
165 |
public String getComment() { |
166 |
return comment;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Establece los comentarios del proyecto
|
171 |
*
|
172 |
* @param string
|
173 |
*/
|
174 |
public void setComment(String string) { |
175 |
comment = string; |
176 |
change.firePropertyChange("comment", comment, comment);
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* A?ade un listener para los cambios en las bounded properties
|
181 |
*
|
182 |
* @param listener
|
183 |
*/
|
184 |
public synchronized void addPropertyChangeListener( |
185 |
PropertyChangeListener listener) {
|
186 |
change.addPropertyChangeListener(listener); |
187 |
} |
188 |
|
189 |
/**
|
190 |
* DOCUMENT ME!
|
191 |
*
|
192 |
* @return DOCUMENT ME!
|
193 |
* @throws XMLException
|
194 |
* @throws SaveException
|
195 |
*/
|
196 |
public XMLEntity getXMLEntity() throws SaveException { |
197 |
XMLEntity xml = new XMLEntity();
|
198 |
try{
|
199 |
xml.putProperty("className", this.getClass().getName()); |
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 ProjectElement createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{ |
228 |
ProjectElement pe = null;
|
229 |
|
230 |
Class clase;
|
231 |
try {
|
232 |
clase = Class.forName(xml.getStringProperty("className")); |
233 |
pe = (ProjectElement) 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 |
pe.setComment(xml.getStringProperty("comment"));
|
246 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
247 |
pe.setName(xml.getStringProperty("name"));
|
248 |
pe.setOwner(xml.getStringProperty("owner"));
|
249 |
pe.project = p; |
250 |
|
251 |
pe.setXMLEntity03(xml,p); |
252 |
|
253 |
return pe;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* DOCUMENT ME!
|
258 |
*
|
259 |
* @param xml DOCUMENT ME!
|
260 |
* @param p DOCUMENT ME!
|
261 |
*
|
262 |
* @return DOCUMENT ME!
|
263 |
*
|
264 |
* @throws XMLException
|
265 |
* @throws DriverException
|
266 |
* @throws DriverIOException
|
267 |
* @throws OpenException
|
268 |
*/
|
269 |
public static ProjectElement createFromXML(XMLEntity xml, Project p) |
270 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
271 |
ProjectElement pe = null;
|
272 |
try{
|
273 |
Class clase;
|
274 |
|
275 |
try {
|
276 |
clase = Class.forName(xml.getStringProperty("className")); |
277 |
pe = (ProjectElement) clase.newInstance(); |
278 |
} catch (ClassNotFoundException e) { |
279 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
280 |
e); |
281 |
} catch (InstantiationException e) { |
282 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
283 |
e); |
284 |
} catch (IllegalAccessException e) { |
285 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
286 |
e); |
287 |
} |
288 |
|
289 |
pe.setComment(xml.getStringProperty("comment"));
|
290 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
291 |
pe.setName(xml.getStringProperty("name"));
|
292 |
pe.setOwner(xml.getStringProperty("owner"));
|
293 |
pe.project = p; |
294 |
}catch (Exception e) { |
295 |
throw new OpenException(e,pe.getClass().getName()); |
296 |
} |
297 |
pe.setXMLEntity(xml, p); |
298 |
|
299 |
return pe;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* DOCUMENT ME!
|
304 |
*
|
305 |
* @param xml DOCUMENT ME!
|
306 |
* @param p DOCUMENT ME!
|
307 |
*
|
308 |
* @throws XMLException
|
309 |
* @throws DriverException
|
310 |
* @throws DriverIOException
|
311 |
* @throws OpenException
|
312 |
*/
|
313 |
public abstract void setXMLEntity(XMLEntity xml, Project p) |
314 |
throws XMLException, DriverException, DriverIOException, OpenException;
|
315 |
|
316 |
/**
|
317 |
* DOCUMENT ME!
|
318 |
*
|
319 |
* @param xml DOCUMENT ME!
|
320 |
* @param p DOCUMENT ME!
|
321 |
*
|
322 |
* @throws XMLException
|
323 |
* @throws DriverException
|
324 |
* @throws DriverIOException
|
325 |
*/
|
326 |
public abstract void setXMLEntity03(XMLEntity xml, Project p) |
327 |
throws XMLException, DriverException, DriverIOException;
|
328 |
|
329 |
/**
|
330 |
* DOCUMENT ME!
|
331 |
*
|
332 |
* @return DOCUMENT ME!
|
333 |
*/
|
334 |
public Project getProject() {
|
335 |
return project;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* DOCUMENT ME!
|
340 |
*
|
341 |
* @param project DOCUMENT ME!
|
342 |
*/
|
343 |
public void setProject(Project project, int index) { |
344 |
this.project = project;
|
345 |
this.index = index;
|
346 |
} |
347 |
public int getIndex() { |
348 |
return index;
|
349 |
} |
350 |
|
351 |
/**
|
352 |
* Gets the window associated to this project element.
|
353 |
*/
|
354 |
public com.iver.andami.ui.mdiManager.IWindow getAndamiWindow() {
|
355 |
return window;
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Sets the window associated to this project element.
|
360 |
* @param view
|
361 |
*/
|
362 |
public void setAndamiWindow(com.iver.andami.ui.mdiManager.IWindow window) { |
363 |
this.window = window;
|
364 |
} |
365 |
|
366 |
/**
|
367 |
* DOCUMENT ME!
|
368 |
*
|
369 |
* @return DOCUMENT ME!
|
370 |
* @throws SaveException
|
371 |
* @throws XMLException
|
372 |
* @throws SaveException
|
373 |
*/
|
374 |
public XMLEntity getViewInfoXMLEntity() throws SaveException { |
375 |
if (window!=null && PluginServices.getMDIManager().getWindowInfo(window)!=null) { |
376 |
WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(window); |
377 |
XMLEntity xml = new XMLEntity();
|
378 |
//xml.putProperty("nameClass", this.getClass().getName());
|
379 |
try{
|
380 |
xml.setName("ViewInfoProperties");
|
381 |
xml.putProperty("className", this.getClass().getName()); |
382 |
xml.putProperty("X", vi.getX());
|
383 |
xml.putProperty("Y", vi.getY());
|
384 |
xml.putProperty("Width", vi.getWidth());
|
385 |
xml.putProperty("Height", vi.getHeight());
|
386 |
xml.putProperty("isVisible", vi.isVisible());
|
387 |
xml.putProperty("isResizable", vi.isResizable());
|
388 |
xml.putProperty("isMaximizable", vi.isMaximizable());
|
389 |
xml.putProperty("isModal", vi.isModal());
|
390 |
xml.putProperty("isModeless", vi.isModeless());
|
391 |
xml.putProperty("isClosed", vi.isClosed());
|
392 |
if (vi.isMaximized()==true) { |
393 |
xml.putProperty("isMaximized", vi.isMaximized());
|
394 |
xml.putProperty("normalX", vi.getNormalX());
|
395 |
xml.putProperty("normalY", vi.getNormalY());
|
396 |
xml.putProperty("normalWidth", vi.getNormalWidth());
|
397 |
xml.putProperty("normalHeight", vi.getNormalHeight());
|
398 |
} |
399 |
}catch (Exception e) { |
400 |
throw new SaveException(e,this.getClass().getName()); |
401 |
} |
402 |
return xml;
|
403 |
} |
404 |
else
|
405 |
return null; |
406 |
} |
407 |
|
408 |
public WindowInfo getSeedWindowInfo() {
|
409 |
return seedViewInfo;
|
410 |
} |
411 |
|
412 |
/**
|
413 |
* Locks this project element protecting it from deleting from the project.
|
414 |
*/
|
415 |
public void lock() { |
416 |
locked = true;
|
417 |
} |
418 |
|
419 |
/**
|
420 |
* Unlocks this element. So, from now on, it can be removed from the project.
|
421 |
*/
|
422 |
public void unlock() { |
423 |
locked = false;
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* Tells whether if this project's element is locked/protected or not. A protected
|
428 |
* element cannot be removed from the current project.
|
429 |
*
|
430 |
* @see <b>lock()</b> and <b>unlock()</b> methods.
|
431 |
*
|
432 |
* @return true if it is locked, false otherwise
|
433 |
*/
|
434 |
public boolean isLocked() { |
435 |
return locked;
|
436 |
} |
437 |
} |