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 |
/* 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 |
|
85 |
/**
|
86 |
* Creates a new ProjectElement object.
|
87 |
*/
|
88 |
public ProjectElement() {
|
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("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 |
}catch (Exception e) { |
203 |
throw new SaveException(e,this.getClass().getName()); |
204 |
} |
205 |
return xml;
|
206 |
} |
207 |
|
208 |
/**
|
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 |
/**
|
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 |
* @throws OpenException
|
266 |
*/
|
267 |
public static ProjectElement createFromXML(XMLEntity xml, Project p) |
268 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
269 |
ProjectElement pe = null;
|
270 |
try{
|
271 |
Class clase;
|
272 |
|
273 |
try {
|
274 |
clase = Class.forName(xml.getStringProperty("className")); |
275 |
pe = (ProjectElement) clase.newInstance(); |
276 |
} 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 |
|
287 |
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 |
}catch (Exception e) { |
293 |
throw new OpenException(e,pe.getClass().getName()); |
294 |
} |
295 |
pe.setXMLEntity(xml, p); |
296 |
|
297 |
return pe;
|
298 |
} |
299 |
|
300 |
/**
|
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 |
* @throws OpenException
|
310 |
*/
|
311 |
public abstract void setXMLEntity(XMLEntity xml, Project p) |
312 |
throws XMLException, DriverException, DriverIOException, OpenException;
|
313 |
|
314 |
/**
|
315 |
* DOCUMENT ME!
|
316 |
*
|
317 |
* @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 |
* @return DOCUMENT ME!
|
331 |
*/
|
332 |
public Project getProject() {
|
333 |
return project;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* DOCUMENT ME!
|
338 |
*
|
339 |
* @param project DOCUMENT ME!
|
340 |
*/
|
341 |
public void setProject(Project project, int index) { |
342 |
this.project = project;
|
343 |
this.index = index;
|
344 |
} |
345 |
public int getIndex() { |
346 |
return index;
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Gets the window associated to this project element.
|
351 |
*/
|
352 |
public com.iver.andami.ui.mdiManager.IWindow getAndamiWindow() {
|
353 |
return window;
|
354 |
} |
355 |
|
356 |
/**
|
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 |
} |
363 |
|
364 |
/**
|
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 |
} |