root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 24759
History | View | Annotate | Download (10.4 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.documents; |
42 |
|
43 |
import java.beans.PropertyChangeListener; |
44 |
import java.beans.PropertyChangeSupport; |
45 |
import java.io.Serializable; |
46 |
import java.text.DateFormat; |
47 |
import java.util.Date; |
48 |
import java.util.HashMap; |
49 |
import java.util.Iterator; |
50 |
|
51 |
import org.gvsig.fmap.dal.exception.ReadException; |
52 |
import org.gvsig.tools.exception.DriverException; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.messages.NotificationManager; |
56 |
import com.iver.andami.ui.mdiManager.IWindow; |
57 |
import com.iver.cit.gvsig.project.Project; |
58 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
59 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
60 |
import com.iver.cit.gvsig.project.documents.gui.WindowData; |
61 |
import com.iver.utiles.XMLEntity; |
62 |
import com.iver.utiles.XMLException; |
63 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
64 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
65 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
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 ProjectDocument implements Serializable { |
74 |
public static HashMap<String,Integer> NUMS = new HashMap<String,Integer>(); |
75 |
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 |
private boolean locked = false; |
83 |
protected WindowData windowData = null; |
84 |
private boolean isModified=false; |
85 |
private ProjectDocumentFactory projectDocumentFactory;
|
86 |
/**
|
87 |
* Creates a new ProjectElement object.
|
88 |
*/
|
89 |
public ProjectDocument() {
|
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("nameRegister",this.getRegisterName());
|
199 |
xml.putProperty("className", projectDocumentFactory.getRegisterName());
|
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 |
*
|
218 |
* @throws XMLException
|
219 |
* @throws DriverException
|
220 |
* @throws DriverIOException
|
221 |
* @throws OpenException
|
222 |
*/
|
223 |
public static ProjectDocument createFromXML(XMLEntity xml, Project p) |
224 |
throws XMLException {
|
225 |
ProjectDocumentFactory pde = null;
|
226 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
227 |
ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
|
228 |
try {
|
229 |
pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
|
230 |
} catch (InstantiationException e) { |
231 |
NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
232 |
e); |
233 |
} catch (IllegalAccessException e) { |
234 |
NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
235 |
e); |
236 |
}catch (Exception e) { |
237 |
throw new OpenException(e,xml.getStringProperty("className")); |
238 |
} |
239 |
if (pde==null){ |
240 |
Exception e=new Exception(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className")); |
241 |
NotificationManager.showMessageWarning(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"),e); |
242 |
throw new OpenException(e,xml.getStringProperty("className")); |
243 |
} |
244 |
ProjectDocument pe=pde.create(p); |
245 |
pe.setProjectDocumentFactory(pde); |
246 |
return pe;
|
247 |
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* DOCUMENT ME!
|
252 |
*
|
253 |
* @param xml DOCUMENT ME!
|
254 |
* @param p DOCUMENT ME!
|
255 |
*
|
256 |
* @throws XMLException
|
257 |
* @throws OpenException
|
258 |
* @throws ReadException
|
259 |
* @throws com.iver.utiles.XMLException
|
260 |
* @throws ReadDriverException
|
261 |
*/
|
262 |
public void setXMLEntity(XMLEntity xml) |
263 |
throws XMLException{
|
264 |
|
265 |
this.setComment(xml.getStringProperty("comment")); |
266 |
this.setCreationDate(xml.getStringProperty("creationDate")); |
267 |
this.setName(xml.getStringProperty("name")); |
268 |
this.setOwner(xml.getStringProperty("owner")); |
269 |
|
270 |
} |
271 |
|
272 |
/**
|
273 |
* DOCUMENT ME!
|
274 |
*
|
275 |
* @return DOCUMENT ME!
|
276 |
*/
|
277 |
public Project getProject() {
|
278 |
return project;
|
279 |
} |
280 |
/**
|
281 |
* DOCUMENT ME!
|
282 |
*
|
283 |
* @param project DOCUMENT ME!
|
284 |
*/
|
285 |
public void setProject(Project project, int index) { |
286 |
this.project = project;
|
287 |
this.index = index;
|
288 |
} |
289 |
public int getIndex() { |
290 |
return index;
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* Locks this project element protecting it from deleting from the project.
|
295 |
*/
|
296 |
public void lock() { |
297 |
locked = true;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* Unlocks this element. So, from now on, it can be removed from the project.
|
302 |
*/
|
303 |
public void unlock() { |
304 |
locked = false;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Tells whether if this project's element is locked/protected or not. A protected
|
309 |
* element cannot be removed from the current project.
|
310 |
*
|
311 |
* @see <b>lock()</b> and <b>unlock()</b> methods.
|
312 |
*
|
313 |
* @return true if it is locked, false otherwise
|
314 |
*/
|
315 |
public boolean isLocked() { |
316 |
return locked;
|
317 |
} |
318 |
|
319 |
public abstract IWindow createWindow(); |
320 |
public abstract IWindow getProperties(); |
321 |
public abstract void afterRemove(); |
322 |
public abstract void afterAdd(); |
323 |
|
324 |
|
325 |
public void setProjectDocumentFactory( |
326 |
ProjectDocumentFactory projectDocumentFactory) { |
327 |
this.projectDocumentFactory = projectDocumentFactory;
|
328 |
} |
329 |
|
330 |
public ProjectDocumentFactory getProjectDocumentFactory() {
|
331 |
return projectDocumentFactory;
|
332 |
} |
333 |
|
334 |
public abstract void exportToXML(XMLEntity root, Project project) throws SaveException ; |
335 |
|
336 |
public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, OpenException, ReadException; |
337 |
|
338 |
|
339 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, OpenException, ReadException{ |
340 |
importFromXML(root,typeRoot, elementIndex,project,false);
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* Get the layout properties (size, position, state of the components)
|
345 |
* of the window associated with this ProjectDocument.
|
346 |
* This is used to re-open the window with the same properties it had
|
347 |
* when it was closed.
|
348 |
*
|
349 |
* @return A WindowData object storing the properties of the window.
|
350 |
*/
|
351 |
public WindowData getWindowData() {
|
352 |
return windowData;
|
353 |
} |
354 |
|
355 |
/**
|
356 |
* Store the layout properties (size, position, state of the components)
|
357 |
* of the window associated with this ProjectDocument.
|
358 |
* This is used to re-open the window with the same properties it had
|
359 |
* when it was closed.
|
360 |
*/
|
361 |
public void storeWindowData(WindowData data) { |
362 |
windowData = data; |
363 |
} |
364 |
|
365 |
public boolean isModified() { |
366 |
return isModified;
|
367 |
} |
368 |
|
369 |
public void setModified(boolean modified) { |
370 |
isModified=modified; |
371 |
} |
372 |
|
373 |
public static void initializeNUMS() { |
374 |
NUMS.clear(); |
375 |
ExtensionPoints extensionPoints = |
376 |
ExtensionPointsSingleton.getInstance(); |
377 |
ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("Documents");
|
378 |
Iterator iterator = extensionPoint.keySet().iterator();
|
379 |
while (iterator.hasNext()) {
|
380 |
try {
|
381 |
ProjectDocumentFactory documentFactory = (ProjectDocumentFactory)extensionPoint.create((String)iterator.next());
|
382 |
NUMS.put(documentFactory.getRegisterName(),new Integer(0)); |
383 |
} catch (InstantiationException e) { |
384 |
e.printStackTrace(); |
385 |
} catch (IllegalAccessException e) { |
386 |
e.printStackTrace(); |
387 |
} catch (ClassCastException e) { |
388 |
e.printStackTrace(); |
389 |
} |
390 |
} |
391 |
} |
392 |
} |