root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectElement.java @ 6888
History | View | Annotate | Download (11 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 |
protected com.iver.andami.ui.mdiManager.IWindow view = null; |
83 |
// El viewInfo que 'levanto' desde el disco (.gvp)
|
84 |
protected WindowInfo seedViewInfo=null; |
85 |
|
86 |
/**
|
87 |
* Creates a new ProjectElement object.
|
88 |
*/
|
89 |
public ProjectElement() {
|
90 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
91 |
change = new PropertyChangeSupport(this); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* @see java.lang.Object#toString()
|
96 |
*/
|
97 |
public String toString() { |
98 |
return name;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Obtiene el nombre del elemento
|
103 |
*
|
104 |
* @return
|
105 |
*/
|
106 |
public String getName() { |
107 |
return name;
|
108 |
} |
109 |
|
110 |
/**
|
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 |
|
121 |
/**
|
122 |
* Obtiene la fecha de creaci?n del elemento
|
123 |
*
|
124 |
* @return
|
125 |
*/
|
126 |
public String getCreationDate() { |
127 |
return creationDate;
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* Obtiene el propietario del elemento
|
132 |
*
|
133 |
* @return
|
134 |
*/
|
135 |
public String getOwner() { |
136 |
return owner;
|
137 |
} |
138 |
|
139 |
/**
|
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 |
|
149 |
/**
|
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 |
|
159 |
/**
|
160 |
* Obtiene los comentarios del proyecto
|
161 |
*
|
162 |
* @return
|
163 |
*/
|
164 |
public String getComment() { |
165 |
return comment;
|
166 |
} |
167 |
|
168 |
/**
|
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 |
|
178 |
/**
|
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 |
|
188 |
/**
|
189 |
* DOCUMENT ME!
|
190 |
*
|
191 |
* @return DOCUMENT ME!
|
192 |
* @throws XMLException
|
193 |
* @throws SaveException
|
194 |
*/
|
195 |
public XMLEntity getXMLEntity() throws SaveException { |
196 |
XMLEntity xml = new XMLEntity();
|
197 |
try{
|
198 |
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 |
}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 |
* @throws XMLException
|
217 |
* @throws DriverException
|
218 |
* @throws DriverIOException
|
219 |
* @throws CancelationException
|
220 |
* @throws ClassNotFoundException
|
221 |
* @throws InstantiationException
|
222 |
* @throws IllegalAccessException
|
223 |
* @throws DriverIOException
|
224 |
* @throws DriverLoadException
|
225 |
*/
|
226 |
public static ProjectElement createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{ |
227 |
ProjectElement pe = null;
|
228 |
|
229 |
Class clase;
|
230 |
try {
|
231 |
clase = Class.forName(xml.getStringProperty("className")); |
232 |
pe = (ProjectElement) clase.newInstance(); |
233 |
} catch (ClassNotFoundException e) { |
234 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
235 |
e); |
236 |
} catch (InstantiationException e) { |
237 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
238 |
e); |
239 |
} catch (IllegalAccessException e) { |
240 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
241 |
e); |
242 |
} |
243 |
|
244 |
pe.setComment(xml.getStringProperty("comment"));
|
245 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
246 |
pe.setName(xml.getStringProperty("name"));
|
247 |
pe.setOwner(xml.getStringProperty("owner"));
|
248 |
pe.project = p; |
249 |
|
250 |
pe.setXMLEntity03(xml,p); |
251 |
|
252 |
return pe;
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* DOCUMENT ME!
|
257 |
*
|
258 |
* @param xml DOCUMENT ME!
|
259 |
* @param p DOCUMENT ME!
|
260 |
*
|
261 |
* @return DOCUMENT ME!
|
262 |
*
|
263 |
* @throws XMLException
|
264 |
* @throws DriverException
|
265 |
* @throws DriverIOException
|
266 |
* @throws OpenException
|
267 |
*/
|
268 |
public static ProjectElement createFromXML(XMLEntity xml, Project p) |
269 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
270 |
ProjectElement pe = null;
|
271 |
try{
|
272 |
Class clase;
|
273 |
|
274 |
try {
|
275 |
clase = Class.forName(xml.getStringProperty("className")); |
276 |
pe = (ProjectElement) clase.newInstance(); |
277 |
} catch (ClassNotFoundException e) { |
278 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
279 |
e); |
280 |
} catch (InstantiationException e) { |
281 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
282 |
e); |
283 |
} catch (IllegalAccessException e) { |
284 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
285 |
e); |
286 |
} |
287 |
|
288 |
pe.setComment(xml.getStringProperty("comment"));
|
289 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
290 |
pe.setName(xml.getStringProperty("name"));
|
291 |
pe.setOwner(xml.getStringProperty("owner"));
|
292 |
pe.project = p; |
293 |
}catch (Exception e) { |
294 |
throw new OpenException(e,pe.getClass().getName()); |
295 |
} |
296 |
pe.setXMLEntity(xml, p); |
297 |
|
298 |
return pe;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* DOCUMENT ME!
|
303 |
*
|
304 |
* @param xml DOCUMENT ME!
|
305 |
* @param p DOCUMENT ME!
|
306 |
*
|
307 |
* @throws XMLException
|
308 |
* @throws DriverException
|
309 |
* @throws DriverIOException
|
310 |
* @throws OpenException
|
311 |
*/
|
312 |
public abstract void setXMLEntity(XMLEntity xml, Project p) |
313 |
throws XMLException, DriverException, DriverIOException, OpenException;
|
314 |
|
315 |
/**
|
316 |
* DOCUMENT ME!
|
317 |
*
|
318 |
* @param xml DOCUMENT ME!
|
319 |
* @param p DOCUMENT ME!
|
320 |
*
|
321 |
* @throws XMLException
|
322 |
* @throws DriverException
|
323 |
* @throws DriverIOException
|
324 |
*/
|
325 |
public abstract void setXMLEntity03(XMLEntity xml, Project p) |
326 |
throws XMLException, DriverException, DriverIOException;
|
327 |
|
328 |
/**
|
329 |
* DOCUMENT ME!
|
330 |
*
|
331 |
* @return DOCUMENT ME!
|
332 |
*/
|
333 |
public Project getProject() {
|
334 |
return project;
|
335 |
} |
336 |
|
337 |
/**
|
338 |
* DOCUMENT ME!
|
339 |
*
|
340 |
* @param project DOCUMENT ME!
|
341 |
*/
|
342 |
public void setProject(Project project, int index) { |
343 |
this.project = project;
|
344 |
this.index = index;
|
345 |
} |
346 |
public int getIndex() { |
347 |
return index;
|
348 |
} |
349 |
|
350 |
public WindowInfo getViewInfo() {
|
351 |
if (view==null) |
352 |
return null; |
353 |
return PluginServices.getMDIManager().getWindowInfo(view);
|
354 |
} |
355 |
|
356 |
/* public void setViewInfo(ViewInfo viewInfo) {
|
357 |
this.viewInfo = viewInfo;
|
358 |
}*/
|
359 |
|
360 |
|
361 |
public com.iver.andami.ui.mdiManager.IWindow getAndamiView() {
|
362 |
return view;
|
363 |
} |
364 |
|
365 |
public void setAndamiView(com.iver.andami.ui.mdiManager.IWindow view) { |
366 |
this.view = view;
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* DOCUMENT ME!
|
371 |
*
|
372 |
* @return DOCUMENT ME!
|
373 |
* @throws SaveException
|
374 |
* @throws XMLException
|
375 |
* @throws SaveException
|
376 |
*/
|
377 |
public XMLEntity getViewInfoXMLEntity() throws SaveException { |
378 |
if (view!=null && PluginServices.getMDIManager().getWindowInfo(view)!=null) { |
379 |
WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(view); |
380 |
XMLEntity xml = new XMLEntity();
|
381 |
//xml.putProperty("nameClass", this.getClass().getName());
|
382 |
try{
|
383 |
xml.setName("ViewInfoProperties");
|
384 |
xml.putProperty("className", this.getClass().getName()); |
385 |
xml.putProperty("X", vi.getX());
|
386 |
xml.putProperty("Y", vi.getY());
|
387 |
xml.putProperty("Width", vi.getWidth());
|
388 |
xml.putProperty("Height", vi.getHeight());
|
389 |
xml.putProperty("isVisible", vi.isVisible());
|
390 |
xml.putProperty("isResizable", vi.isResizable());
|
391 |
xml.putProperty("isMaximizable", vi.isMaximizable());
|
392 |
xml.putProperty("isModal", vi.isModal());
|
393 |
xml.putProperty("isModeless", vi.isModeless());
|
394 |
xml.putProperty("isClosed", vi.isClosed());
|
395 |
if (vi.isMaximized()==true) { |
396 |
xml.putProperty("isMaximized", vi.isMaximized());
|
397 |
xml.putProperty("normalX", vi.getNormalX());
|
398 |
xml.putProperty("normalY", vi.getNormalY());
|
399 |
xml.putProperty("normalWidth", vi.getNormalWidth());
|
400 |
xml.putProperty("normalHeight", vi.getNormalHeight());
|
401 |
} |
402 |
}catch (Exception e) { |
403 |
throw new SaveException(e,this.getClass().getName()); |
404 |
} |
405 |
return xml;
|
406 |
} |
407 |
else
|
408 |
return null; |
409 |
} |
410 |
|
411 |
public static WindowInfo createViewInfoFromXMLEntity(XMLEntity xml) |
412 |
{ |
413 |
return Project.createWindowInfoFromXMLEntity(xml);
|
414 |
} |
415 |
|
416 |
public WindowInfo getSeedViewInfo() {
|
417 |
return seedViewInfo;
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* Locks this project element protecting it from deleting from the project.
|
422 |
*/
|
423 |
public void lock() { |
424 |
locked = true;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* Unlocks this element. So, from now on, it can be removed from the project.
|
429 |
*/
|
430 |
public void unlock() { |
431 |
locked = false;
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* Tells whether if this project's element is locked/protected or not. A protected
|
436 |
* element cannot be removed from the current project.
|
437 |
*
|
438 |
* @see <b>lock()</b> and <b>unlock()</b> methods.
|
439 |
*
|
440 |
* @return true if it is locked, false otherwise
|
441 |
*/
|
442 |
public boolean isLocked() { |
443 |
return locked;
|
444 |
} |
445 |
} |