svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 28153
History | View | Annotate | Download (10.7 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.ArrayList; |
48 |
import java.util.Date; |
49 |
import java.util.HashMap; |
50 |
import java.util.Iterator; |
51 |
|
52 |
import org.gvsig.fmap.dal.exception.ReadException; |
53 |
import org.gvsig.tools.ToolsLocator; |
54 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.andami.messages.NotificationManager; |
58 |
import com.iver.andami.ui.mdiManager.IWindow; |
59 |
import com.iver.cit.gvsig.project.Project; |
60 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
61 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
62 |
import com.iver.cit.gvsig.project.documents.gui.WindowData; |
63 |
import com.iver.utiles.XMLEntity; |
64 |
import com.iver.utiles.XMLException; |
65 |
|
66 |
|
67 |
/**
|
68 |
* Clase base de los elementos del proyecto (mapas, tablas y vistas)
|
69 |
*
|
70 |
* @author Fernando Gonz?lez Cort?s
|
71 |
*/
|
72 |
public abstract class ProjectDocument implements Serializable { |
73 |
public static HashMap<String,Integer> NUMS = new HashMap<String,Integer>(); |
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 WindowData windowData = null; |
83 |
private boolean isModified=false; |
84 |
private ProjectDocumentFactory projectDocumentFactory;
|
85 |
private ArrayList<ProjectDocumentListener> projectDocListener = new ArrayList<ProjectDocumentListener>(); |
86 |
|
87 |
/**
|
88 |
* Creates a new ProjectElement object.
|
89 |
*/
|
90 |
public ProjectDocument() {
|
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("nameRegister",this.getRegisterName());
|
200 |
xml.putProperty("className", projectDocumentFactory.getRegisterName());
|
201 |
xml.putProperty("comment", comment);
|
202 |
xml.putProperty("creationDate", creationDate);
|
203 |
xml.putProperty("name", name);
|
204 |
xml.putProperty("owner", owner);
|
205 |
}catch (Exception e) { |
206 |
throw new SaveException(e,this.getClass().getName()); |
207 |
} |
208 |
return xml;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* DOCUMENT ME!
|
213 |
*
|
214 |
* @param xml DOCUMENT ME!
|
215 |
* @param p DOCUMENT ME!
|
216 |
*
|
217 |
* @return DOCUMENT ME!
|
218 |
*
|
219 |
* @throws XMLException
|
220 |
* @throws DriverException
|
221 |
* @throws DriverIOException
|
222 |
* @throws OpenException
|
223 |
*/
|
224 |
public static ProjectDocument createFromXML(XMLEntity xml, Project p) |
225 |
throws XMLException {
|
226 |
ProjectDocumentFactory pde = null;
|
227 |
try {
|
228 |
pde = (ProjectDocumentFactory) ToolsLocator |
229 |
.getExtensionPointManager().get("Documents").create(
|
230 |
xml.getStringProperty("className"));
|
231 |
} catch (InstantiationException e) { |
232 |
NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
233 |
e); |
234 |
} catch (IllegalAccessException e) { |
235 |
NotificationManager.showMessageError(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"), |
236 |
e); |
237 |
}catch (Exception e) { |
238 |
throw new OpenException(e,xml.getStringProperty("className")); |
239 |
} |
240 |
if (pde==null){ |
241 |
Exception e=new Exception(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className")); |
242 |
NotificationManager.showMessageWarning(PluginServices.getText(p,"documento_no_reconocido")+": "+xml.getStringProperty("className"),e); |
243 |
throw new OpenException(e,xml.getStringProperty("className")); |
244 |
} |
245 |
ProjectDocument pe=pde.create(p); |
246 |
pe.setProjectDocumentFactory(pde); |
247 |
return pe;
|
248 |
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* DOCUMENT ME!
|
253 |
*
|
254 |
* @param xml DOCUMENT ME!
|
255 |
* @param p DOCUMENT ME!
|
256 |
*
|
257 |
* @throws XMLException
|
258 |
* @throws OpenException
|
259 |
* @throws ReadException
|
260 |
* @throws com.iver.utiles.XMLException
|
261 |
* @throws ReadDriverException
|
262 |
*/
|
263 |
public void setXMLEntity(XMLEntity xml) |
264 |
throws XMLException{
|
265 |
|
266 |
this.setComment(xml.getStringProperty("comment")); |
267 |
this.setCreationDate(xml.getStringProperty("creationDate")); |
268 |
this.setName(xml.getStringProperty("name")); |
269 |
this.setOwner(xml.getStringProperty("owner")); |
270 |
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* DOCUMENT ME!
|
275 |
*
|
276 |
* @return DOCUMENT ME!
|
277 |
*/
|
278 |
public Project getProject() {
|
279 |
return project;
|
280 |
} |
281 |
/**
|
282 |
* DOCUMENT ME!
|
283 |
*
|
284 |
* @param project DOCUMENT ME!
|
285 |
*/
|
286 |
public void setProject(Project project, int index) { |
287 |
this.project = project;
|
288 |
this.index = index;
|
289 |
} |
290 |
public int getIndex() { |
291 |
return index;
|
292 |
} |
293 |
|
294 |
/**
|
295 |
* Locks this project element protecting it from deleting from the project.
|
296 |
*/
|
297 |
public void lock() { |
298 |
locked = true;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* Unlocks this element. So, from now on, it can be removed from the project.
|
303 |
*/
|
304 |
public void unlock() { |
305 |
locked = false;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* Tells whether if this project's element is locked/protected or not. A protected
|
310 |
* element cannot be removed from the current project.
|
311 |
*
|
312 |
* @see <b>lock()</b> and <b>unlock()</b> methods.
|
313 |
*
|
314 |
* @return true if it is locked, false otherwise
|
315 |
*/
|
316 |
public boolean isLocked() { |
317 |
return locked;
|
318 |
} |
319 |
|
320 |
public abstract IWindow createWindow(); |
321 |
public abstract IWindow getProperties(); |
322 |
public abstract void afterRemove(); |
323 |
public abstract void afterAdd(); |
324 |
|
325 |
|
326 |
public void setProjectDocumentFactory( |
327 |
ProjectDocumentFactory projectDocumentFactory) { |
328 |
this.projectDocumentFactory = projectDocumentFactory;
|
329 |
} |
330 |
|
331 |
public ProjectDocumentFactory getProjectDocumentFactory() {
|
332 |
return projectDocumentFactory;
|
333 |
} |
334 |
|
335 |
public abstract void exportToXML(XMLEntity root, Project project) throws SaveException ; |
336 |
|
337 |
public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, OpenException, ReadException; |
338 |
|
339 |
|
340 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, OpenException, ReadException{ |
341 |
importFromXML(root,typeRoot, elementIndex,project,false);
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* Get the layout properties (size, position, state of the components)
|
346 |
* of the window associated with this ProjectDocument.
|
347 |
* This is used to re-open the window with the same properties it had
|
348 |
* when it was closed.
|
349 |
*
|
350 |
* @return A WindowData object storing the properties of the window.
|
351 |
*/
|
352 |
public WindowData getWindowData() {
|
353 |
return windowData;
|
354 |
} |
355 |
|
356 |
/**
|
357 |
* Store the layout properties (size, position, state of the components)
|
358 |
* of the window associated with this ProjectDocument.
|
359 |
* This is used to re-open the window with the same properties it had
|
360 |
* when it was closed.
|
361 |
*/
|
362 |
public void storeWindowData(WindowData data) { |
363 |
windowData = data; |
364 |
} |
365 |
|
366 |
public boolean isModified() { |
367 |
return isModified;
|
368 |
} |
369 |
|
370 |
public void setModified(boolean modified) { |
371 |
isModified=modified; |
372 |
} |
373 |
|
374 |
public static void initializeNUMS() { |
375 |
NUMS.clear(); |
376 |
Iterator<Extension> iterator = ToolsLocator.getExtensionPointManager()
|
377 |
.get( |
378 |
"Documents").iterator();
|
379 |
while (iterator.hasNext()) {
|
380 |
try {
|
381 |
ProjectDocumentFactory documentFactory = (ProjectDocumentFactory) iterator |
382 |
.next().create(); |
383 |
NUMS.put(documentFactory.getRegisterName(),new Integer(0)); |
384 |
} catch (InstantiationException e) { |
385 |
e.printStackTrace(); |
386 |
} catch (IllegalAccessException e) { |
387 |
e.printStackTrace(); |
388 |
} catch (ClassCastException e) { |
389 |
e.printStackTrace(); |
390 |
} |
391 |
} |
392 |
} |
393 |
/**
|
394 |
* Register a ProjectViewListener.
|
395 |
* @param listener
|
396 |
* ProjectViewListener
|
397 |
*/
|
398 |
public void addProjectViewListener(ProjectDocumentListener listener) { |
399 |
if(this.projectDocListener.indexOf(listener) == -1) |
400 |
this.projectDocListener.add(listener);
|
401 |
} |
402 |
/**
|
403 |
* Throw this event when a new window is created
|
404 |
* @param window
|
405 |
* IWindow created
|
406 |
*/
|
407 |
protected void callCreateWindow(IWindow window) { |
408 |
for (int i = 0; i < projectDocListener.size(); i++) |
409 |
projectDocListener.get(i).windowCreated(window); |
410 |
} |
411 |
} |