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