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