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