svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / Project.java @ 27723
History | View | Annotate | Download (59.4 KB)
1 | 12728 | jaume | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 1222 | fernando | *
|
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 | 12728 | jaume | * Av. Blasco Ib��ez, 50
|
24 | 1222 | fernando | * 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 | 2217 | fernando | import java.awt.Color; |
44 | import java.beans.PropertyChangeEvent; |
||
45 | import java.beans.PropertyChangeListener; |
||
46 | import java.beans.PropertyChangeSupport; |
||
47 | import java.io.Serializable; |
||
48 | import java.text.DateFormat; |
||
49 | import java.util.ArrayList; |
||
50 | 7343 | caballero | import java.util.Comparator; |
51 | 2217 | fernando | import java.util.Date; |
52 | 3060 | fjp | import java.util.Hashtable; |
53 | 2217 | fernando | import java.util.Iterator; |
54 | 8137 | jcampos | import java.util.List; |
55 | 7343 | caballero | import java.util.TreeMap; |
56 | 1222 | fernando | |
57 | 2217 | fernando | import org.cresques.cts.IProjection; |
58 | 20994 | jmvivo | import org.gvsig.fmap.crs.CRSFactory; |
59 | 24929 | vcaballero | import org.gvsig.fmap.dal.exception.ReadException; |
60 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
61 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
62 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
63 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
64 | 24929 | vcaballero | import org.gvsig.project.document.table.FeatureTableDocument; |
65 | import org.gvsig.project.document.table.FeatureTableDocumentFactory; |
||
66 | 24962 | vcaballero | import org.gvsig.project.document.table.LinkSelectionObserver; |
67 | 24956 | jmvivo | import org.gvsig.tools.ToolsLocator; |
68 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
69 | 1222 | fernando | |
70 | 5029 | cesar | import com.iver.andami.PluginServices; |
71 | 7753 | jmvivo | import com.iver.andami.messages.NotificationManager; |
72 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
73 | 7689 | cesar | import com.iver.andami.ui.mdiManager.SingletonWindow; |
74 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
75 | 7689 | cesar | import com.iver.cit.gvsig.ProjectExtension; |
76 | 7753 | jmvivo | import com.iver.cit.gvsig.Version; |
77 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
78 | 7343 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
79 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
80 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
81 | 9199 | maquerol | import com.iver.cit.gvsig.project.documents.gui.IDocumentWindow; |
82 | 7343 | caballero | import com.iver.cit.gvsig.project.documents.gui.ProjectWindow; |
83 | 9044 | cesar | import com.iver.cit.gvsig.project.documents.gui.WindowData; |
84 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.layout.ProjectMap; |
85 | 7379 | caballero | import com.iver.cit.gvsig.project.documents.layout.ProjectMapFactory; |
86 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
87 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.ProjectView; |
88 | 7379 | caballero | import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
89 | 13913 | jaume | import com.iver.utiles.IPersistence; |
90 | 2673 | fjp | import com.iver.utiles.PostProcessSupport; |
91 | 1222 | fernando | import com.iver.utiles.StringUtilities; |
92 | import com.iver.utiles.XMLEntity; |
||
93 | 23176 | vcaballero | import com.iver.utiles.XMLException; |
94 | 1222 | fernando | |
95 | /**
|
||
96 | * Clase que representa un proyecto de openSIG
|
||
97 | 9237 | caballero | *
|
98 | 12728 | jaume | * @author Fernando Gonz�lez Cort�s
|
99 | 1222 | fernando | */
|
100 | public class Project implements Serializable, PropertyChangeListener { |
||
101 | 11334 | jmvivo | public static String VERSION = Version.format(); |
102 | 7654 | jaume | |
103 | 11334 | jmvivo | static private IProjection defaultProjection = null; |
104 | |||
105 | static private IProjection defaultFactoryProjection = CRSFactory |
||
106 | 8137 | jcampos | .getCRS("EPSG:23030");
|
107 | |||
108 | 7654 | jaume | /*
|
109 | 8137 | jcampos | * distiguishing between a static field "defaultSelectionColor" and a
|
110 | * selectionColor field will allow to define default color in a multiple
|
||
111 | 7654 | jaume | * project scenario
|
112 | */
|
||
113 | 7766 | jaume | static private Color defaultSelectionColor = Color.YELLOW; |
114 | 8137 | jcampos | |
115 | 7787 | jaume | private static int defaultMapUnits = -1; |
116 | 8137 | jcampos | |
117 | 7787 | jaume | private static int defaultDistanceUnits = -1; |
118 | 7654 | jaume | |
119 | 20334 | vcaballero | private static int defaultDistanceArea = -1; |
120 | |||
121 | 1222 | fernando | private PropertyChangeSupport change; |
122 | 8137 | jcampos | |
123 | 9532 | caballero | private boolean modified = false; |
124 | 8137 | jcampos | |
125 | 10679 | jaume | private String name = PluginServices.getText(this, "untitled"); |
126 | 8137 | jcampos | |
127 | // private String path;
|
||
128 | 10679 | jaume | private String creationDate = new Date().toGMTString(); |
129 | 8137 | jcampos | |
130 | 10679 | jaume | private String modificationDate = new Date().toGMTString(); |
131 | 8137 | jcampos | |
132 | 10679 | jaume | private String owner = ""; |
133 | 8137 | jcampos | |
134 | 10679 | jaume | private String comments = ""; |
135 | 8137 | jcampos | |
136 | 7654 | jaume | private Color selectionColor = null; |
137 | 8137 | jcampos | |
138 | // private ArrayList views = new ArrayList();
|
||
139 | // private ArrayList tables = new ArrayList();
|
||
140 | // private ArrayList maps = new ArrayList();
|
||
141 | 17092 | vcaballero | private ArrayList<ProjectDocument> documents = new ArrayList<ProjectDocument>(); |
142 | 8137 | jcampos | |
143 | 1222 | fernando | private ArrayList extents = new ArrayList(); |
144 | 8137 | jcampos | |
145 | // Lista de objetos del tipo camera. Necesarios para almacenar la posicion
|
||
146 | // del usuario haciendo uso de los marcadores
|
||
147 | private List cameras = new ArrayList(); |
||
148 | |||
149 | 10679 | jaume | /**
|
150 | * this is a runtime-calculated value, do NOT persist it!
|
||
151 | */
|
||
152 | private long signatureAtStartup; |
||
153 | 7222 | jaume | private IProjection projection;
|
154 | 8137 | jcampos | |
155 | 7689 | cesar | /**
|
156 | 8137 | jcampos | * Stores the initial properties of the windows, to be restored just after
|
157 | * the project is loaded. It's an ordered iterator of XMLEntity objects,
|
||
158 | * each containing a XML version of a WindowInfo object.
|
||
159 | 7689 | cesar | */
|
160 | private Iterator initialWindowProperties = null; |
||
161 | 7766 | jaume | |
162 | 17092 | vcaballero | private TreeMap<ProjectDocument,Integer> sortedDocuments = new TreeMap<ProjectDocument,Integer>(new Comparator() { |
163 | 7787 | jaume | public int compare(Object o1, Object o2) { |
164 | if ((o1 != null) && (o2 != null)) { |
||
165 | 8137 | jcampos | int priority1 = ((ProjectDocument) o1)
|
166 | .getProjectDocumentFactory().getPriority(); |
||
167 | int priority2 = ((ProjectDocument) o2)
|
||
168 | .getProjectDocumentFactory().getPriority(); |
||
169 | 24759 | jmvivo | if (priority1 >= priority2) {
|
170 | 7787 | jaume | return 1; |
171 | 24759 | jmvivo | } |
172 | 7787 | jaume | return -1; |
173 | } |
||
174 | return 0; |
||
175 | } |
||
176 | }); // Para poder ordenar
|
||
177 | 7766 | jaume | |
178 | 1222 | fernando | /**
|
179 | * Creates a new Project object.
|
||
180 | */
|
||
181 | public Project() {
|
||
182 | change = new PropertyChangeSupport(this); |
||
183 | |||
184 | 8137 | jcampos | // change.addPropertyChangeListener(this);
|
185 | 1222 | fernando | creationDate = DateFormat.getDateInstance().format(new Date()); |
186 | modificationDate = creationDate; |
||
187 | 7766 | jaume | setSelectionColor(getDefaultSelectionColor()); |
188 | 11341 | jmvivo | getDefaultProjection(); //For initialize it
|
189 | 8137 | jcampos | // signatureAtStartup = computeSignature();
|
190 | 1222 | fernando | |
191 | 8137 | jcampos | /*
|
192 | * LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
|
||
193 | * .getPluginDirectory() .getAbsolutePath() + File.separator +
|
||
194 | * "drivers");
|
||
195 | 2183 | fernando | */
|
196 | } |
||
197 | |||
198 | 1222 | fernando | /**
|
199 | 12728 | jaume | * Obtiene la fecha de creaci�n del proyecto
|
200 | 9237 | caballero | *
|
201 | 1222 | fernando | * @return
|
202 | */
|
||
203 | public String getCreationDate() { |
||
204 | return creationDate;
|
||
205 | } |
||
206 | |||
207 | /**
|
||
208 | * Obtiene el nombre del proyecto
|
||
209 | 9237 | caballero | *
|
210 | 1222 | fernando | * @return
|
211 | */
|
||
212 | public String getName() { |
||
213 | return name;
|
||
214 | } |
||
215 | |||
216 | 8137 | jcampos | // /**
|
217 | 12728 | jaume | // * Obtiene la ruta completa del fichero donde se guardo por �ltima vez el
|
218 | 8137 | jcampos | // * proyecto
|
219 | // *
|
||
220 | // * @return
|
||
221 | // */
|
||
222 | // public String getPath() {
|
||
223 | // return path;
|
||
224 | // }
|
||
225 | 1222 | fernando | |
226 | /**
|
||
227 | 12728 | jaume | * Asigna la fecha de creaci�n del proyecto. Este m�todo tiene sentido s�lo
|
228 | 1222 | fernando | * por que al recuperar la fecha del XML hay que asignarla al objeto
|
229 | * proyecto de alguna manera. La fecha se asigna en el constructor y no se
|
||
230 | 12728 | jaume | * deber�a de modificar nunca
|
231 | 9237 | caballero | *
|
232 | 1222 | fernando | * @param string
|
233 | */
|
||
234 | public void setCreationDate(String string) { |
||
235 | creationDate = string; |
||
236 | 9532 | caballero | //modified = true;
|
237 | 1222 | fernando | change.firePropertyChange("", null, null); |
238 | } |
||
239 | |||
240 | /**
|
||
241 | * Establece el nombre del proyecto
|
||
242 | 9237 | caballero | *
|
243 | 1222 | fernando | * @param string
|
244 | */
|
||
245 | public void setName(String string) { |
||
246 | name = string; |
||
247 | 9532 | caballero | //modified = true;
|
248 | 1222 | fernando | change.firePropertyChange("", null, null); |
249 | } |
||
250 | |||
251 | /**
|
||
252 | 7532 | caballero | * Devuelve a partir de la capa la tabla asociada.
|
253 | 9237 | caballero | *
|
254 | 8137 | jcampos | * @param co
|
255 | * Capa.
|
||
256 | 9237 | caballero | *
|
257 | 7532 | caballero | * @return ProjectTable de la tabla asociada.
|
258 | 1222 | fernando | */
|
259 | 24929 | vcaballero | public FeatureTableDocument getTable(FLyrVect co) {
|
260 | ArrayList tables = getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
||
261 | 1222 | fernando | /**
|
262 | 12728 | jaume | * Como las tablas se pueden a�adir cuando se pincha en "ver tabla" de
|
263 | * una capa, se puede intentar a�adir dos veces la misma tabla
|
||
264 | 1222 | fernando | */
|
265 | for (int i = 0; i < tables.size(); i++) { |
||
266 | 24929 | vcaballero | try {
|
267 | if (((FeatureTableDocument) tables.get(i)).getStore().equals(co.getFeatureStore())){
|
||
268 | // if (((FeatureTableDocument) tables.get(i)).getAssociatedTable() == co) {
|
||
269 | return (FeatureTableDocument) tables.get(i);
|
||
270 | } |
||
271 | } catch (ReadException e) {
|
||
272 | e.printStackTrace(); |
||
273 | 1222 | fernando | } |
274 | } |
||
275 | |||
276 | return null; |
||
277 | } |
||
278 | |||
279 | 7532 | caballero | /**
|
280 | * Devuelve a partir del nombre la tabla asociada.
|
||
281 | 9237 | caballero | *
|
282 | 8137 | jcampos | * @param name
|
283 | * Nombre.
|
||
284 | 7532 | caballero | * @deprecated utilizar getProjectDocumentByName(...);
|
285 | * @return ProjectTable de la tabla asociada.
|
||
286 | */
|
||
287 | 24929 | vcaballero | public FeatureTableDocument getTable(String name) { |
288 | ArrayList tables = getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
||
289 | 6451 | jmvivo | /**
|
290 | 12728 | jaume | * Como las tablas se pueden a�adir cuando se pincha en "ver tabla" de
|
291 | * una capa, se puede intentar a�adir dos veces la misma tabla
|
||
292 | 6451 | jmvivo | */
|
293 | for (int i = 0; i < tables.size(); i++) { |
||
294 | 24929 | vcaballero | if (((FeatureTableDocument) tables.get(i)).getName().equals(name)) {
|
295 | return (FeatureTableDocument) tables.get(i);
|
||
296 | 6451 | jmvivo | } |
297 | } |
||
298 | |||
299 | return null; |
||
300 | } |
||
301 | |||
302 | 9532 | caballero | private boolean isModifiedDocuments() { |
303 | 24759 | jmvivo | ProjectDocument[] documents=getDocuments().toArray(new ProjectDocument[0]); |
304 | 9532 | caballero | for (int i=0;i<documents.length;i++) { |
305 | if (documents[i].isModified()) {
|
||
306 | return true; |
||
307 | } |
||
308 | } |
||
309 | return false; |
||
310 | } |
||
311 | 10679 | jaume | // /**
|
312 | // * Devuelve true si el proyecto (o alguna tabla, vista o mapa que contiene)
|
||
313 | // * fue modificado
|
||
314 | // *
|
||
315 | // * @return
|
||
316 | // */
|
||
317 | // public boolean isModified() {
|
||
318 | // if ((this.getDocuments().size() == 0) && !modified && !isModifiedDocuments()) {
|
||
319 | // return false;
|
||
320 | // }
|
||
321 | // return true;
|
||
322 | // // /return modified; TODO El atributo modified solo detecta cuando se
|
||
323 | 12728 | jaume | // // elimina o a�ade una vista,
|
324 | 10679 | jaume | // // /mapa o tabla pero no cuando se modifican.
|
325 | // }
|
||
326 | 1222 | fernando | |
327 | /**
|
||
328 | * Obtiene los comentarios
|
||
329 | 9237 | caballero | *
|
330 | 1222 | fernando | * @return
|
331 | */
|
||
332 | public String getComments() { |
||
333 | return comments;
|
||
334 | } |
||
335 | |||
336 | /**
|
||
337 | 12728 | jaume | * Obtiene la fecha de la �ltima modificaci�n
|
338 | 9237 | caballero | *
|
339 | 1222 | fernando | * @return
|
340 | */
|
||
341 | public String getModificationDate() { |
||
342 | return modificationDate;
|
||
343 | } |
||
344 | |||
345 | /**
|
||
346 | * Obtiene el propietario del proyecto
|
||
347 | 9237 | caballero | *
|
348 | 1222 | fernando | * @return
|
349 | */
|
||
350 | public String getOwner() { |
||
351 | return owner;
|
||
352 | } |
||
353 | |||
354 | /**
|
||
355 | * Establece una cadena como comentarios al proyecto
|
||
356 | 9237 | caballero | *
|
357 | 1222 | fernando | * @param string
|
358 | */
|
||
359 | public void setComments(String string) { |
||
360 | comments = string; |
||
361 | 9532 | caballero | //modified = true;
|
362 | 1222 | fernando | change.firePropertyChange("", null, null); |
363 | } |
||
364 | |||
365 | /**
|
||
366 | 12728 | jaume | * Establece la fecha de la �ltima modificaci�n
|
367 | 9237 | caballero | *
|
368 | 1222 | fernando | * @param string
|
369 | */
|
||
370 | public void setModificationDate(String string) { |
||
371 | modificationDate = string; |
||
372 | 9532 | caballero | //modified = true;
|
373 | 1222 | fernando | change.firePropertyChange("", null, null); |
374 | } |
||
375 | |||
376 | /**
|
||
377 | * Establece el propietario del proyecto
|
||
378 | 9237 | caballero | *
|
379 | 1222 | fernando | * @param string
|
380 | */
|
||
381 | public void setOwner(String string) { |
||
382 | owner = string; |
||
383 | 9532 | caballero | //modified = true;
|
384 | 1222 | fernando | change.firePropertyChange("", null, null); |
385 | } |
||
386 | |||
387 | /**
|
||
388 | * Establece el flag de modificado del proyecto
|
||
389 | 9237 | caballero | *
|
390 | 1222 | fernando | * @param b
|
391 | */
|
||
392 | public void setModified(boolean b) { |
||
393 | modified = b; |
||
394 | 9532 | caballero | if (modified==false) { |
395 | 24759 | jmvivo | ProjectDocument[] documents=getDocuments().toArray(new ProjectDocument[0]); |
396 | 9532 | caballero | for (int i=0;i<documents.length;i++) { |
397 | documents[i].setModified(false);
|
||
398 | } |
||
399 | } |
||
400 | 1222 | fernando | } |
401 | |||
402 | /**
|
||
403 | 12728 | jaume | * Obtiene el color de selecci�n que se usar� en el proyecto
|
404 | 9237 | caballero | *
|
405 | 1222 | fernando | * @return
|
406 | */
|
||
407 | public Color getSelectionColor() { |
||
408 | 7654 | jaume | if (selectionColor == null) { |
409 | selectionColor = defaultSelectionColor; |
||
410 | } |
||
411 | 1222 | fernando | return selectionColor;
|
412 | } |
||
413 | |||
414 | /**
|
||
415 | 12728 | jaume | * Establece el color de selecci�n
|
416 | 9237 | caballero | *
|
417 | 1222 | fernando | * @param color
|
418 | */
|
||
419 | public void setSelectionColor(Color color) { |
||
420 | selectionColor = color; |
||
421 | 12728 | jaume | MapContext.setSelectionColor(color); |
422 | 9532 | caballero | //modified = true;
|
423 | 1222 | fernando | change.firePropertyChange("selectionColor", null, color); |
424 | } |
||
425 | |||
426 | /**
|
||
427 | 12728 | jaume | * Obtiene el color como un entero para su serializaci�n a XML
|
428 | 9237 | caballero | *
|
429 | 1222 | fernando | * @return
|
430 | */
|
||
431 | public String getColor() { |
||
432 | return StringUtilities.color2String(selectionColor);
|
||
433 | } |
||
434 | |||
435 | /**
|
||
436 | 12728 | jaume | * M�todo invocado al recuperar de XML para establecer el color de seleccion
|
437 | 8137 | jcampos | * del proyecto
|
438 | 9237 | caballero | *
|
439 | 8137 | jcampos | * @param color
|
440 | * Entero que representa un color
|
||
441 | 1222 | fernando | */
|
442 | public void setColor(String color) { |
||
443 | 9532 | caballero | //modified = true;
|
444 | 1222 | fernando | selectionColor = StringUtilities.string2Color(color); |
445 | } |
||
446 | |||
447 | 8137 | jcampos | /*
|
448 | * (non-Javadoc)
|
||
449 | 9237 | caballero | *
|
450 | 1222 | fernando | * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
451 | */
|
||
452 | public void propertyChange(PropertyChangeEvent evt) { |
||
453 | 9532 | caballero | //this.modified = true;
|
454 | 1222 | fernando | change.firePropertyChange(evt); |
455 | } |
||
456 | |||
457 | /**
|
||
458 | * DOCUMENT ME!
|
||
459 | 9237 | caballero | *
|
460 | 1222 | fernando | * @param arg1
|
461 | */
|
||
462 | public void addExtent(ProjectExtent arg1) { |
||
463 | extents.add(arg1); |
||
464 | 9532 | caballero | //modified = true;
|
465 | 1222 | fernando | change.firePropertyChange("addExtent", null, null); |
466 | } |
||
467 | |||
468 | /**
|
||
469 | * DOCUMENT ME!
|
||
470 | 9237 | caballero | *
|
471 | 1222 | fernando | * @param arg0
|
472 | 9237 | caballero | *
|
473 | 1222 | fernando | * @return
|
474 | */
|
||
475 | public Object removeExtent(int arg0) { |
||
476 | 9532 | caballero | //modified = true;
|
477 | 1222 | fernando | change.firePropertyChange("delExtent", null, null); |
478 | |||
479 | return extents.remove(arg0);
|
||
480 | } |
||
481 | |||
482 | /**
|
||
483 | * DOCUMENT ME!
|
||
484 | 9237 | caballero | *
|
485 | 1222 | fernando | * @return DOCUMENT ME!
|
486 | */
|
||
487 | public ProjectExtent[] getExtents() { |
||
488 | return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]); |
||
489 | } |
||
490 | |||
491 | /**
|
||
492 | 12728 | jaume | * Metodo que a�ade una nueva camera a la lista de cameras
|
493 | 9237 | caballero | *
|
494 | 8137 | jcampos | * @param arg1
|
495 | * camera introducida
|
||
496 | */
|
||
497 | public void addCamera(Object arg1) { |
||
498 | this.cameras.add(arg1);
|
||
499 | 9532 | caballero | //modified = true;
|
500 | 8137 | jcampos | change.firePropertyChange("addCamera", null, null); |
501 | } |
||
502 | |||
503 | /**
|
||
504 | * Metodo que borra de la lisat un elemento seleccionado
|
||
505 | 9237 | caballero | *
|
506 | 8137 | jcampos | * @param arg0
|
507 | * indice del elemento que se va a borrar
|
||
508 | 9237 | caballero | *
|
509 | 8137 | jcampos | * @return resultado de la operacion de borrado
|
510 | */
|
||
511 | public Object removeCamera(int arg0) { |
||
512 | 9532 | caballero | //modified = true;
|
513 | 8137 | jcampos | change.firePropertyChange("delCamera", null, null); |
514 | |||
515 | return this.cameras.remove(arg0); |
||
516 | } |
||
517 | |||
518 | /**
|
||
519 | * Metodo que devuelve la lista de cameras
|
||
520 | 9237 | caballero | *
|
521 | 8137 | jcampos | * @return lista de objetos de tipo camera
|
522 | */
|
||
523 | public Object[] getCameras() { |
||
524 | 24759 | jmvivo | return this.cameras.toArray(new Object[0]); |
525 | 8137 | jcampos | } |
526 | |||
527 | /**
|
||
528 | 1222 | fernando | * DOCUMENT ME!
|
529 | 9237 | caballero | *
|
530 | 1222 | fernando | * @param arg0
|
531 | */
|
||
532 | public synchronized void addPropertyChangeListener( |
||
533 | 8137 | jcampos | PropertyChangeListener arg0) {
|
534 | 1222 | fernando | change.addPropertyChangeListener(arg0); |
535 | } |
||
536 | |||
537 | /**
|
||
538 | * DOCUMENT ME!
|
||
539 | 9237 | caballero | *
|
540 | 7304 | caballero | * @deprecated utilizar getDocument(String s);
|
541 | 1222 | fernando | * @return
|
542 | */
|
||
543 | public ArrayList getMaps() { |
||
544 | 7379 | caballero | return getDocumentsByType(ProjectMapFactory.registerName);
|
545 | 1222 | fernando | } |
546 | |||
547 | /**
|
||
548 | * DOCUMENT ME!
|
||
549 | 9237 | caballero | *
|
550 | 7304 | caballero | * @deprecated utilizar getDocument(String s);
|
551 | 1222 | fernando | * @return
|
552 | */
|
||
553 | public ArrayList getTables() { |
||
554 | 24929 | vcaballero | return getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
555 | 1222 | fernando | } |
556 | |||
557 | /**
|
||
558 | * DOCUMENT ME!
|
||
559 | 9237 | caballero | *
|
560 | 7304 | caballero | * @deprecated utilizar getDocument(String s);
|
561 | 1222 | fernando | * @return
|
562 | */
|
||
563 | public ArrayList getViews() { |
||
564 | 7379 | caballero | return getDocumentsByType(ProjectViewFactory.registerName);
|
565 | 1222 | fernando | } |
566 | 8137 | jcampos | |
567 | 7304 | caballero | /**
|
568 | 12728 | jaume | * A�ade un mapa al proyecto
|
569 | 9237 | caballero | *
|
570 | 7304 | caballero | * @deprecated utilizar addDocument(ProjectDocument pD);
|
571 | * @param m
|
||
572 | */
|
||
573 | public void addMap(ProjectMap m) { |
||
574 | addDocument(m); |
||
575 | } |
||
576 | 1222 | fernando | |
577 | /**
|
||
578 | 7304 | caballero | * Elimina un mapa del proyecto
|
579 | 9237 | caballero | *
|
580 | 7304 | caballero | * @deprecated utilizar delDocument(ProjectDocument pD);
|
581 | 8137 | jcampos | * @param i
|
582 | * indice del mapa
|
||
583 | 7304 | caballero | */
|
584 | public void delMap(int i) { |
||
585 | 8137 | jcampos | ArrayList list = getDocumentsByType(ProjectMapFactory.registerName);
|
586 | delDocument((ProjectDocument) list.get(i)); |
||
587 | 7304 | caballero | } |
588 | 8137 | jcampos | |
589 | 7304 | caballero | /**
|
590 | 12728 | jaume | * A�ade una tabla al proyecto
|
591 | 9237 | caballero | *
|
592 | 7304 | caballero | * @deprecated utilizar addDocument(ProjectDocument pD);
|
593 | * @param t
|
||
594 | */
|
||
595 | 24929 | vcaballero | public void addTable(FeatureTableDocument t) { |
596 | 7304 | caballero | addDocument(t); |
597 | } |
||
598 | |||
599 | /**
|
||
600 | * Elimina una tabla del proyecto
|
||
601 | 9237 | caballero | *
|
602 | 7304 | caballero | * @deprecated utilizar delDocument(ProjectDocument pD);
|
603 | 8137 | jcampos | * @param i
|
604 | * indice de la tabla
|
||
605 | 7304 | caballero | */
|
606 | public void delTable(int i) { |
||
607 | 24929 | vcaballero | ArrayList list = getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
608 | 8137 | jcampos | delDocument((ProjectDocument) list.get(i)); |
609 | 7304 | caballero | } |
610 | 8137 | jcampos | |
611 | 7304 | caballero | /**
|
612 | 12728 | jaume | * A�ade una vista al proyecto
|
613 | 9237 | caballero | *
|
614 | 7304 | caballero | * @deprecated utilizar addDocument(ProjectDocument pD);
|
615 | * @param v
|
||
616 | */
|
||
617 | public void addView(ProjectView v) { |
||
618 | addDocument(v); |
||
619 | } |
||
620 | |||
621 | /**
|
||
622 | * Elimina una tabla del proyecto
|
||
623 | 9237 | caballero | *
|
624 | 7304 | caballero | * @deprecated utilizar delDocument(ProjectDocument pD);
|
625 | 8137 | jcampos | * @param i
|
626 | * indice del proyecto
|
||
627 | 7304 | caballero | */
|
628 | public void delView(int i) { |
||
629 | 8137 | jcampos | ArrayList list = getDocumentsByType(ProjectViewFactory.registerName);
|
630 | delDocument((ProjectDocument) list.get(i)); |
||
631 | 7304 | caballero | } |
632 | |||
633 | /**
|
||
634 | 1222 | fernando | * DOCUMENT ME!
|
635 | 9237 | caballero | *
|
636 | 1222 | fernando | * @return DOCUMENT ME!
|
637 | 23176 | vcaballero | * @throws com.iver.utiles.XMLException
|
638 | 9237 | caballero | *
|
639 | 1222 | fernando | * @throws DriverException
|
640 | 1830 | fernando | * @throws XMLException
|
641 | 1222 | fernando | */
|
642 | 23176 | vcaballero | public XMLEntity getXMLEntity() throws XMLException { |
643 | 1222 | fernando | XMLEntity xml = new XMLEntity();
|
644 | 1830 | fernando | xml.putProperty("className", this.getClass().getName()); |
645 | xml.putProperty("VERSION", VERSION);
|
||
646 | 10679 | jaume | xml.putProperty("comments", getComments());
|
647 | 1222 | fernando | xml.putProperty("creationDate", creationDate);
|
648 | |||
649 | 1302 | vcaballero | int numExtents = extents.size();
|
650 | 1830 | fernando | xml.putProperty("numExtents", numExtents);
|
651 | |||
652 | 1302 | vcaballero | for (int i = 0; i < numExtents; i++) { |
653 | 1830 | fernando | xml.addChild(((ProjectExtent) extents.get(i)).getXMLEntity()); |
654 | 1222 | fernando | } |
655 | 1830 | fernando | |
656 | 8137 | jcampos | // Guardando propiedades de las camaras
|
657 | int numCameras = this.cameras.size(); |
||
658 | xml.putProperty("numCameras", numCameras);
|
||
659 | |||
660 | for (int i = 0; i < numCameras; i++) { |
||
661 | 13913 | jaume | xml.addChild(((IPersistence) this.cameras.get(i)).getXMLEntity());
|
662 | 8137 | jcampos | } |
663 | |||
664 | // NUEVO: ESTO ESTA EN PRUEBAS. SIRVE PARA
|
||
665 | // BORRAR LAS REFERENCIAS A DATASOURCES QUE HEMOS
|
||
666 | // BORRADO. Hay que probar a borrarlos cuando se
|
||
667 | // borra una tabla y cuando se borra una capa.
|
||
668 | 23176 | vcaballero | // try {
|
669 | 20779 | vcaballero | // cleanBadReferences();
|
670 | 23176 | vcaballero | // }catch (Exception e) {
|
671 | // NotificationManager.addError("clean_bad_references",e);
|
||
672 | // }
|
||
673 | // SourceInfo[] infos = LayerFactory.getDataSourceFactory()
|
||
674 | // .getDriverInfos();
|
||
675 | // xml.putProperty("data-source-count", infos.length);
|
||
676 | //
|
||
677 | // for (int i = 0; i < infos.length; i++) {
|
||
678 | // SourceInfo di = infos[i];
|
||
679 | // XMLEntity child = this.getSourceInfoXMLEntity(di);
|
||
680 | // xml.addChild(child);
|
||
681 | // }
|
||
682 | 8137 | jcampos | int numDocuments = 0; |
683 | 7304 | caballero | for (int i = 0; i < documents.size(); i++) { |
684 | try {
|
||
685 | 24759 | jmvivo | XMLEntity xmlchild = (documents.get(i)) |
686 | 8137 | jcampos | .getXMLEntity(); |
687 | 23176 | vcaballero | xmlchild.putProperty("tagName","document"+i); |
688 | 7304 | caballero | xml.addChild(xmlchild); |
689 | numDocuments++; |
||
690 | } catch (SaveException e) {
|
||
691 | e.showError(); |
||
692 | } |
||
693 | } |
||
694 | xml.putProperty("numDocuments", numDocuments);
|
||
695 | 8137 | jcampos | /*
|
696 | * int numViews=0; for (int i = 0; i < views.size(); i++) { try {
|
||
697 | * XMLEntity xmlchild=((ProjectView) views.get(i)).getXMLEntity();
|
||
698 | * xml.addChild(xmlchild); numViews++; } catch (SaveException e) {
|
||
699 | * e.showError(); } } xml.putProperty("numViews", numViews);
|
||
700 | 9237 | caballero | *
|
701 | 8137 | jcampos | * int numMaps=0; for (int i = 0; i < maps.size(); i++) { try {
|
702 | * XMLEntity xmlchild=((ProjectMap) maps.get(i)).getXMLEntity();
|
||
703 | * xml.addChild(xmlchild); numMaps++; } catch (SaveException e) {
|
||
704 | * e.showError(); } } xml.putProperty("numMaps", numMaps);
|
||
705 | */
|
||
706 | 1222 | fernando | xml.putProperty("modificationDate", modificationDate);
|
707 | 10737 | jaume | xml.putProperty("name", name, false); |
708 | 1222 | fernando | xml.putProperty("owner", owner);
|
709 | 8137 | jcampos | xml.putProperty("selectionColor", StringUtilities
|
710 | .color2String(selectionColor)); |
||
711 | /*
|
||
712 | * int numTables=0; for (int i = 0; i < tables.size(); i++) { try {
|
||
713 | * XMLEntity xmlchild=((ProjectTable) tables.get(i)).getXMLEntity();
|
||
714 | * xml.addChild(xmlchild); numTables++; } catch (SaveException e) {
|
||
715 | 9237 | caballero | *
|
716 | 8137 | jcampos | * e.showError(); } } xml.putProperty("numTables", numTables);
|
717 | */
|
||
718 | 1222 | fernando | xml.putProperty("projection", defaultProjection.getAbrev());
|
719 | 6147 | jaume | |
720 | 7689 | cesar | saveWindowProperties(xml); |
721 | 1222 | fernando | return xml;
|
722 | } |
||
723 | 7766 | jaume | |
724 | 7689 | cesar | private void saveWindowProperties(XMLEntity xml) { |
725 | XMLEntity propertyList = new XMLEntity();
|
||
726 | 7766 | jaume | |
727 | 7689 | cesar | propertyList.setName("AndamiPersistence");
|
728 | 10621 | cesar | propertyList.putProperty("className", Project.class.getName(), false); |
729 | 7766 | jaume | |
730 | 7689 | cesar | boolean projectWindowSaved = false; |
731 | 7766 | jaume | |
732 | 8137 | jcampos | IWindow[] windowList = PluginServices.getMDIManager()
|
733 | .getOrderedWindows(); |
||
734 | 7689 | cesar | WindowInfo wi; |
735 | XMLEntity windowProperties; |
||
736 | 8137 | jcampos | for (int winIndex = windowList.length - 1; winIndex >= 0; winIndex--) { |
737 | wi = PluginServices.getMDIManager().getWindowInfo( |
||
738 | windowList[winIndex]); |
||
739 | if (wi != null && wi.checkPersistence()) { |
||
740 | if (windowList[winIndex] instanceof Layout) { // for the |
||
741 | // moment we
|
||
742 | // can't do this
|
||
743 | // for Maps
|
||
744 | // because they
|
||
745 | // don't have a
|
||
746 | // standard
|
||
747 | // model
|
||
748 | 7689 | cesar | Layout layoutWindow = (Layout) windowList[winIndex]; |
749 | windowProperties = wi.getXMLEntity(); |
||
750 | 8137 | jcampos | windowProperties.putProperty("documentType",
|
751 | 10621 | cesar | ProjectMapFactory.registerName, false);
|
752 | 8137 | jcampos | windowProperties.putProperty("documentName", layoutWindow
|
753 | 10621 | cesar | .getName(), false);
|
754 | windowProperties.putProperty("zPosition", winIndex, false); |
||
755 | 7689 | cesar | propertyList.addChild(windowProperties); |
756 | 8137 | jcampos | } else if (windowList[winIndex] instanceof ProjectWindow) { |
757 | 7689 | cesar | projectWindowSaved = true;
|
758 | 7766 | jaume | windowProperties = wi.getXMLEntity(); |
759 | 8137 | jcampos | windowProperties |
760 | .putProperty("className",
|
||
761 | 10621 | cesar | "com.iver.cit.gvsig.project.document.gui.ProjectWindow", false); |
762 | windowProperties.putProperty("zPosition", winIndex, false); |
||
763 | 7689 | cesar | propertyList.addChild(windowProperties); |
764 | 8137 | jcampos | } else if (windowList[winIndex] instanceof SingletonWindow) { // for |
765 | // table,
|
||
766 | // view
|
||
767 | // and
|
||
768 | // maybe
|
||
769 | // other
|
||
770 | // documents
|
||
771 | 7766 | jaume | SingletonWindow viewWindow = (SingletonWindow) windowList[winIndex]; |
772 | 7689 | cesar | if (viewWindow.getWindowModel() instanceof ProjectDocument) { |
773 | 8137 | jcampos | ProjectDocument doc = (ProjectDocument) viewWindow |
774 | .getWindowModel(); |
||
775 | 7689 | cesar | windowProperties = wi.getXMLEntity(); |
776 | 8137 | jcampos | windowProperties.putProperty("documentType", doc
|
777 | 10621 | cesar | .getProjectDocumentFactory().getRegisterName(), false);
|
778 | 8137 | jcampos | windowProperties.putProperty("documentName",
|
779 | ((ProjectDocument) viewWindow.getWindowModel()) |
||
780 | 10621 | cesar | .getName(), false);
|
781 | windowProperties.putProperty("zPosition", winIndex, false); |
||
782 | 9237 | caballero | |
783 | 9044 | cesar | // TODO this will be generalized to all ProjectDocuments as soon as possible
|
784 | 9199 | maquerol | // if (viewWindow instanceof BaseView) {
|
785 | // BaseView win = (BaseView) viewWindow;
|
||
786 | // windowProperties.addChild(win.getWindowData().getXMLEntity());
|
||
787 | // }
|
||
788 | if (viewWindow instanceof IDocumentWindow) { |
||
789 | IDocumentWindow win = (IDocumentWindow) viewWindow; |
||
790 | 9044 | cesar | windowProperties.addChild(win.getWindowData().getXMLEntity()); |
791 | } |
||
792 | 9237 | caballero | |
793 | 7689 | cesar | propertyList.addChild(windowProperties); |
794 | 7766 | jaume | } |
795 | 7689 | cesar | } |
796 | } |
||
797 | } |
||
798 | 7766 | jaume | |
799 | 7689 | cesar | if (projectWindowSaved == false) { |
800 | // If the Project Manager was closed, it was not in the
|
||
801 | // previous window list. Save it now
|
||
802 | 8137 | jcampos | ProjectExtension pe = (ProjectExtension) PluginServices |
803 | .getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
||
804 | 7766 | jaume | |
805 | 8137 | jcampos | if (pe != null) { |
806 | 7689 | cesar | IWindow projectWindow = pe.getProjectWindow(); |
807 | 8137 | jcampos | wi = PluginServices.getMDIManager() |
808 | .getWindowInfo(projectWindow); |
||
809 | if (wi != null && wi.checkPersistence()) { |
||
810 | 7689 | cesar | windowProperties = wi.getXMLEntity(); |
811 | 8137 | jcampos | if (windowProperties != null) { |
812 | windowProperties |
||
813 | .putProperty("className",
|
||
814 | 10621 | cesar | "com.iver.cit.gvsig.project.document.gui.ProjectWindow", false); |
815 | 7689 | cesar | propertyList.addChild(windowProperties); |
816 | } |
||
817 | } |
||
818 | } |
||
819 | } |
||
820 | 7766 | jaume | |
821 | 7689 | cesar | xml.addChild(propertyList); |
822 | } |
||
823 | 7766 | jaume | |
824 | 8137 | jcampos | /**
|
825 | * Store the initial window properties, to later restore the window sizes
|
||
826 | * and positions
|
||
827 | */
|
||
828 | 7689 | cesar | private void storeInitialWindowProperties(XMLEntity xml) { |
829 | XMLEntity child; |
||
830 | int childNumb;
|
||
831 | 7766 | jaume | |
832 | 7689 | cesar | // order the window properties before restoring them, so that we also
|
833 | // restore the zPosition
|
||
834 | TreeMap orderedProperties = new TreeMap(); |
||
835 | int maximum = 1; |
||
836 | 8137 | jcampos | for (childNumb = xml.getChildrenCount() - 1; childNumb >= 0; childNumb--) { |
837 | 7689 | cesar | child = xml.getChild(childNumb); |
838 | if (child.contains("zPosition")) { |
||
839 | 8137 | jcampos | orderedProperties.put(new Integer(-child |
840 | .getIntProperty("zPosition")), child); // reverse the |
||
841 | // order, so
|
||
842 | // that we add
|
||
843 | // the back
|
||
844 | // windows first
|
||
845 | } else {
|
||
846 | orderedProperties.put(new Integer(maximum++), child); // the |
||
847 | // windows
|
||
848 | // without
|
||
849 | // zPosition
|
||
850 | // will
|
||
851 | // be on
|
||
852 | // the
|
||
853 | // fore
|
||
854 | 7689 | cesar | } |
855 | } |
||
856 | 7766 | jaume | |
857 | this.initialWindowProperties = orderedProperties.values().iterator();
|
||
858 | 7689 | cesar | } |
859 | 7766 | jaume | |
860 | 8137 | jcampos | /**
|
861 | * Store the initial window properties, to later restore the window sizes
|
||
862 | * and positions
|
||
863 | */
|
||
864 | 7689 | cesar | private void storeInitialWindowProperties061(XMLEntity xml) { |
865 | XMLEntity child; |
||
866 | 7697 | cesar | int childNumb = 0; |
867 | 7689 | cesar | ArrayList windowList = new ArrayList(); |
868 | 7766 | jaume | |
869 | 8137 | jcampos | child = xml.getChild(xml.getChildrenCount() - 1);
|
870 | 7689 | cesar | if (child.contains("className") |
871 | 8137 | jcampos | && child.getStringProperty("className").equals(
|
872 | "com.iver.cit.gvsig.project.Project")
|
||
873 | 7689 | cesar | && child.contains("name")
|
874 | && child.getStringProperty("name").equals("ViewInfoProperties")) { |
||
875 | 8137 | jcampos | child.putProperty("className",
|
876 | "com.iver.cit.gvsig.project.document.gui.ProjectWindow");
|
||
877 | 7689 | cesar | windowList.add(child); |
878 | } |
||
879 | 7766 | jaume | |
880 | 7689 | cesar | // try to open the views
|
881 | 24759 | jmvivo | if (xml.contains("numExtents")) { |
882 | 7697 | cesar | childNumb += xml.getIntProperty("numExtents");
|
883 | 24759 | jmvivo | } |
884 | if (xml.contains("data-source-count")) { |
||
885 | 7697 | cesar | childNumb += xml.getIntProperty("data-source-count");
|
886 | 24759 | jmvivo | } |
887 | 8137 | jcampos | int limit = 0; |
888 | 24759 | jmvivo | if (xml.contains("numViews")) { |
889 | 8400 | cesar | limit = xml.getIntProperty("numViews")+childNumb;
|
890 | 24759 | jmvivo | } |
891 | 7766 | jaume | |
892 | 7689 | cesar | XMLEntity view; |
893 | for (int i = childNumb; i < limit; i++) { |
||
894 | view = xml.getChild(i); |
||
895 | 8137 | jcampos | child = view.getChild(view.getChildrenCount() - 1);
|
896 | if (child.contains("className") |
||
897 | && child.getStringProperty("className").equals(
|
||
898 | "com.iver.cit.gvsig.project.ProjectView")
|
||
899 | && child.contains("name")
|
||
900 | && child.getStringProperty("name").equals(
|
||
901 | "ViewInfoProperties")) {
|
||
902 | child.putProperty("documentName", view
|
||
903 | .getStringProperty("name"));
|
||
904 | child.putProperty("documentType",
|
||
905 | ProjectViewFactory.registerName); |
||
906 | 7689 | cesar | windowList.add(child); |
907 | } |
||
908 | } |
||
909 | 7766 | jaume | |
910 | 24759 | jmvivo | if (xml.contains("numViews")) { |
911 | 7697 | cesar | childNumb += xml.getIntProperty("numViews");
|
912 | 24759 | jmvivo | } |
913 | 7689 | cesar | |
914 | 24759 | jmvivo | if (xml.contains("numMaps")) { |
915 | 7766 | jaume | limit = childNumb + xml.getIntProperty("numMaps");
|
916 | 24759 | jmvivo | } |
917 | 7697 | cesar | |
918 | 7689 | cesar | // try to open the maps
|
919 | XMLEntity map; |
||
920 | for (int i = childNumb; i < limit; i++) { |
||
921 | map = xml.getChild(i); |
||
922 | 8137 | jcampos | for (int j = 0; j < map.getChildrenCount(); j++) { |
923 | 7689 | cesar | child = map.getChild(j); |
924 | 8137 | jcampos | if (child.contains("className") |
925 | && child.getStringProperty("className").equals(
|
||
926 | "com.iver.cit.gvsig.project.ProjectMap")
|
||
927 | && child.contains("name")
|
||
928 | && child.getStringProperty("name").equals(
|
||
929 | "ViewInfoProperties")) {
|
||
930 | child.putProperty("documentName", map
|
||
931 | .getStringProperty("name"));
|
||
932 | child.putProperty("documentType",
|
||
933 | ProjectMapFactory.registerName); |
||
934 | 7689 | cesar | windowList.add(child); |
935 | } |
||
936 | } |
||
937 | } |
||
938 | 7766 | jaume | |
939 | this.initialWindowProperties = windowList.iterator();
|
||
940 | 7689 | cesar | } |
941 | |||
942 | 2183 | fernando | /**
|
943 | 8137 | jcampos | * Restores the size, position and order of the windows, according to
|
944 | * variable initialWindowProperties. If this variable is null, the method
|
||
945 | * just opens the project manager window.
|
||
946 | 9237 | caballero | *
|
947 | 7689 | cesar | */
|
948 | public void restoreWindowProperties() { |
||
949 | boolean projectWindowRestored = false; |
||
950 | XMLEntity child; |
||
951 | 7766 | jaume | |
952 | 7689 | cesar | Iterator propertiesIterator = this.initialWindowProperties; |
953 | 8137 | jcampos | if (propertiesIterator != null) { |
954 | 7689 | cesar | this.initialWindowProperties = null; |
955 | 7766 | jaume | |
956 | 7689 | cesar | while (propertiesIterator.hasNext()) {
|
957 | child = (XMLEntity) propertiesIterator.next(); |
||
958 | 8137 | jcampos | if (child.contains("name") // restore the position of the |
959 | // document windows
|
||
960 | && child.getStringProperty("name").equals(
|
||
961 | "ViewInfoProperties")
|
||
962 | && child.contains("documentType")) {
|
||
963 | boolean isClosed = true; |
||
964 | 24759 | jmvivo | if (child.contains("isClosed")) { |
965 | 8137 | jcampos | isClosed = child.getBooleanProperty("isClosed");
|
966 | 24759 | jmvivo | } |
967 | 8137 | jcampos | if (isClosed == false) { |
968 | WindowInfo windowProps = WindowInfo |
||
969 | .createFromXMLEntity(child); |
||
970 | String documentName = child
|
||
971 | .getStringProperty("documentName");
|
||
972 | String documentType = child
|
||
973 | .getStringProperty("documentType");
|
||
974 | ProjectDocument pd = this.getProjectDocumentByName(
|
||
975 | documentName, documentType); |
||
976 | 24759 | jmvivo | if (pd==null) { |
977 | continue;
|
||
978 | } |
||
979 | 9044 | cesar | IWindow win = null;
|
980 | 9199 | maquerol | if (pd instanceof ProjectDocument |
981 | 9044 | cesar | && child.getChildrenCount()>0
|
982 | && child.getChild(0).getName().equals("windowData")) { |
||
983 | // this will be generalized to all ProjectDocuments as soon as possible
|
||
984 | WindowData windowData = new WindowData();
|
||
985 | windowData.setXMLEntity(child.getChild(0));
|
||
986 | 9199 | maquerol | pd.storeWindowData(windowData); |
987 | 24759 | jmvivo | win = (pd).createWindow(); |
988 | 9044 | cesar | } else {
|
989 | win = pd.createWindow(); |
||
990 | } |
||
991 | 14845 | jmvivo | if (win == null){ |
992 | continue;
|
||
993 | } |
||
994 | 8137 | jcampos | PluginServices.getMDIManager().addWindow(win); |
995 | PluginServices.getMDIManager().changeWindowInfo(win, |
||
996 | windowProps); |
||
997 | } |
||
998 | } else if (child.contains("className") // restore the position |
||
999 | // of the project
|
||
1000 | // manager window
|
||
1001 | && child |
||
1002 | .getStringProperty("className")
|
||
1003 | .equals( |
||
1004 | "com.iver.cit.gvsig.project.document.gui.ProjectWindow")
|
||
1005 | && child.contains("name")
|
||
1006 | && child.getStringProperty("name").equals(
|
||
1007 | "ViewInfoProperties")) {
|
||
1008 | WindowInfo wi = WindowInfo.createFromXMLEntity(child); |
||
1009 | 8374 | cesar | // don't restore size for ProjectManager window, as it's not resizable
|
1010 | wi.setHeight(-1);
|
||
1011 | wi.setWidth(-1);
|
||
1012 | 8137 | jcampos | ProjectExtension pe = (ProjectExtension) PluginServices |
1013 | .getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
||
1014 | if (pe != null) { |
||
1015 | pe.setProject(this);
|
||
1016 | pe.showProjectWindow(wi); |
||
1017 | } |
||
1018 | projectWindowRestored = true;
|
||
1019 | } |
||
1020 | 7689 | cesar | } |
1021 | } |
||
1022 | 7766 | jaume | |
1023 | 8137 | jcampos | if (!projectWindowRestored) { // if the project window was not stored |
1024 | // in the project, open it now
|
||
1025 | ProjectExtension pe = (ProjectExtension) PluginServices |
||
1026 | .getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
||
1027 | 7766 | jaume | |
1028 | 8137 | jcampos | if (pe != null) { |
1029 | 7689 | cesar | pe.setProject(this);
|
1030 | pe.showProjectWindow(); |
||
1031 | } |
||
1032 | } |
||
1033 | } |
||
1034 | 7766 | jaume | |
1035 | 7689 | cesar | /**
|
1036 | 2183 | fernando | * DOCUMENT ME!
|
1037 | 9237 | caballero | *
|
1038 | 8137 | jcampos | * @param xml
|
1039 | * DOCUMENT ME!
|
||
1040 | 9237 | caballero | *
|
1041 | 2183 | fernando | * @return DOCUMENT ME!
|
1042 | 9237 | caballero | *
|
1043 | 1222 | fernando | * @throws XMLException
|
1044 | * @throws DriverException
|
||
1045 | * @throws DriverIOException
|
||
1046 | 3940 | caballero | * @throws OpenException
|
1047 | * @throws VersionException
|
||
1048 | 1222 | fernando | */
|
1049 | 8137 | jcampos | public static Project createFromXML(XMLEntity xml) throws OpenException { |
1050 | 3940 | caballero | |
1051 | 1830 | fernando | int childNumber = 0; |
1052 | 1222 | fernando | Project p = new Project();
|
1053 | 10679 | jaume | |
1054 | 8137 | jcampos | try {
|
1055 | p.comments = xml.getStringProperty("comments");
|
||
1056 | p.creationDate = xml.getStringProperty("creationDate");
|
||
1057 | int numExtents = xml.getIntProperty("numExtents"); |
||
1058 | 1830 | fernando | |
1059 | 8137 | jcampos | for (int i = 0; i < numExtents; i++) { |
1060 | ProjectExtent pe = ProjectExtent.createFromXML(xml.getChild(i)); |
||
1061 | p.extents.add(pe); |
||
1062 | } |
||
1063 | 1222 | fernando | |
1064 | 8137 | jcampos | // Leemos el ultiom hijo recogido
|
1065 | childNumber = numExtents; |
||
1066 | 1830 | fernando | |
1067 | 8137 | jcampos | // Recogiendo el numero de cameras
|
1068 | 8145 | sbayarri | int numCameras = 0; |
1069 | 24759 | jmvivo | if (xml.contains("numCameras")) { |
1070 | 8145 | sbayarri | numCameras = xml.getIntProperty("numCameras");
|
1071 | 24759 | jmvivo | } |
1072 | 1830 | fernando | |
1073 | 8137 | jcampos | // Recogiendo todo las camaras
|
1074 | for (int i = childNumber; i < (childNumber + numCameras); i++) { |
||
1075 | XMLEntity xmlProp = xml.getChild(i); |
||
1076 | try {
|
||
1077 | String className = xmlProp.getStringProperty("className"); |
||
1078 | Class classProp = Class.forName(className); |
||
1079 | Object obj = classProp.newInstance();
|
||
1080 | 13913 | jaume | IPersistence objPersist = (IPersistence) obj; |
1081 | 8137 | jcampos | objPersist.setXMLEntity(xmlProp); |
1082 | p.cameras.add(obj); |
||
1083 | } catch (Exception e) { |
||
1084 | continue;
|
||
1085 | } |
||
1086 | } |
||
1087 | 1830 | fernando | |
1088 | 8137 | jcampos | childNumber += numCameras; |
1089 | 1830 | fernando | |
1090 | 23176 | vcaballero | // int numDataSources = xml.getIntProperty("data-source-count");
|
1091 | 8137 | jcampos | |
1092 | 23176 | vcaballero | // for (int i = childNumber; i < (childNumber + numDataSources); i++) {
|
1093 | // XMLEntity child = xml.getChild(i);
|
||
1094 | // registerDataSourceFromXML(child);
|
||
1095 | // }
|
||
1096 | 1222 | fernando | |
1097 | 23176 | vcaballero | // childNumber += numDataSources;
|
1098 | 8137 | jcampos | int numDocuments = 0; |
1099 | if (xml.contains("numDocuments")) { |
||
1100 | numDocuments = xml.getIntProperty("numDocuments");
|
||
1101 | } else {
|
||
1102 | int numViews = xml.getIntProperty("numViews"); |
||
1103 | int numMaps = xml.getIntProperty("numMaps"); |
||
1104 | int numTables = xml.getIntProperty("numTables"); |
||
1105 | numDocuments = numViews + numMaps + numTables; |
||
1106 | 7436 | caballero | } |
1107 | 15843 | vcaballero | int i=0; |
1108 | for (i = childNumber; i < (numDocuments + childNumber); i++) {
|
||
1109 | 8137 | jcampos | try {
|
1110 | ProjectDocument pD = ProjectDocument.createFromXML(xml |
||
1111 | .getChild(i), p); |
||
1112 | p.addDocument(pD); |
||
1113 | p.sortedDocuments.put(pD, new Integer(i)); |
||
1114 | } catch (OpenException e) {
|
||
1115 | 15843 | vcaballero | XMLEntity childXML=xml.getChild(i); |
1116 | e.showMessageError(childXML.getName()+"\n "+childXML.getStringProperty("className")); |
||
1117 | 8137 | jcampos | } |
1118 | } |
||
1119 | 24759 | jmvivo | ProjectDocument[] sortDocKeys = p.sortedDocuments
|
1120 | 8137 | jcampos | .keySet().toArray(new ProjectDocument[0]); |
1121 | 24759 | jmvivo | Integer[] sortDocValues = p.sortedDocuments.values() |
1122 | 8137 | jcampos | .toArray(new Integer[0]); |
1123 | 1222 | fernando | |
1124 | 15843 | vcaballero | i=0;
|
1125 | for ( i = 0; i < sortDocValues.length; i++) { |
||
1126 | 8137 | jcampos | try {
|
1127 | sortDocKeys[i].setXMLEntity(xml.getChild(sortDocValues[i] |
||
1128 | .intValue())); |
||
1129 | } catch (OpenException e) {
|
||
1130 | 17092 | vcaballero | XMLEntity childXML=xml.getChild(sortDocValues[i].intValue()); |
1131 | 15843 | vcaballero | e.showMessageError(childXML.getName()+"\n "+childXML.getStringProperty("className")); |
1132 | 8137 | jcampos | } |
1133 | } |
||
1134 | childNumber += numDocuments; |
||
1135 | 1830 | fernando | |
1136 | 8137 | jcampos | p.modificationDate = xml.getStringProperty("modificationDate");
|
1137 | 9532 | caballero | //p.modified = xml.getBooleanProperty("modified");
|
1138 | 8137 | jcampos | p.name = xml.getStringProperty("name");
|
1139 | p.owner = xml.getStringProperty("owner");
|
||
1140 | p.selectionColor = StringUtilities.string2Color(xml |
||
1141 | .getStringProperty("selectionColor"));
|
||
1142 | 7766 | jaume | |
1143 | 8137 | jcampos | p.setLinkTable(); |
1144 | String strProj = xml.getStringProperty("projection"); |
||
1145 | |||
1146 | if (strProj != null) { |
||
1147 | p.setProjection(CRSFactory.getCRS(strProj)); |
||
1148 | 7689 | cesar | } |
1149 | 8137 | jcampos | |
1150 | if (childNumber < xml.getChildrenCount()) { // restore the position |
||
1151 | // of the windows
|
||
1152 | XMLEntity child = xml.getChild(childNumber); |
||
1153 | if (child.contains("name") |
||
1154 | && child.getStringProperty("name").equals(
|
||
1155 | "AndamiPersistence")) {
|
||
1156 | p.storeInitialWindowProperties(child); |
||
1157 | } else if (child.contains("className") |
||
1158 | && child.getStringProperty("className").equals(
|
||
1159 | "com.iver.cit.gvsig.project.Project")
|
||
1160 | && child.contains("name")
|
||
1161 | && child.getStringProperty("name").equals(
|
||
1162 | "ViewInfoProperties")) {
|
||
1163 | p.storeInitialWindowProperties061(xml); |
||
1164 | } |
||
1165 | 7689 | cesar | } |
1166 | 7766 | jaume | |
1167 | 8137 | jcampos | PostProcessSupport.executeCalls(); |
1168 | } catch (Exception e) { |
||
1169 | throw new OpenException(e, p.getClass().getName()); |
||
1170 | 3171 | caballero | } |
1171 | 10679 | jaume | |
1172 | 3183 | caballero | return p;
|
1173 | 3940 | caballero | |
1174 | 1222 | fernando | } |
1175 | |||
1176 | /**
|
||
1177 | 12728 | jaume | * Reestablece los link que ten�a cada tabla con las dem�s.
|
1178 | 2183 | fernando | */
|
1179 | public void setLinkTable() { |
||
1180 | 24929 | vcaballero | ArrayList tables = getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
1181 | 22717 | vcaballero | |
1182 | for (int i = 0; i < tables.size(); i++) { |
||
1183 | for (int j = 0; j < tables.size(); j++) { |
||
1184 | /*
|
||
1185 | * System.out.println("name = " + ((ProjectTable)
|
||
1186 | * tables.get(j)).getModelo().getName());
|
||
1187 | * System.out.println("linktable = " + ((ProjectTable)
|
||
1188 | * tables.get(i)).getLinkTable());
|
||
1189 | */
|
||
1190 | 21118 | jmvivo | // try {
|
1191 | 24929 | vcaballero | if ((((FeatureTableDocument) tables.get(i)).getLinkTable() != null) |
1192 | && ((FeatureTableDocument) tables.get(i)).getLinkTable() |
||
1193 | 22717 | vcaballero | .equals( |
1194 | 24929 | vcaballero | ((FeatureTableDocument) tables.get(j)) |
1195 | .getStore() |
||
1196 | 22717 | vcaballero | .getName())) { |
1197 | LinkSelectionObserver lso; |
||
1198 | |||
1199 | 24929 | vcaballero | lso = new LinkSelectionObserver(((FeatureTableDocument) tables
|
1200 | .get(i)).getStore(), |
||
1201 | ((FeatureTableDocument) tables.get(j)).getStore(), |
||
1202 | ((FeatureTableDocument) tables |
||
1203 | 22717 | vcaballero | .get(i)).getField1(), |
1204 | 24929 | vcaballero | ((FeatureTableDocument) tables.get(i)).getField2()); |
1205 | 22717 | vcaballero | |
1206 | 24929 | vcaballero | (((FeatureTableDocument) tables.get(i)).getStore()).addObserver(lso); |
1207 | ((FeatureTableDocument) tables.get(i)).addLinkSelectionObserver(lso); |
||
1208 | 22717 | vcaballero | |
1209 | } |
||
1210 | // } catch (ReadException e) {
|
||
1211 | 21118 | jmvivo | // e.printStackTrace();
|
1212 | // }
|
||
1213 | 22717 | vcaballero | } |
1214 | } |
||
1215 | 2183 | fernando | } |
1216 | |||
1217 | /**
|
||
1218 | 12728 | jaume | * Obtiene la vista que contiene a la capa que se pasa como par�metro
|
1219 | 9237 | caballero | *
|
1220 | 8137 | jcampos | * @param layer
|
1221 | * Capa cuya vista se quiere obtener
|
||
1222 | 9237 | caballero | *
|
1223 | 1222 | fernando | * @return
|
1224 | 9237 | caballero | *
|
1225 | 8137 | jcampos | * @throws RuntimeException
|
1226 | 12728 | jaume | * Si la capa que se pasa como par�metro no se encuentra en
|
1227 | 8137 | jcampos | * ninguna vista
|
1228 | 1222 | fernando | */
|
1229 | public String getView(FLayer layer) { |
||
1230 | 8137 | jcampos | ArrayList views = getDocumentsByType(ProjectViewFactory.registerName);
|
1231 | 1222 | fernando | for (int v = 0; v < views.size(); v++) { |
1232 | ProjectView pView = (ProjectView) views.get(v); |
||
1233 | FLayers layers = pView.getMapContext().getLayers(); |
||
1234 | 24759 | jmvivo | if (isView(layers, layer)) {
|
1235 | 8137 | jcampos | return pView.getName();
|
1236 | 24759 | jmvivo | } |
1237 | 2611 | caballero | } |
1238 | 1222 | fernando | |
1239 | 9479 | fdiaz | throw new RuntimeException("The layer '"+layer.getName()+"' is not in a view"); |
1240 | 2611 | caballero | } |
1241 | 6888 | jaume | |
1242 | public boolean isView(FLayers layers, FLayer layer) { |
||
1243 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
1244 | 8137 | jcampos | if (layers.getLayer(i) instanceof FLayers) { |
1245 | 17131 | jmvivo | if (isView((FLayers) layers.getLayer(i), layer)){
|
1246 | return true; |
||
1247 | } |
||
1248 | 7304 | caballero | } |
1249 | if (layers.getLayer(i) == layer) {
|
||
1250 | 8137 | jcampos | return true; |
1251 | 1222 | fernando | } |
1252 | 6888 | jaume | } |
1253 | return false; |
||
1254 | 1222 | fernando | } |
1255 | 6888 | jaume | |
1256 | 1222 | fernando | /**
|
1257 | 8137 | jcampos | * Devuelve la vista cuyo nombre coincide (sensible a mayusculas) con el que
|
1258 | 12728 | jaume | * se pasa como par�metro. Devuelve null si no hay ninguna vista con ese
|
1259 | 8137 | jcampos | * nombre
|
1260 | 9237 | caballero | *
|
1261 | 8137 | jcampos | * @param viewName
|
1262 | * Nombre de la vista que se quiere obtener
|
||
1263 | 9237 | caballero | *
|
1264 | 1222 | fernando | * @return DOCUMENT ME!
|
1265 | */
|
||
1266 | 8137 | jcampos | /*
|
1267 | * public ProjectView getViewByName(String viewName) { ArrayList
|
||
1268 | * views=getDocuments(PluginServices.getText(this,"Vista")); Object o =
|
||
1269 | * getProjectDocumentByName(viewName, PluginServices.getText(this,"Vista"));
|
||
1270 | 9237 | caballero | *
|
1271 | 8137 | jcampos | * if (o == null) { return null; }
|
1272 | 9237 | caballero | *
|
1273 | 8137 | jcampos | * return (ProjectView) o; }
|
1274 | */
|
||
1275 | 1830 | fernando | /**
|
1276 | * DOCUMENT ME!
|
||
1277 | 9237 | caballero | *
|
1278 | 1830 | fernando | * @return DOCUMENT ME!
|
1279 | */
|
||
1280 | 7222 | jaume | public IProjection getProjection() {
|
1281 | 24759 | jmvivo | if (projection == null) { |
1282 | 7222 | jaume | projection = Project.defaultProjection; |
1283 | 24759 | jmvivo | } |
1284 | 7222 | jaume | return projection;
|
1285 | 1222 | fernando | } |
1286 | 1830 | fernando | |
1287 | /**
|
||
1288 | * DOCUMENT ME!
|
||
1289 | 9237 | caballero | *
|
1290 | 8137 | jcampos | * @param defaultProjection
|
1291 | * DOCUMENT ME!
|
||
1292 | 1830 | fernando | */
|
1293 | 7222 | jaume | public void setProjection(IProjection projection) { |
1294 | this.projection = projection;
|
||
1295 | } |
||
1296 | |||
1297 | /**
|
||
1298 | * Sets the projection used when no projection is defined
|
||
1299 | 9237 | caballero | *
|
1300 | 8137 | jcampos | * @param defaultProjection
|
1301 | * DOCUMENT ME!
|
||
1302 | 7222 | jaume | */
|
1303 | public static void setDefaultProjection(IProjection defaultProjection) { |
||
1304 | 1222 | fernando | Project.defaultProjection = defaultProjection; |
1305 | } |
||
1306 | 1830 | fernando | |
1307 | 7222 | jaume | public static IProjection getDefaultProjection() { |
1308 | 11334 | jmvivo | if (defaultProjection == null){ |
1309 | XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig")
|
||
1310 | .getPersistentXML(); |
||
1311 | 11503 | jaume | |
1312 | 11334 | jmvivo | // Default Projection
|
1313 | 11503 | jaume | String projCode = null; |
1314 | 11334 | jmvivo | if (xml.contains("DefaultProjection")) { |
1315 | projCode = xml.getStringProperty("DefaultProjection");
|
||
1316 | Project.setDefaultProjection(CRSFactory.getCRS(projCode)); |
||
1317 | } else {
|
||
1318 | Project.setDefaultProjection(defaultFactoryProjection); |
||
1319 | } |
||
1320 | 11503 | jaume | |
1321 | 11334 | jmvivo | } |
1322 | 7222 | jaume | return Project.defaultProjection;
|
1323 | } |
||
1324 | |||
1325 | 1830 | fernando | /**
|
1326 | 8137 | jcampos | * Obtiene un documento a partir de su nombre y el nombre de registro en el
|
1327 | 12728 | jaume | * pointExtension, este �ltimo se puede obtener del
|
1328 | 8137 | jcampos | * Project****Factory.registerName.
|
1329 | 9237 | caballero | *
|
1330 | 8137 | jcampos | * @param name
|
1331 | * Nombre del documento
|
||
1332 | * @param type
|
||
1333 | * nombre de registro en el extensionPoint
|
||
1334 | 9237 | caballero | *
|
1335 | 7529 | caballero | * @return Documento
|
1336 | 1830 | fernando | */
|
1337 | 7304 | caballero | public ProjectDocument getProjectDocumentByName(String name, String type) { |
1338 | 8137 | jcampos | ArrayList docs = getDocumentsByType(type);
|
1339 | 7304 | caballero | for (Iterator iter = docs.iterator(); iter.hasNext();) { |
1340 | ProjectDocument elem = (ProjectDocument) iter.next(); |
||
1341 | 1830 | fernando | |
1342 | if (elem.getName().equals(name)) {
|
||
1343 | return elem;
|
||
1344 | } |
||
1345 | } |
||
1346 | |||
1347 | return null; |
||
1348 | } |
||
1349 | |||
1350 | /**
|
||
1351 | * DOCUMENT ME!
|
||
1352 | 9237 | caballero | *
|
1353 | 1830 | fernando | * @param name
|
1354 | 9237 | caballero | *
|
1355 | 1830 | fernando | * @return
|
1356 | */
|
||
1357 | 8137 | jcampos | /*
|
1358 | * public ProjectTable getTableByName(String name) { ArrayList
|
||
1359 | * tables=getDocuments(PluginServices.getText(this,"Tabla")); Object o =
|
||
1360 | * getProjectElementByName(name, tables);
|
||
1361 | 9237 | caballero | *
|
1362 | 8137 | jcampos | * if (o == null) { return null; }
|
1363 | 9237 | caballero | *
|
1364 | 8137 | jcampos | * return (ProjectTable) o; }
|
1365 | */
|
||
1366 | 1830 | fernando | /**
|
1367 | * DOCUMENT ME!
|
||
1368 | 9237 | caballero | *
|
1369 | 1830 | fernando | * @param name
|
1370 | 9237 | caballero | *
|
1371 | 1830 | fernando | * @return
|
1372 | */
|
||
1373 | 8137 | jcampos | /*
|
1374 | * public ProjectMap getLayoutByName(String name) { Object o =
|
||
1375 | * getProjectElementByName(name, maps);
|
||
1376 | 9237 | caballero | *
|
1377 | 8137 | jcampos | * if (o == null) { return null; }
|
1378 | 9237 | caballero | *
|
1379 | 8137 | jcampos | * return (ProjectMap) o; }
|
1380 | */
|
||
1381 | 22477 | vcaballero | // public SelectableDataSource getDataSourceByLayer(FLayer layer)
|
1382 | // throws ReadException {
|
||
1383 | // ArrayList tables = getDocumentsByType(ProjectTableFactory.registerName);
|
||
1384 | // SelectableDataSource dataSource = null;
|
||
1385 | // for (int i = 0; i < tables.size(); i++) {
|
||
1386 | // ProjectTable pt = (ProjectTable) tables.get(i);
|
||
1387 | // if (pt.getOriginal() == ((FLyrVect) layer)
|
||
1388 | // .getRecordset()) {
|
||
1389 | // dataSource = pt.getModelo().getRecordset();
|
||
1390 | // break;
|
||
1391 | // } else if (pt.getModelo() == ((FLyrVect) layer)
|
||
1392 | // .getRecordset()) {
|
||
1393 | // dataSource = pt.getModelo().getRecordset();
|
||
1394 | // break;
|
||
1395 | // }
|
||
1396 | // }
|
||
1397 | //
|
||
1398 | // if (dataSource == null) {
|
||
1399 | // // No se ha creado la tabla asociada al tema
|
||
1400 | // dataSource = ((FLyrVect) layer).getRecordset();
|
||
1401 | // }
|
||
1402 | //
|
||
1403 | // return dataSource;
|
||
1404 | //
|
||
1405 | // }
|
||
1406 | 3940 | caballero | |
1407 | 8137 | jcampos | /**
|
1408 | * Recorremos las capas y las tablas del proyecto, y creamos una lista con
|
||
1409 | * todos los datasources de GDBMS que estamos usando. Luego recorremos los
|
||
1410 | 12728 | jaume | * que est�n registrados, y borramos aquellos que no est�n siendo usados, es
|
1411 | * decir, aquellos que no est�n en nuestra lista (un Hash con clave el
|
||
1412 | 8137 | jcampos | * nombre del GDBMS)
|
1413 | 9237 | caballero | *
|
1414 | 8137 | jcampos | */
|
1415 | 22477 | vcaballero | // private void cleanBadReferences() {
|
1416 | // ArrayList tables = getDocumentsByType(ProjectTableFactory.registerName);
|
||
1417 | // Hashtable usedDataSources = new Hashtable();
|
||
1418 | // // Primero las tablas
|
||
1419 | // int i, j;
|
||
1420 | // try {
|
||
1421 | // for (i = 0; i < tables.size(); i++) {
|
||
1422 | // ProjectTable t = (ProjectTable) tables.get(i);
|
||
1423 | // SelectableDataSource ds;
|
||
1424 | // if (t.getModelo() == null){
|
||
1425 | // /*
|
||
1426 | // * if a broken table was found
|
||
1427 | // * we don't clean any source
|
||
1428 | // */
|
||
1429 | // return;
|
||
1430 | // }
|
||
1431 | //
|
||
1432 | // ds = t.getModelo().getRecordset();
|
||
1433 | //
|
||
1434 | // if (t.getOriginal() != null)
|
||
1435 | // usedDataSources.put(t.getOriginal().getRecordset()
|
||
1436 | // .getName(), t.getOriginal());
|
||
1437 | // usedDataSources.put(ds.getName(), ds);
|
||
1438 | // }
|
||
1439 | // } catch (ReadException e) {
|
||
1440 | // e.printStackTrace();
|
||
1441 | // }
|
||
1442 | // // Ahora las vistas
|
||
1443 | // ProjectView pv;
|
||
1444 | // ArrayList views = getDocumentsByType(ProjectViewFactory.registerName);
|
||
1445 | // try {
|
||
1446 | // for (i = 0; i < views.size(); i++) {
|
||
1447 | // pv = (ProjectView) views.get(i);
|
||
1448 | // this.findLayersVectDataSorces(pv.getMapContext(), usedDataSources);
|
||
1449 | //
|
||
1450 | // MapContext aux = pv.getMapOverViewContext();
|
||
1451 | // if (aux != null) {
|
||
1452 | // if (!this.findLayersVectDataSorces(aux, usedDataSources)){
|
||
1453 | // /*
|
||
1454 | // * if a broken layer was found
|
||
1455 | // * we don't clean any source
|
||
1456 | // */
|
||
1457 | // return;
|
||
1458 | // }
|
||
1459 | //
|
||
1460 | // }
|
||
1461 | //
|
||
1462 | // } // for i
|
||
1463 | //
|
||
1464 | // } catch (ReadException e) {
|
||
1465 | // e.printStackTrace();
|
||
1466 | // }
|
||
1467 | //
|
||
1468 | // // Ahora los mapas
|
||
1469 | // ArrayList maps = getDocumentsByType(ProjectMapFactory.registerName);
|
||
1470 | // ProjectMap pm;
|
||
1471 | // LayoutContext lContext;
|
||
1472 | // IFFrame[] fframes;
|
||
1473 | // try {
|
||
1474 | // for (i = 0; i < maps.size(); i++) {
|
||
1475 | // pm = (ProjectMap) maps.get(i);
|
||
1476 | // fframes = pm.getModel().getLayoutContext().getFFrames();
|
||
1477 | // for (j=0;j < fframes.length; j++){
|
||
1478 | // if (!(fframes[j] instanceof FFrameView)){
|
||
1479 | // continue;
|
||
1480 | // }
|
||
1481 | // if (!this.findLayersVectDataSorces(((FFrameView)fframes[i]).getMapContext(), usedDataSources)){
|
||
1482 | // /*
|
||
1483 | // * if a broken layer was found
|
||
1484 | // * we don't clean any source
|
||
1485 | // */
|
||
1486 | // return;
|
||
1487 | //
|
||
1488 | // }
|
||
1489 | // } //for j
|
||
1490 | //
|
||
1491 | // } // for i
|
||
1492 | //
|
||
1493 | // } catch (ReadException e) {
|
||
1494 | // e.printStackTrace();
|
||
1495 | // }
|
||
1496 | //
|
||
1497 | //
|
||
1498 | // // Recorremos los dataSources y los borramos si no
|
||
1499 | // // los estamos usando.
|
||
1500 | // SourceInfo[] infos = LayerFactory.getDataSourceFactory()
|
||
1501 | // .getDriverInfos();
|
||
1502 | // try {
|
||
1503 | // for (i = 0; i < infos.length; i++) {
|
||
1504 | // if (!usedDataSources.containsKey(infos[i].name)) {
|
||
1505 | // DataSource ds;
|
||
1506 | // ds = LayerFactory.getDataSourceFactory()
|
||
1507 | // .createRandomDataSource(infos[i].name);
|
||
1508 | // ds.remove();
|
||
1509 | // }
|
||
1510 | // }
|
||
1511 | // } catch (ReadException e) {
|
||
1512 | // e.printStackTrace();
|
||
1513 | // } catch (WriteException e) {
|
||
1514 | // e.printStackTrace();
|
||
1515 | // }
|
||
1516 | // }
|
||
1517 | 3940 | caballero | |
1518 | 14845 | jmvivo | /**
|
1519 | * Find DataSorces of the layers in the mapContext and store them in dataSourcesMap
|
||
1520 | *
|
||
1521 | * @param mapContext
|
||
1522 | * @param dataSourcesMap
|
||
1523 | * @return false if find a no Available layer
|
||
1524 | * @throws ReadDriverException
|
||
1525 | */
|
||
1526 | 22477 | vcaballero | // private boolean findLayersVectDataSorces(MapContext mapContext,Map dataSourcesMap) throws ReadException{
|
1527 | // LayersIterator iter = new LayersIterator(mapContext.getLayers()){
|
||
1528 | //
|
||
1529 | // //@Override
|
||
1530 | // public boolean evaluate(FLayer layer) {
|
||
1531 | // if (!(layer instanceof FLyrVect))
|
||
1532 | // return false;
|
||
1533 | // return super.evaluate(layer);
|
||
1534 | // }
|
||
1535 | //
|
||
1536 | // };
|
||
1537 | // FLyrVect layer;
|
||
1538 | // while (iter.hasNext()){
|
||
1539 | // layer = (FLyrVect)iter.nextLayer();
|
||
1540 | // if (!layer.isAvailable()){
|
||
1541 | // return false;
|
||
1542 | // }
|
||
1543 | //
|
||
1544 | // dataSourcesMap.put(layer.getRecordset().getName(), layer.getRecordset());
|
||
1545 | // if (layer.isJoined()){
|
||
1546 | // dataSourcesMap.put(layer.getSource().getRecordset().getName(),layer.getSource().getRecordset());
|
||
1547 | // }
|
||
1548 | //
|
||
1549 | // }
|
||
1550 | // return true;
|
||
1551 | // }
|
||
1552 | 14704 | jmvivo | |
1553 | 8137 | jcampos | /**
|
1554 | 5029 | cesar | * DOCUMENT ME!
|
1555 | 9237 | caballero | *
|
1556 | 5029 | cesar | * @return DOCUMENT ME!
|
1557 | 8137 | jcampos | * @throws SaveException
|
1558 | 5029 | cesar | * @throws XMLException
|
1559 | 6147 | jaume | * @throws SaveException
|
1560 | 5029 | cesar | */
|
1561 | 8137 | jcampos | public XMLEntity getWindowInfoXMLEntity(IWindow window)
|
1562 | throws SaveException {
|
||
1563 | if (window != null |
||
1564 | && PluginServices.getMDIManager().getWindowInfo(window) != null) {
|
||
1565 | WindowInfo vi = PluginServices.getMDIManager() |
||
1566 | .getWindowInfo(window); |
||
1567 | 5029 | cesar | XMLEntity xml = new XMLEntity();
|
1568 | 8137 | jcampos | // xml.putProperty("nameClass", this.getClass().getName());
|
1569 | try {
|
||
1570 | 5029 | cesar | xml.setName("ViewInfoProperties");
|
1571 | xml.putProperty("className", this.getClass().getName()); |
||
1572 | xml.putProperty("X", vi.getX());
|
||
1573 | xml.putProperty("Y", vi.getY());
|
||
1574 | xml.putProperty("Width", vi.getWidth());
|
||
1575 | xml.putProperty("Height", vi.getHeight());
|
||
1576 | xml.putProperty("isVisible", vi.isVisible());
|
||
1577 | xml.putProperty("isResizable", vi.isResizable());
|
||
1578 | xml.putProperty("isMaximizable", vi.isMaximizable());
|
||
1579 | xml.putProperty("isModal", vi.isModal());
|
||
1580 | xml.putProperty("isModeless", vi.isModeless());
|
||
1581 | xml.putProperty("isClosed", vi.isClosed());
|
||
1582 | 8137 | jcampos | if (vi.isMaximized() == true) { |
1583 | 5029 | cesar | xml.putProperty("isMaximized", vi.isMaximized());
|
1584 | xml.putProperty("normalX", vi.getNormalX());
|
||
1585 | xml.putProperty("normalY", vi.getNormalY());
|
||
1586 | xml.putProperty("normalWidth", vi.getNormalWidth());
|
||
1587 | xml.putProperty("normalHeight", vi.getNormalHeight());
|
||
1588 | 10679 | jaume | } |
1589 | 8137 | jcampos | } catch (Exception e) { |
1590 | throw new SaveException(e, this.getClass().getName()); |
||
1591 | 5029 | cesar | } |
1592 | return xml;
|
||
1593 | } |
||
1594 | 7304 | caballero | return null; |
1595 | 5029 | cesar | } |
1596 | 6147 | jaume | |
1597 | 8137 | jcampos | public static WindowInfo createWindowInfoFromXMLEntity(XMLEntity xml) { |
1598 | 6880 | cesar | WindowInfo result = new WindowInfo();
|
1599 | 5029 | cesar | result.setX(xml.getIntProperty("X"));
|
1600 | result.setY(xml.getIntProperty("Y"));
|
||
1601 | result.setHeight(xml.getIntProperty("Height"));
|
||
1602 | result.setWidth(xml.getIntProperty("Width"));
|
||
1603 | result.setClosed(xml.getBooleanProperty("isClosed"));
|
||
1604 | if (xml.contains("isMaximized")) { |
||
1605 | boolean maximized = xml.getBooleanProperty("isMaximized"); |
||
1606 | result.setMaximized(maximized); |
||
1607 | 8137 | jcampos | if (maximized == true) { |
1608 | result.setNormalBounds(xml.getIntProperty("normalX"), xml
|
||
1609 | .getIntProperty("normalY"), xml
|
||
1610 | .getIntProperty("normalWidth"), xml
|
||
1611 | .getIntProperty("normalHeight"));
|
||
1612 | } else {
|
||
1613 | 5029 | cesar | result.setNormalBounds(result.getBounds()); |
1614 | } |
||
1615 | } |
||
1616 | |||
1617 | return result;
|
||
1618 | } |
||
1619 | 6147 | jaume | |
1620 | 23176 | vcaballero | // public XMLEntity getSourceInfoXMLEntity(SourceInfo di) {
|
1621 | // XMLEntity child = new XMLEntity();
|
||
1622 | //
|
||
1623 | // if (di instanceof ObjectSourceInfo) {
|
||
1624 | // ObjectSourceInfo driver = (ObjectSourceInfo) di;
|
||
1625 | // child.putProperty("type", "sameDriverFile");
|
||
1626 | // child.putProperty("gdbmsname", driver.name);
|
||
1627 | // } else if (di instanceof FileSourceInfo) {
|
||
1628 | // FileSourceInfo vfdi = (FileSourceInfo) di;
|
||
1629 | // child.putProperty("type", "otherDriverFile");
|
||
1630 | // child.putProperty("gdbmsname", vfdi.name);
|
||
1631 | // child.putProperty("file", vfdi.file);
|
||
1632 | // child.putProperty("driverName", vfdi.driverName);
|
||
1633 | // } else if (di instanceof DBSourceInfo) {
|
||
1634 | // DBTableSourceInfo dbdi = (DBTableSourceInfo) di;
|
||
1635 | // child.putProperty("type", "db");
|
||
1636 | // child.putProperty("gdbmsname", dbdi.name);
|
||
1637 | // child.putProperty("dbms", dbdi.dbms);
|
||
1638 | // child.putProperty("host", dbdi.host);
|
||
1639 | // child.putProperty("port", dbdi.port);
|
||
1640 | // child.putProperty("user", dbdi.user);
|
||
1641 | // child.putProperty("password", dbdi.password);
|
||
1642 | // child.putProperty("dbName", dbdi.dbName);
|
||
1643 | // child.putProperty("tableName", dbdi.tableName);
|
||
1644 | // child.putProperty("driverInfo", dbdi.driverName);
|
||
1645 | // }
|
||
1646 | //
|
||
1647 | // return child;
|
||
1648 | // }
|
||
1649 | //
|
||
1650 | 7529 | caballero | /**
|
1651 | 8137 | jcampos | * Devuelve un arrayList con todos los documentos del tipo especificado como
|
1652 | 12728 | jaume | * par�metro.
|
1653 | 9237 | caballero | *
|
1654 | 8137 | jcampos | * @param registerName
|
1655 | * nombre de registro en el extensionPoint
|
||
1656 | 9237 | caballero | *
|
1657 | 7529 | caballero | * @return Documentos del tipo especificado
|
1658 | */
|
||
1659 | 17743 | vcaballero | public ArrayList<ProjectDocument> getDocumentsByType(String registerName) { |
1660 | ArrayList<ProjectDocument> docuArray = new ArrayList<ProjectDocument>(); |
||
1661 | 8137 | jcampos | for (int i = 0; i < documents.size(); i++) { |
1662 | 24759 | jmvivo | ProjectDocument projectDocument = documents |
1663 | 8137 | jcampos | .get(i); |
1664 | ProjectDocumentFactory pdf = projectDocument |
||
1665 | .getProjectDocumentFactory(); |
||
1666 | 24759 | jmvivo | if (pdf == null) { |
1667 | 7343 | caballero | continue;
|
1668 | 24759 | jmvivo | } |
1669 | 7343 | caballero | if (pdf.getRegisterName().equals(registerName)) {
|
1670 | 7304 | caballero | docuArray.add(projectDocument); |
1671 | } |
||
1672 | } |
||
1673 | return docuArray;
|
||
1674 | } |
||
1675 | 8137 | jcampos | |
1676 | 7543 | caballero | /**
|
1677 | * Devuelve un arrayList con todos los documentos.
|
||
1678 | 9237 | caballero | *
|
1679 | 7543 | caballero | * @return Documentos
|
1680 | */
|
||
1681 | 17092 | vcaballero | public ArrayList<ProjectDocument> getDocuments() { |
1682 | ArrayList<ProjectDocument> docuArray = new ArrayList<ProjectDocument>(); |
||
1683 | 8137 | jcampos | for (int i = 0; i < documents.size(); i++) { |
1684 | 24759 | jmvivo | ProjectDocument projectDocument = documents |
1685 | 8137 | jcampos | .get(i); |
1686 | 7318 | caballero | docuArray.add(projectDocument); |
1687 | } |
||
1688 | return docuArray;
|
||
1689 | } |
||
1690 | 8137 | jcampos | |
1691 | 7543 | caballero | /**
|
1692 | * Inserta un documento.
|
||
1693 | 9237 | caballero | *
|
1694 | 8137 | jcampos | * @param doc
|
1695 | * Documento
|
||
1696 | 7543 | caballero | */
|
1697 | 7304 | caballero | public void addDocument(ProjectDocument doc) { |
1698 | documents.add(doc); |
||
1699 | doc.addPropertyChangeListener(this);
|
||
1700 | 9532 | caballero | //modified = true;
|
1701 | 7753 | jmvivo | change.firePropertyChange("", "", null); |
1702 | 7304 | caballero | doc.setProject(this, 0); |
1703 | 7343 | caballero | doc.afterAdd(); |
1704 | 7222 | jaume | |
1705 | 7304 | caballero | } |
1706 | 8137 | jcampos | |
1707 | 7543 | caballero | /**
|
1708 | * Borra un documento.
|
||
1709 | 9237 | caballero | *
|
1710 | 8137 | jcampos | * @param doc
|
1711 | * Documento
|
||
1712 | 7543 | caballero | */
|
1713 | 7304 | caballero | public void delDocument(ProjectDocument doc) { |
1714 | documents.remove(doc); |
||
1715 | 9532 | caballero | //modified = true;
|
1716 | 7304 | caballero | change.firePropertyChange("", null, null); |
1717 | 7343 | caballero | doc.afterRemove(); |
1718 | 7304 | caballero | } |
1719 | |||
1720 | 7654 | jaume | /**
|
1721 | * Sets the default selection color that will be used in subsequent
|
||
1722 | * projects.
|
||
1723 | 9237 | caballero | *
|
1724 | 7654 | jaume | * @param color
|
1725 | */
|
||
1726 | public static void setDefaultSelectionColor(Color color) { |
||
1727 | defaultSelectionColor = color; |
||
1728 | } |
||
1729 | |||
1730 | /**
|
||
1731 | 8137 | jcampos | * Returns the current default selection color defined which is the color
|
1732 | * defined when the user does not define any other one
|
||
1733 | 9237 | caballero | *
|
1734 | 7654 | jaume | * @return java.awt.Color
|
1735 | */
|
||
1736 | 7766 | jaume | public static Color getDefaultSelectionColor() { |
1737 | 7658 | jaume | // TODO es millorable?
|
1738 | 8137 | jcampos | XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig")
|
1739 | .getPersistentXML(); |
||
1740 | 24759 | jmvivo | if (xml.contains("DefaultSelectionColor")) { |
1741 | 8137 | jcampos | defaultSelectionColor = StringUtilities.string2Color(xml |
1742 | .getStringProperty("DefaultSelectionColor"));
|
||
1743 | 24759 | jmvivo | } |
1744 | 7654 | jaume | return defaultSelectionColor;
|
1745 | } |
||
1746 | |||
1747 | 7797 | jaume | /**
|
1748 | 8137 | jcampos | * Returns the user's default map units. This is the cartography data
|
1749 | * distance units.
|
||
1750 | 9237 | caballero | *
|
1751 | 7797 | jaume | * @return int (index of the <b>Attributes.NAMES array</b>)
|
1752 | */
|
||
1753 | 7787 | jaume | public static int getDefaultMapUnits() { |
1754 | if (defaultMapUnits == -1) { |
||
1755 | 8137 | jcampos | XMLEntity xml = PluginServices.getPluginServices( |
1756 | "com.iver.cit.gvsig").getPersistentXML();
|
||
1757 | 7794 | jaume | if (xml.contains("DefaultMapUnits")) { |
1758 | defaultMapUnits = xml.getIntProperty("DefaultMapUnits");
|
||
1759 | } else {
|
||
1760 | // first app run case
|
||
1761 | 20334 | vcaballero | String[] unitNames = MapContext.getDistanceNames(); |
1762 | 7794 | jaume | for (int i = 0; i < unitNames.length; i++) { |
1763 | // meter is the factory default's map unit
|
||
1764 | 20345 | vcaballero | if (unitNames[i].equals("Metros")) { |
1765 | 7794 | jaume | defaultMapUnits = i; |
1766 | break;
|
||
1767 | } |
||
1768 | 7787 | jaume | } |
1769 | } |
||
1770 | 24759 | jmvivo | if (defaultMapUnits == -1) { |
1771 | 20345 | vcaballero | defaultMapUnits = MapContext.getDistancePosition("Metros");
|
1772 | 24759 | jmvivo | } |
1773 | 7787 | jaume | } |
1774 | return defaultMapUnits;
|
||
1775 | } |
||
1776 | |||
1777 | 7797 | jaume | /**
|
1778 | 8137 | jcampos | * Returns the user's default view units for measuring distances. This is
|
1779 | * the units that the user will see in the status bar of the view.
|
||
1780 | 9237 | caballero | *
|
1781 | 7797 | jaume | * @return int (index of the <b>Attributes.NAMES array</b>)
|
1782 | */
|
||
1783 | 7787 | jaume | public static int getDefaultDistanceUnits() { |
1784 | if (defaultDistanceUnits == -1) { |
||
1785 | 8137 | jcampos | XMLEntity xml = PluginServices.getPluginServices( |
1786 | "com.iver.cit.gvsig").getPersistentXML();
|
||
1787 | 7794 | jaume | if (xml.contains("DefaultDistanceUnits")) { |
1788 | 8137 | jcampos | defaultDistanceUnits = xml |
1789 | .getIntProperty("DefaultDistanceUnits");
|
||
1790 | 7794 | jaume | } else {
|
1791 | // first app run case
|
||
1792 | 20334 | vcaballero | String[] unitNames = MapContext.getDistanceNames(); |
1793 | 7794 | jaume | for (int i = 0; i < unitNames.length; i++) { |
1794 | // meter is the factory default's distance unit
|
||
1795 | 20345 | vcaballero | if (unitNames[i].equals("Metros")) { |
1796 | 7794 | jaume | defaultDistanceUnits = i; |
1797 | break;
|
||
1798 | } |
||
1799 | 7787 | jaume | } |
1800 | } |
||
1801 | 24759 | jmvivo | if (defaultDistanceUnits == -1) { |
1802 | 20345 | vcaballero | defaultDistanceUnits = MapContext.getDistancePosition("Metros");
|
1803 | 24759 | jmvivo | } |
1804 | 7787 | jaume | } |
1805 | return defaultDistanceUnits;
|
||
1806 | } |
||
1807 | 7798 | jaume | /**
|
1808 | 20334 | vcaballero | * Returns the user's default view units for measuring areas. This is
|
1809 | * the units that the user will see in the status bar of the view.
|
||
1810 | *
|
||
1811 | * @return int (index of the <b>Attributes.NAMES array</b>)
|
||
1812 | */
|
||
1813 | public static int getDefaultDistanceArea() { |
||
1814 | if (defaultDistanceArea == -1) { |
||
1815 | XMLEntity xml = PluginServices.getPluginServices( |
||
1816 | "com.iver.cit.gvsig").getPersistentXML();
|
||
1817 | if (xml.contains("DefaultDistanceArea")) { |
||
1818 | defaultDistanceArea = xml |
||
1819 | .getIntProperty("DefaultDistanceArea");
|
||
1820 | } else {
|
||
1821 | // first app run case
|
||
1822 | String[] unitNames = MapContext.getAreaNames(); |
||
1823 | for (int i = 0; i < unitNames.length; i++) { |
||
1824 | // meter is the factory default's distance unit
|
||
1825 | 20345 | vcaballero | if (unitNames[i].equals("Metros")) { |
1826 | 20334 | vcaballero | defaultDistanceArea = i; |
1827 | break;
|
||
1828 | } |
||
1829 | } |
||
1830 | } |
||
1831 | if (defaultDistanceArea == -1){ |
||
1832 | defaultDistanceArea=getDefaultDistanceUnits(); |
||
1833 | } |
||
1834 | } |
||
1835 | return defaultDistanceArea;
|
||
1836 | } |
||
1837 | /**
|
||
1838 | 7798 | jaume | * Sets the default map unit (the units used by the data).
|
1839 | 9237 | caballero | *
|
1840 | 7798 | jaume | * @param mapUnits
|
1841 | */
|
||
1842 | 7787 | jaume | public static void setDefaultMapUnits(int mapUnits) { |
1843 | defaultMapUnits = mapUnits; |
||
1844 | } |
||
1845 | |||
1846 | 7798 | jaume | /**
|
1847 | * Sets the default distance units (the units shown in the status bar)
|
||
1848 | 9237 | caballero | *
|
1849 | 7798 | jaume | * @param distanceUnits
|
1850 | */
|
||
1851 | 7787 | jaume | public static void setDefaultDistanceUnits(int distanceUnits) { |
1852 | defaultDistanceUnits = distanceUnits; |
||
1853 | } |
||
1854 | 20334 | vcaballero | /**
|
1855 | * Sets the default distance area (the units shown in the status bar)
|
||
1856 | *
|
||
1857 | * @param distanceUnits
|
||
1858 | */
|
||
1859 | public static void setDefaultDistanceArea(int distanceArea) { |
||
1860 | defaultDistanceArea = distanceArea; |
||
1861 | } |
||
1862 | 7753 | jmvivo | public String exportToXML() throws SaveException { |
1863 | XMLEntity xml = this.newExportXMLRootNode();
|
||
1864 | 7766 | jaume | |
1865 | 7753 | jmvivo | Iterator iter = this.documents.iterator(); |
1866 | ProjectDocument document; |
||
1867 | // FIXME: Falta atrapar los errores
|
||
1868 | while (iter.hasNext()) {
|
||
1869 | 8137 | jcampos | document = (ProjectDocument) iter.next(); |
1870 | document.exportToXML(xml, this);
|
||
1871 | 7753 | jmvivo | } |
1872 | 7766 | jaume | |
1873 | 7753 | jmvivo | return xml.toString();
|
1874 | } |
||
1875 | 7766 | jaume | |
1876 | 7753 | jmvivo | public String exportToXML(ProjectDocument[] documents) throws SaveException { |
1877 | XMLEntity xml = this.newExportXMLRootNode();
|
||
1878 | 7766 | jaume | |
1879 | 8137 | jcampos | for (int i = 0; i < documents.length; i++) { |
1880 | documents[i].exportToXML(xml, this);
|
||
1881 | 7753 | jmvivo | } |
1882 | 7766 | jaume | |
1883 | 7753 | jmvivo | return xml.toString();
|
1884 | } |
||
1885 | |||
1886 | public void importFromXML(String xml) throws Exception { |
||
1887 | throw new Exception("Not Implemented"); |
||
1888 | /*
|
||
1889 | 8137 | jcampos | * // FIXME: ?? Exceptions XMLEntity xmlEntity = new XMLEntity();
|
1890 | 9237 | caballero | *
|
1891 | 8137 | jcampos | * try { xmlEntity.parse(xml); } catch (Exception e) { throw new
|
1892 | * Exception(e); }
|
||
1893 | 9237 | caballero | *
|
1894 | 8137 | jcampos | * if (!checkExportXMLRootNode(xmlEntity)) { throw new Exception("Check
|
1895 | * Error"); //FIXME: traducir }
|
||
1896 | 9237 | caballero | *
|
1897 | 8137 | jcampos | * int i;
|
1898 | 9237 | caballero | *
|
1899 | 8137 | jcampos | * XMLEntity xmlDocumentRoot; ProjectDocument document = null;
|
1900 | * ProjectDocumentFactory documentFactory = null; for (i=0;i<xmlEntity.getChildrenCount();i++) {
|
||
1901 | * xmlDocumentRoot = xmlEntity.getChild(i); if
|
||
1902 | * (!xmlDocumentRoot.contains("type")) { throw new Exception("Document
|
||
1903 | * root "+i+ "error"); } documentFactory =
|
||
1904 | * Project.getProjectDocumentFactory(xmlDocumentRoot.getStringProperty("type"));
|
||
1905 | * int j; }
|
||
1906 | */
|
||
1907 | 7766 | jaume | |
1908 | 7753 | jmvivo | } |
1909 | 7766 | jaume | |
1910 | 8137 | jcampos | public void importFromXML(String xml, String type) throws Exception { |
1911 | // FIXME: EXCEPTIONS!!!!
|
||
1912 | 7753 | jmvivo | XMLEntity xmlEntity = XMLEntity.parse(xml); |
1913 | 7766 | jaume | |
1914 | 7753 | jmvivo | if (!checkExportXMLRootNode(xmlEntity)) {
|
1915 | 7766 | jaume | throw new Exception(); |
1916 | 7753 | jmvivo | } |
1917 | |||
1918 | 8137 | jcampos | XMLEntity typeRoot = xmlEntity.firstChild("type", type);
|
1919 | 7753 | jmvivo | if (typeRoot.getChildrenCount() == 0) { |
1920 | return;
|
||
1921 | } |
||
1922 | 7766 | jaume | |
1923 | 7753 | jmvivo | ProjectDocumentFactory documentFactory = getProjectDocumentFactory(type); |
1924 | 7766 | jaume | |
1925 | 7753 | jmvivo | Hashtable conflicts = getConflicts(xmlEntity);
|
1926 | 7766 | jaume | |
1927 | 7753 | jmvivo | if (conflicts.size() != 0) { |
1928 | 8137 | jcampos | if (!documentFactory.resolveImportXMLConflicts(xmlEntity, this, |
1929 | conflicts)) { |
||
1930 | 7753 | jmvivo | return;
|
1931 | } |
||
1932 | } |
||
1933 | 23176 | vcaballero | // this.registerDataSources(this.getExportXMLTypeRootNode(xmlEntity,
|
1934 | // "dataSources"));
|
||
1935 | 7766 | jaume | |
1936 | 7753 | jmvivo | int i;
|
1937 | 7766 | jaume | ProjectDocument document; |
1938 | 8137 | jcampos | for (i = 0; i < typeRoot.getChildrenCount(); i++) { |
1939 | 7766 | jaume | document = documentFactory.create(this);
|
1940 | 8137 | jcampos | document.importFromXML(xmlEntity, typeRoot, i, this);
|
1941 | 7753 | jmvivo | } |
1942 | |||
1943 | } |
||
1944 | 7766 | jaume | |
1945 | 7753 | jmvivo | private Hashtable getConflicts(XMLEntity xml) { |
1946 | int iType;
|
||
1947 | Hashtable conflicts = new Hashtable(); |
||
1948 | ArrayList elements;
|
||
1949 | XMLEntity typeRoot; |
||
1950 | 8137 | jcampos | for (iType = 0; iType < xml.getChildrenCount(); iType++) { |
1951 | 7753 | jmvivo | typeRoot = xml.getChild(iType); |
1952 | elements = getDocumentsByType(typeRoot.getStringProperty("type"));
|
||
1953 | 7766 | jaume | Hashtable conflictsType = new Hashtable(); |
1954 | 8137 | jcampos | for (int iXML = 0; iXML < typeRoot.getChildrenCount(); iXML++) { |
1955 | 7753 | jmvivo | XMLEntity child = typeRoot.getChild(iXML); |
1956 | Iterator iter = elements.iterator();
|
||
1957 | while (iter.hasNext()) {
|
||
1958 | 8137 | jcampos | ProjectDocument element = (ProjectDocument) iter.next(); |
1959 | if (element.getName().equalsIgnoreCase(
|
||
1960 | child.getStringProperty("name"))) {
|
||
1961 | conflictsType.put(new Integer(iXML), child); |
||
1962 | 7753 | jmvivo | break;
|
1963 | } |
||
1964 | 7766 | jaume | |
1965 | 7753 | jmvivo | } |
1966 | } |
||
1967 | if (conflictsType.size() > 0) { |
||
1968 | 8137 | jcampos | conflicts |
1969 | .put(typeRoot.getStringProperty("type"), conflictsType);
|
||
1970 | 7753 | jmvivo | } |
1971 | } |
||
1972 | return conflicts;
|
||
1973 | } |
||
1974 | |||
1975 | public boolean isValidXMLForImport(String xml) { |
||
1976 | XMLEntity xmlEntity; |
||
1977 | try {
|
||
1978 | xmlEntity = XMLEntity.parse(xml); |
||
1979 | } catch (Exception e) { |
||
1980 | return false; |
||
1981 | } |
||
1982 | 7766 | jaume | |
1983 | 7753 | jmvivo | return checkExportXMLRootNode(xmlEntity);
|
1984 | } |
||
1985 | |||
1986 | 8137 | jcampos | public boolean isValidXMLForImport(String xml, String type) { |
1987 | 7753 | jmvivo | XMLEntity xmlEntity; |
1988 | try {
|
||
1989 | 8137 | jcampos | xmlEntity = XMLEntity.parse(xml); |
1990 | 7753 | jmvivo | } catch (Exception e) { |
1991 | return false; |
||
1992 | } |
||
1993 | 7766 | jaume | |
1994 | 7753 | jmvivo | if (!checkExportXMLRootNode(xmlEntity)) {
|
1995 | 7766 | jaume | return false; |
1996 | 7753 | jmvivo | } |
1997 | |||
1998 | 8137 | jcampos | XMLEntity typeRoot = xmlEntity.firstChild("type", type);
|
1999 | 7766 | jaume | |
2000 | 7753 | jmvivo | if (typeRoot == null) { |
2001 | return false; |
||
2002 | } |
||
2003 | 7766 | jaume | |
2004 | 7753 | jmvivo | return (typeRoot.getChildrenCount() > 0); |
2005 | } |
||
2006 | 7766 | jaume | |
2007 | 7753 | jmvivo | private boolean checkExportXMLRootNode(XMLEntity xml) { |
2008 | 24759 | jmvivo | if (!xml.contains("applicationName")) { |
2009 | 8137 | jcampos | return false; |
2010 | 24759 | jmvivo | } |
2011 | if (!xml.getStringProperty("applicationName").equalsIgnoreCase("gvSIG")) { |
||
2012 | 8137 | jcampos | return false; |
2013 | 24759 | jmvivo | } |
2014 | 7753 | jmvivo | |
2015 | 24759 | jmvivo | if (!xml.contains("version")) { |
2016 | 8137 | jcampos | return false; |
2017 | 24759 | jmvivo | } |
2018 | 8137 | jcampos | if (!xml.getStringProperty("version") |
2019 | 24759 | jmvivo | .equalsIgnoreCase(Version.format())) { |
2020 | 8137 | jcampos | return false; |
2021 | 24759 | jmvivo | } |
2022 | 7753 | jmvivo | |
2023 | return true; |
||
2024 | } |
||
2025 | |||
2026 | 23176 | vcaballero | // public void exportToXMLDataSource(XMLEntity root, String dataSourceName) {
|
2027 | // XMLEntity dsRoot = this.getExportXMLTypeRootNode(root, "dataSources");
|
||
2028 | // SourceInfo sourceInfo = LayerFactory.getDataSourceFactory()
|
||
2029 | // .getDriverInfo(dataSourceName);
|
||
2030 | // dsRoot.addChild(this.getSourceInfoXMLEntity(sourceInfo));
|
||
2031 | // }
|
||
2032 | 7766 | jaume | |
2033 | 7753 | jmvivo | private XMLEntity newExportXMLRootNode() {
|
2034 | XMLEntity xml = new XMLEntity();
|
||
2035 | 8137 | jcampos | xml.putProperty("applicationName", "gvSIG"); |
2036 | xml.putProperty("version", Version.format());
|
||
2037 | 7753 | jmvivo | return xml;
|
2038 | } |
||
2039 | 7766 | jaume | |
2040 | 8137 | jcampos | public XMLEntity getExportXMLTypeRootNode(XMLEntity root, String type) { |
2041 | XMLEntity typeRoot = root.firstChild("type", type);
|
||
2042 | 7753 | jmvivo | if (typeRoot == null) { |
2043 | typeRoot = this.newExportXMLTypeNode(type);
|
||
2044 | root.addChild(typeRoot); |
||
2045 | } |
||
2046 | return typeRoot;
|
||
2047 | } |
||
2048 | 7766 | jaume | |
2049 | 7753 | jmvivo | private XMLEntity newExportXMLTypeNode(String type) { |
2050 | XMLEntity xmlDataSources = new XMLEntity();
|
||
2051 | 8137 | jcampos | xmlDataSources.putProperty("type", type);
|
2052 | 7753 | jmvivo | return xmlDataSources;
|
2053 | } |
||
2054 | |||
2055 | 23176 | vcaballero | // private static boolean registerDataSourceFromXML(XMLEntity xmlDataSource) {
|
2056 | // String name = xmlDataSource.getStringProperty("gdbmsname");
|
||
2057 | //
|
||
2058 | // if (LayerFactory.getDataSourceFactory().getDriverInfo(name) == null) {
|
||
2059 | // if (xmlDataSource.getStringProperty("type").equals(
|
||
2060 | // "otherDriverFile")) {
|
||
2061 | // LayerFactory.getDataSourceFactory().addFileDataSource(
|
||
2062 | // xmlDataSource.getStringProperty("driverName"), name,
|
||
2063 | // xmlDataSource.getStringProperty("file"));
|
||
2064 | //
|
||
2065 | // } else if (xmlDataSource.getStringProperty("type").equals(
|
||
2066 | // "sameDriverFile")) {
|
||
2067 | //
|
||
2068 | // } else if (xmlDataSource.getStringProperty("type").equals("db")) {
|
||
2069 | // LayerFactory.getDataSourceFactory().addDBDataSourceByTable(
|
||
2070 | // name, xmlDataSource.getStringProperty("host"),
|
||
2071 | // xmlDataSource.getIntProperty("port"),
|
||
2072 | // xmlDataSource.getStringProperty("user"),
|
||
2073 | // xmlDataSource.getStringProperty("password"),
|
||
2074 | // xmlDataSource.getStringProperty("dbName"),
|
||
2075 | // xmlDataSource.getStringProperty("tableName"),
|
||
2076 | // xmlDataSource.getStringProperty("driverInfo"));
|
||
2077 | // } else {
|
||
2078 | // return false;
|
||
2079 | // }
|
||
2080 | //
|
||
2081 | // }
|
||
2082 | // return true;
|
||
2083 | // }
|
||
2084 | 7753 | jmvivo | |
2085 | 23176 | vcaballero | // private boolean registerDataSources(XMLEntity xmlDataSources) {
|
2086 | // try {
|
||
2087 | // int numDataSources = xmlDataSources.getChildrenCount();
|
||
2088 | //
|
||
2089 | // if (numDataSources == 0)
|
||
2090 | // return true;
|
||
2091 | // DataSourceFactory dsFactory = LayerFactory.getDataSourceFactory();
|
||
2092 | //
|
||
2093 | // for (int i = 0; i < numDataSources; i++) {
|
||
2094 | // XMLEntity child = xmlDataSources.getChild(i);
|
||
2095 | // if (!this.registerDataSourceFromXML(child)) {
|
||
2096 | // return false;
|
||
2097 | // }
|
||
2098 | // }
|
||
2099 | //
|
||
2100 | // return true;
|
||
2101 | // } catch (Exception e) {
|
||
2102 | // e.printStackTrace();
|
||
2103 | // return false;
|
||
2104 | // }
|
||
2105 | // }
|
||
2106 | 7753 | jmvivo | |
2107 | public static ProjectDocumentFactory getProjectDocumentFactory(String type) { |
||
2108 | ProjectDocumentFactory pde = null;
|
||
2109 | 8137 | jcampos | try {
|
2110 | 24956 | jmvivo | ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
2111 | 7753 | jmvivo | try {
|
2112 | 24956 | jmvivo | pde = (ProjectDocumentFactory) epManager.get("Documents").create(type);
|
2113 | 7753 | jmvivo | } catch (InstantiationException e) { |
2114 | 8137 | jcampos | NotificationManager.addError( |
2115 | "Clase de ProjectDocument no reconocida", e);
|
||
2116 | 7753 | jmvivo | } catch (IllegalAccessException e) { |
2117 | 8137 | jcampos | NotificationManager.addError( |
2118 | "Clase de ProjectDocument no reconocida", e);
|
||
2119 | 7753 | jmvivo | } |
2120 | 7766 | jaume | |
2121 | 7753 | jmvivo | } catch (Exception e1) { |
2122 | return null; |
||
2123 | } |
||
2124 | 7766 | jaume | return pde;
|
2125 | 7753 | jmvivo | } |
2126 | |||
2127 | 10679 | jaume | public boolean hasChanged() { |
2128 | 12698 | cesar | // we return true if the project is not empty (until we have a better method...)
|
2129 | if ((this.getDocuments().size() != 0) || modified) { |
||
2130 | return true; |
||
2131 | } |
||
2132 | return false; |
||
2133 | 11704 | jaume | // return signatureAtStartup != getXMLEntity().hash();
|
2134 | 10679 | jaume | } |
2135 | |||
2136 | public void setSignature(long hash) { |
||
2137 | signatureAtStartup = hash; |
||
2138 | } |
||
2139 | 1222 | fernando | } |