root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / Project.java @ 7658
History | View | Annotate | Download (40.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.NoSuchTableException; |
61 |
import com.hardcode.gdbms.engine.data.SourceInfo; |
62 |
import com.hardcode.gdbms.engine.data.db.DBSourceInfo; |
63 |
import com.hardcode.gdbms.engine.data.db.DBTableSourceInfo; |
64 |
import com.hardcode.gdbms.engine.data.file.FileSourceInfo; |
65 |
import com.hardcode.gdbms.engine.data.object.ObjectSourceInfo; |
66 |
import com.iver.andami.PluginServices; |
67 |
import com.iver.andami.ui.mdiManager.IWindow; |
68 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
69 |
import com.iver.cit.gvsig.IntializeApplicationExtension; |
70 |
import com.iver.cit.gvsig.fmap.DriverException; |
71 |
import com.iver.cit.gvsig.fmap.MapContext; |
72 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
73 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
74 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
75 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
76 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
78 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
79 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
80 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
82 |
import com.iver.cit.gvsig.fmap.operations.selection.LinkSelectionListener; |
83 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
84 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
85 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
86 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
87 |
import com.iver.cit.gvsig.project.documents.gui.ProjectWindow; |
88 |
import com.iver.cit.gvsig.project.documents.layout.ProjectMap; |
89 |
import com.iver.cit.gvsig.project.documents.layout.ProjectMapFactory; |
90 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
91 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
92 |
import com.iver.cit.gvsig.project.documents.view.ProjectView; |
93 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
94 |
import com.iver.utiles.PostProcessSupport; |
95 |
import com.iver.utiles.StringUtilities; |
96 |
import com.iver.utiles.XMLEntity; |
97 |
|
98 |
|
99 |
/**
|
100 |
* Clase que representa un proyecto de openSIG
|
101 |
*
|
102 |
* @author Fernando Gonz?lez Cort?s
|
103 |
*/
|
104 |
public class Project implements Serializable, PropertyChangeListener { |
105 |
public static String VERSION = "1.0"; |
106 |
static private IProjection defaultProjection = CRSFactory.getCRS( |
107 |
"EPSG:23030");
|
108 |
|
109 |
/*
|
110 |
* distiguishing between a static field "defaultSelectionColor" and
|
111 |
* a selectionColor field will allow to define default color in a multiple
|
112 |
* project scenario
|
113 |
*/
|
114 |
static private Color defaultSelectionColor = new Color(255, 255, 0); |
115 |
|
116 |
private PropertyChangeSupport change; |
117 |
boolean modified = false; |
118 |
private String name; |
119 |
//private String path;
|
120 |
private String creationDate; |
121 |
private String modificationDate; |
122 |
private String owner; |
123 |
private String comments; |
124 |
private Color selectionColor = null; |
125 |
//private ArrayList views = new ArrayList();
|
126 |
//private ArrayList tables = new ArrayList();
|
127 |
//private ArrayList maps = new ArrayList();
|
128 |
private ArrayList documents=new ArrayList(); |
129 |
private ArrayList extents = new ArrayList(); |
130 |
private int signatureAtStartup; |
131 |
// used to restore the position of the Project Manager window when loading a project from file
|
132 |
private static WindowInfo seedProjectWindow = null; |
133 |
private IProjection projection;
|
134 |
private TreeMap sortedDocuments = new TreeMap(new Comparator() { |
135 |
public int compare(Object o1, Object o2) { |
136 |
if ((o1 != null) && (o2 != null)) { |
137 |
int priority1=((ProjectDocument)o1).getProjectDocumentFactory().getPriority();
|
138 |
int priority2=((ProjectDocument)o2).getProjectDocumentFactory().getPriority();
|
139 |
if (priority1>=priority2)
|
140 |
return 1; |
141 |
return -1; |
142 |
} |
143 |
return 0; |
144 |
} |
145 |
}); // Para poder ordenar
|
146 |
|
147 |
/**
|
148 |
* Creates a new Project object.
|
149 |
*/
|
150 |
public Project() {
|
151 |
change = new PropertyChangeSupport(this); |
152 |
|
153 |
// change.addPropertyChangeListener(this);
|
154 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
155 |
modificationDate = creationDate; |
156 |
setSelectionColor(getDefaultColor()); |
157 |
// signatureAtStartup = computeSignature();
|
158 |
|
159 |
/* LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
|
160 |
.getPluginDirectory()
|
161 |
.getAbsolutePath() +
|
162 |
File.separator + "drivers");
|
163 |
*/
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* Obtiene la fecha de creaci?n del proyecto
|
168 |
*
|
169 |
* @return
|
170 |
*/
|
171 |
public String getCreationDate() { |
172 |
return creationDate;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Obtiene el nombre del proyecto
|
177 |
*
|
178 |
* @return
|
179 |
*/
|
180 |
public String getName() { |
181 |
return name;
|
182 |
} |
183 |
|
184 |
// /**
|
185 |
// * Obtiene la ruta completa del fichero donde se guardo por ?ltima vez el
|
186 |
// * proyecto
|
187 |
// *
|
188 |
// * @return
|
189 |
// */
|
190 |
// public String getPath() {
|
191 |
// return path;
|
192 |
// }
|
193 |
|
194 |
/**
|
195 |
* Asigna la fecha de creaci?n del proyecto. Este m?todo tiene sentido s?lo
|
196 |
* por que al recuperar la fecha del XML hay que asignarla al objeto
|
197 |
* proyecto de alguna manera. La fecha se asigna en el constructor y no se
|
198 |
* deber?a de modificar nunca
|
199 |
*
|
200 |
* @param string
|
201 |
*/
|
202 |
public void setCreationDate(String string) { |
203 |
creationDate = string; |
204 |
modified = true;
|
205 |
change.firePropertyChange("", null, null); |
206 |
} |
207 |
|
208 |
|
209 |
/**
|
210 |
* Establece el nombre del proyecto
|
211 |
*
|
212 |
* @param string
|
213 |
*/
|
214 |
public void setName(String string) { |
215 |
name = string; |
216 |
modified = true;
|
217 |
change.firePropertyChange("", null, null); |
218 |
} |
219 |
|
220 |
// /**
|
221 |
// * establece la ruta completa de donde se encuentra guardado el proyecto
|
222 |
// *
|
223 |
// * @param string
|
224 |
// */
|
225 |
// public void setPath(String string) {
|
226 |
// path = string;
|
227 |
// modified = true;
|
228 |
// change.firePropertyChange("", null, null);
|
229 |
// }
|
230 |
|
231 |
/**
|
232 |
* Devuelve a partir de la capa la tabla asociada.
|
233 |
*
|
234 |
* @param co Capa.
|
235 |
*
|
236 |
* @return ProjectTable de la tabla asociada.
|
237 |
*/
|
238 |
public ProjectTable getTable(AlphanumericData co) {
|
239 |
ArrayList tables=getDocumentsByType(ProjectTableFactory.registerName);
|
240 |
/**
|
241 |
* Como las tablas se pueden a?adir cuando se pincha en "ver tabla" de
|
242 |
* una capa, se puede intentar a?adir dos veces la misma tabla
|
243 |
*/
|
244 |
for (int i = 0; i < tables.size(); i++) { |
245 |
if (((ProjectTable) tables.get(i)).getAssociatedTable() == co) {
|
246 |
return (ProjectTable) tables.get(i);
|
247 |
} |
248 |
} |
249 |
|
250 |
return null; |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Devuelve a partir del nombre la tabla asociada.
|
255 |
*
|
256 |
* @param name Nombre.
|
257 |
* @deprecated utilizar getProjectDocumentByName(...);
|
258 |
* @return ProjectTable de la tabla asociada.
|
259 |
*/
|
260 |
public ProjectTable getTable(String name) { |
261 |
ArrayList tables=getDocumentsByType(ProjectTableFactory.registerName);
|
262 |
/**
|
263 |
* Como las tablas se pueden a?adir cuando se pincha en "ver tabla" de
|
264 |
* una capa, se puede intentar a?adir dos veces la misma tabla
|
265 |
*/
|
266 |
for (int i = 0; i < tables.size(); i++) { |
267 |
if (((ProjectTable) tables.get(i)).getName().equals(name)) {
|
268 |
return (ProjectTable) tables.get(i);
|
269 |
} |
270 |
} |
271 |
|
272 |
return null; |
273 |
} |
274 |
|
275 |
/**
|
276 |
* Devuelve true si el proyecto (o alguna tabla, vista o mapa que contiene)
|
277 |
* fue modificado
|
278 |
*
|
279 |
* @return
|
280 |
*/
|
281 |
public boolean isModified() { |
282 |
if (this.getDocumentsByType(ProjectMapFactory.registerName).size()==0 && this.getDocumentsByType(ProjectViewFactory.registerName).size()==0 && this.getDocumentsByType(ProjectTableFactory.registerName).size() == 0){ |
283 |
return false; |
284 |
} |
285 |
return true; |
286 |
///return modified; TODO El atributo modified solo detecta cuando se elimina o a?ade una vista,
|
287 |
///mapa o tabla pero no cuando se modifican.
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* Obtiene los comentarios
|
292 |
*
|
293 |
* @return
|
294 |
*/
|
295 |
public String getComments() { |
296 |
return comments;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* Obtiene la fecha de la ?ltima modificaci?n
|
301 |
*
|
302 |
* @return
|
303 |
*/
|
304 |
public String getModificationDate() { |
305 |
return modificationDate;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* Obtiene el propietario del proyecto
|
310 |
*
|
311 |
* @return
|
312 |
*/
|
313 |
public String getOwner() { |
314 |
return owner;
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* Establece una cadena como comentarios al proyecto
|
319 |
*
|
320 |
* @param string
|
321 |
*/
|
322 |
public void setComments(String string) { |
323 |
comments = string; |
324 |
modified = true;
|
325 |
change.firePropertyChange("", null, null); |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Establece la fecha de la ?ltima modificaci?n
|
330 |
*
|
331 |
* @param string
|
332 |
*/
|
333 |
public void setModificationDate(String string) { |
334 |
modificationDate = string; |
335 |
modified = true;
|
336 |
change.firePropertyChange("", null, null); |
337 |
} |
338 |
|
339 |
/**
|
340 |
* Establece el propietario del proyecto
|
341 |
*
|
342 |
* @param string
|
343 |
*/
|
344 |
public void setOwner(String string) { |
345 |
owner = string; |
346 |
modified = true;
|
347 |
change.firePropertyChange("", null, null); |
348 |
} |
349 |
|
350 |
/**
|
351 |
* Establece el flag de modificado del proyecto
|
352 |
*
|
353 |
* @param b
|
354 |
*/
|
355 |
public void setModified(boolean b) { |
356 |
modified = b; |
357 |
} |
358 |
|
359 |
/**
|
360 |
* Obtiene el color de selecci?n que se usar? en el proyecto
|
361 |
*
|
362 |
* @return
|
363 |
*/
|
364 |
public Color getSelectionColor() { |
365 |
if (selectionColor == null) { |
366 |
selectionColor = defaultSelectionColor; |
367 |
} |
368 |
return selectionColor;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Establece el color de selecci?n
|
373 |
*
|
374 |
* @param color
|
375 |
*/
|
376 |
public void setSelectionColor(Color color) { |
377 |
selectionColor = color; |
378 |
FSymbol.setSelectionColor(color); |
379 |
modified = true;
|
380 |
change.firePropertyChange("selectionColor", null, color); |
381 |
} |
382 |
|
383 |
/**
|
384 |
* Obtiene el color como un entero para su serializaci?n a XML
|
385 |
*
|
386 |
* @return
|
387 |
*/
|
388 |
public String getColor() { |
389 |
return StringUtilities.color2String(selectionColor);
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* M?todo invocado al recuperar de XML para establecer el color de
|
394 |
* seleccion del proyecto
|
395 |
*
|
396 |
* @param color Entero que representa un color
|
397 |
*/
|
398 |
public void setColor(String color) { |
399 |
modified = true;
|
400 |
selectionColor = StringUtilities.string2Color(color); |
401 |
} |
402 |
|
403 |
/* (non-Javadoc)
|
404 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
405 |
*/
|
406 |
public void propertyChange(PropertyChangeEvent evt) { |
407 |
this.modified = true; |
408 |
change.firePropertyChange(evt); |
409 |
} |
410 |
|
411 |
/**
|
412 |
* DOCUMENT ME!
|
413 |
*
|
414 |
* @param arg1
|
415 |
*/
|
416 |
public void addExtent(ProjectExtent arg1) { |
417 |
extents.add(arg1); |
418 |
modified = true;
|
419 |
change.firePropertyChange("addExtent", null, null); |
420 |
} |
421 |
|
422 |
/**
|
423 |
* DOCUMENT ME!
|
424 |
*
|
425 |
* @param arg0
|
426 |
*
|
427 |
* @return
|
428 |
*/
|
429 |
public Object removeExtent(int arg0) { |
430 |
modified = true;
|
431 |
change.firePropertyChange("delExtent", null, null); |
432 |
|
433 |
return extents.remove(arg0);
|
434 |
} |
435 |
|
436 |
/**
|
437 |
* DOCUMENT ME!
|
438 |
*
|
439 |
* @return DOCUMENT ME!
|
440 |
*/
|
441 |
public ProjectExtent[] getExtents() { |
442 |
return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]); |
443 |
} |
444 |
|
445 |
/**
|
446 |
* DOCUMENT ME!
|
447 |
*
|
448 |
* @param arg0
|
449 |
*/
|
450 |
public synchronized void addPropertyChangeListener( |
451 |
PropertyChangeListener arg0) {
|
452 |
change.addPropertyChangeListener(arg0); |
453 |
} |
454 |
|
455 |
/**
|
456 |
* DOCUMENT ME!
|
457 |
* @deprecated utilizar getDocument(String s);
|
458 |
* @return
|
459 |
*/
|
460 |
public ArrayList getMaps() { |
461 |
return getDocumentsByType(ProjectMapFactory.registerName);
|
462 |
} |
463 |
|
464 |
/**
|
465 |
* DOCUMENT ME!
|
466 |
* @deprecated utilizar getDocument(String s);
|
467 |
* @return
|
468 |
*/
|
469 |
public ArrayList getTables() { |
470 |
return getDocumentsByType(ProjectTableFactory.registerName);
|
471 |
} |
472 |
|
473 |
/**
|
474 |
* DOCUMENT ME!
|
475 |
* @deprecated utilizar getDocument(String s);
|
476 |
* @return
|
477 |
*/
|
478 |
public ArrayList getViews() { |
479 |
return getDocumentsByType(ProjectViewFactory.registerName);
|
480 |
} |
481 |
/**
|
482 |
* A?ade un mapa al proyecto
|
483 |
* @deprecated utilizar addDocument(ProjectDocument pD);
|
484 |
* @param m
|
485 |
*/
|
486 |
public void addMap(ProjectMap m) { |
487 |
addDocument(m); |
488 |
} |
489 |
|
490 |
/**
|
491 |
* Elimina un mapa del proyecto
|
492 |
* @deprecated utilizar delDocument(ProjectDocument pD);
|
493 |
* @param i indice del mapa
|
494 |
*/
|
495 |
public void delMap(int i) { |
496 |
ArrayList list=getDocumentsByType(ProjectMapFactory.registerName);
|
497 |
delDocument((ProjectDocument)list.get(i)); |
498 |
} |
499 |
/**
|
500 |
* A?ade una tabla al proyecto
|
501 |
* @deprecated utilizar addDocument(ProjectDocument pD);
|
502 |
* @param t
|
503 |
*/
|
504 |
public void addTable(ProjectTable t) { |
505 |
addDocument(t); |
506 |
} |
507 |
|
508 |
/**
|
509 |
* Elimina una tabla del proyecto
|
510 |
* @deprecated utilizar delDocument(ProjectDocument pD);
|
511 |
* @param i indice de la tabla
|
512 |
*/
|
513 |
public void delTable(int i) { |
514 |
ArrayList list=getDocumentsByType(ProjectTableFactory.registerName);
|
515 |
delDocument((ProjectDocument)list.get(i)); |
516 |
} |
517 |
/**
|
518 |
* A?ade una vista al proyecto
|
519 |
* @deprecated utilizar addDocument(ProjectDocument pD);
|
520 |
* @param v
|
521 |
*/
|
522 |
public void addView(ProjectView v) { |
523 |
addDocument(v); |
524 |
} |
525 |
|
526 |
/**
|
527 |
* Elimina una tabla del proyecto
|
528 |
* @deprecated utilizar delDocument(ProjectDocument pD);
|
529 |
* @param i indice del proyecto
|
530 |
*/
|
531 |
public void delView(int i) { |
532 |
ArrayList list=getDocumentsByType(ProjectViewFactory.registerName);
|
533 |
delDocument((ProjectDocument)list.get(i)); |
534 |
} |
535 |
|
536 |
|
537 |
/**
|
538 |
* DOCUMENT ME!
|
539 |
*
|
540 |
* @return DOCUMENT ME!
|
541 |
*
|
542 |
* @throws DriverException
|
543 |
* @throws XMLException
|
544 |
*/
|
545 |
public XMLEntity getXMLEntity() {
|
546 |
XMLEntity xml = new XMLEntity();
|
547 |
xml.putProperty("className", this.getClass().getName()); |
548 |
xml.putProperty("VERSION", VERSION);
|
549 |
xml.putProperty("comments", comments);
|
550 |
xml.putProperty("creationDate", creationDate);
|
551 |
|
552 |
int numExtents = extents.size();
|
553 |
xml.putProperty("numExtents", numExtents);
|
554 |
|
555 |
for (int i = 0; i < numExtents; i++) { |
556 |
xml.addChild(((ProjectExtent) extents.get(i)).getXMLEntity()); |
557 |
} |
558 |
|
559 |
// NUEVO: ESTO ESTA EN PRUEBAS. SIRVE PARA
|
560 |
// BORRAR LAS REFERENCIAS A DATASOURCES QUE HEMOS
|
561 |
// BORRADO. Hay que probar a borrarlos cuando se
|
562 |
// borra una tabla y cuando se borra una capa.
|
563 |
cleanBadReferences(); |
564 |
SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
|
565 |
xml.putProperty("data-source-count", infos.length);
|
566 |
|
567 |
for (int i = 0; i < infos.length; i++) { |
568 |
SourceInfo di = infos[i]; |
569 |
XMLEntity child = this.getSourceInfoXMLEntity(di);
|
570 |
xml.addChild(child); |
571 |
} |
572 |
int numDocuments=0; |
573 |
for (int i = 0; i < documents.size(); i++) { |
574 |
try {
|
575 |
XMLEntity xmlchild=((ProjectDocument) documents.get(i)).getXMLEntity(); |
576 |
xml.addChild(xmlchild); |
577 |
numDocuments++; |
578 |
} catch (SaveException e) {
|
579 |
e.showError(); |
580 |
} |
581 |
} |
582 |
xml.putProperty("numDocuments", numDocuments);
|
583 |
/* int numViews=0;
|
584 |
for (int i = 0; i < views.size(); i++) {
|
585 |
try {
|
586 |
XMLEntity xmlchild=((ProjectView) views.get(i)).getXMLEntity();
|
587 |
xml.addChild(xmlchild);
|
588 |
numViews++;
|
589 |
} catch (SaveException e) {
|
590 |
e.showError();
|
591 |
}
|
592 |
}
|
593 |
xml.putProperty("numViews", numViews);
|
594 |
|
595 |
int numMaps=0;
|
596 |
for (int i = 0; i < maps.size(); i++) {
|
597 |
try {
|
598 |
XMLEntity xmlchild=((ProjectMap) maps.get(i)).getXMLEntity();
|
599 |
xml.addChild(xmlchild);
|
600 |
numMaps++;
|
601 |
} catch (SaveException e) {
|
602 |
e.showError();
|
603 |
}
|
604 |
}
|
605 |
xml.putProperty("numMaps", numMaps);
|
606 |
*/
|
607 |
xml.putProperty("modificationDate", modificationDate);
|
608 |
xml.putProperty("modified", modified);
|
609 |
xml.putProperty("name", name);
|
610 |
xml.putProperty("owner", owner);
|
611 |
//xml.putProperty("path", path);
|
612 |
xml.putProperty("selectionColor",
|
613 |
StringUtilities.color2String(selectionColor)); |
614 |
/*
|
615 |
int numTables=0;
|
616 |
for (int i = 0; i < tables.size(); i++) {
|
617 |
try {
|
618 |
XMLEntity xmlchild=((ProjectTable) tables.get(i)).getXMLEntity();
|
619 |
xml.addChild(xmlchild);
|
620 |
numTables++;
|
621 |
} catch (SaveException e) {
|
622 |
|
623 |
e.showError();
|
624 |
}
|
625 |
}
|
626 |
xml.putProperty("numTables", numTables);
|
627 |
*/
|
628 |
xml.putProperty("projection", defaultProjection.getAbrev());
|
629 |
|
630 |
// save the properties of the Project Manager window
|
631 |
IWindow[] andamiViews = PluginServices.getMDIManager().getAllWindows();
|
632 |
for (int i=0; i<andamiViews.length; i++) { |
633 |
if (andamiViews[i] instanceof ProjectWindow) { |
634 |
ProjectWindow pw = (ProjectWindow) andamiViews[i]; |
635 |
try {
|
636 |
XMLEntity xmlchild = null;
|
637 |
xmlchild = getWindowInfoXMLEntity(pw); |
638 |
if (xmlchild!=null) { |
639 |
xml.addChild(xmlchild); |
640 |
} |
641 |
} |
642 |
catch (SaveException e){
|
643 |
e.showError(); |
644 |
} |
645 |
} |
646 |
} |
647 |
|
648 |
return xml;
|
649 |
} |
650 |
/**
|
651 |
* DOCUMENT ME!
|
652 |
*
|
653 |
* @param xml DOCUMENT ME!
|
654 |
*
|
655 |
* @return DOCUMENT ME!
|
656 |
* @throws XMLException
|
657 |
* @throws DriverException
|
658 |
* @throws DriverIOException
|
659 |
* @throws OpenException
|
660 |
*/
|
661 |
public static Project createFromXML03(XMLEntity xml) |
662 |
throws OpenException {
|
663 |
Project p = new Project();
|
664 |
try{
|
665 |
p.comments = xml.getStringProperty("comments");
|
666 |
p.creationDate = xml.getStringProperty("creationDate");
|
667 |
|
668 |
int numExtents=xml.getIntProperty("numExtents"); |
669 |
for (int i = 0; i < numExtents; i++) { |
670 |
ProjectExtent pe=ProjectExtent.createFromXML03(xml.getChild(i)); |
671 |
p.extents.add(pe); |
672 |
} |
673 |
|
674 |
int numDocuments=0; |
675 |
if (xml.contains("numDocuments")) { |
676 |
numDocuments=xml.getIntProperty("numDocuments");
|
677 |
}else {
|
678 |
int numViews = xml.getIntProperty("numViews"); |
679 |
int numMaps = xml.getIntProperty("numMaps"); |
680 |
int numTables = xml.getIntProperty("numTables"); |
681 |
numDocuments=numViews+numMaps+numTables; |
682 |
} |
683 |
for (int i = numExtents; i < numDocuments+numExtents; i++) { |
684 |
ProjectDocument pD=ProjectDocument.createFromXML03(xml.getChild(i), p); |
685 |
p.addDocument(pD); |
686 |
p.sortedDocuments.put(pD,new Integer(i)); |
687 |
} |
688 |
ProjectDocument[] sortDocKeys=(ProjectDocument[])p.sortedDocuments.keySet().toArray(new ProjectDocument[0]); |
689 |
Integer[] sortDocValues=(Integer[])p.sortedDocuments.values().toArray(new Integer[0]); |
690 |
|
691 |
int i=0; |
692 |
for (int k = numExtents; k < (numDocuments + numExtents); k++) { |
693 |
sortDocKeys[i].setXMLEntity(xml.getChild(sortDocValues[i].intValue()),p); |
694 |
i++; |
695 |
} |
696 |
|
697 |
p.modificationDate = xml.getStringProperty("modificationDate");
|
698 |
p.modified = xml.getBooleanProperty("modified");
|
699 |
p.name = xml.getStringProperty("name");
|
700 |
p.owner = xml.getStringProperty("owner");
|
701 |
p.selectionColor = StringUtilities.string2Color(xml.getStringProperty( |
702 |
"selectionColor"));
|
703 |
|
704 |
String strProj = xml.getStringProperty("projection"); |
705 |
if (strProj != null) |
706 |
p.setProjection( CRSFactory.getCRS(strProj)); |
707 |
}catch (Exception e) { |
708 |
throw new OpenException(e,p.getClass().getName()); |
709 |
} |
710 |
return p;
|
711 |
} |
712 |
|
713 |
/**
|
714 |
* DOCUMENT ME!
|
715 |
*
|
716 |
* @param xml DOCUMENT ME!
|
717 |
*
|
718 |
* @return DOCUMENT ME!
|
719 |
*
|
720 |
* @throws XMLException
|
721 |
* @throws DriverException
|
722 |
* @throws DriverIOException
|
723 |
* @throws OpenException
|
724 |
* @throws VersionException
|
725 |
*/
|
726 |
public static Project createFromXML(XMLEntity xml) |
727 |
throws OpenException {
|
728 |
|
729 |
int childNumber = 0; |
730 |
Project p = new Project();
|
731 |
try{
|
732 |
p.comments = xml.getStringProperty("comments");
|
733 |
p.creationDate = xml.getStringProperty("creationDate");
|
734 |
int numExtents = xml.getIntProperty("numExtents"); |
735 |
|
736 |
for (int i = 0; i < numExtents; i++) { |
737 |
ProjectExtent pe = ProjectExtent.createFromXML(xml.getChild(i)); |
738 |
p.extents.add(pe); |
739 |
} |
740 |
|
741 |
childNumber = numExtents; |
742 |
|
743 |
int numDataSources = xml.getIntProperty("data-source-count"); |
744 |
|
745 |
for (int i = childNumber; i < (childNumber + numDataSources); i++) { |
746 |
XMLEntity child = xml.getChild(i); |
747 |
|
748 |
if (child.getStringProperty("type").equals("otherDriverFile")) { |
749 |
LayerFactory.getDataSourceFactory().addFileDataSource(child.getStringProperty( |
750 |
"driverName"), child.getStringProperty("gdbmsname"), |
751 |
child.getStringProperty("file"));
|
752 |
} else if (child.getStringProperty("type").equals("sameDriverFile")) { |
753 |
} else if (child.getStringProperty("type").equals("db")) { |
754 |
LayerFactory.getDataSourceFactory().addDBDataSourceByTable(child.getStringProperty( |
755 |
"gdbmsname"), child.getStringProperty("host"), |
756 |
child.getIntProperty("port"),
|
757 |
child.getStringProperty("user"),
|
758 |
child.getStringProperty("password"),
|
759 |
child.getStringProperty("dbName"),
|
760 |
child.getStringProperty("tableName"),
|
761 |
child.getStringProperty("driverInfo"));
|
762 |
} |
763 |
} |
764 |
|
765 |
childNumber += numDataSources; |
766 |
int numDocuments=0; |
767 |
if (xml.contains("numDocuments")) { |
768 |
numDocuments=xml.getIntProperty("numDocuments");
|
769 |
}else {
|
770 |
int numViews = xml.getIntProperty("numViews"); |
771 |
int numMaps = xml.getIntProperty("numMaps"); |
772 |
int numTables = xml.getIntProperty("numTables"); |
773 |
numDocuments=numViews+numMaps+numTables; |
774 |
} |
775 |
|
776 |
for (int i = childNumber; i < (numDocuments + childNumber); i++) { |
777 |
try{
|
778 |
ProjectDocument pD=ProjectDocument.createFromXML(xml.getChild(i), p); |
779 |
p.addDocument(pD); |
780 |
p.sortedDocuments.put(pD,new Integer(i)); |
781 |
if (pD.getSeedViewInfo()!=null) { // open the view, if it was open, and restore its dimensions |
782 |
IWindow window=pD.createWindow(); |
783 |
PluginServices.getMDIManager().addWindow(window); |
784 |
PluginServices.getMDIManager().changeWindowInfo(window, pD.getSeedViewInfo()); |
785 |
} |
786 |
}catch(OpenException e){
|
787 |
e.showError(); |
788 |
} |
789 |
} |
790 |
ProjectDocument[] sortDocKeys=(ProjectDocument[])p.sortedDocuments.keySet().toArray(new ProjectDocument[0]); |
791 |
Integer[] sortDocValues=(Integer[])p.sortedDocuments.values().toArray(new Integer[0]); |
792 |
|
793 |
int i=0; |
794 |
for (int k = childNumber; k < (numDocuments + childNumber); k++) { |
795 |
try{
|
796 |
sortDocKeys[i].setXMLEntity(xml.getChild(sortDocValues[i].intValue()),p); |
797 |
}catch(OpenException e){
|
798 |
e.showError(); |
799 |
} |
800 |
i++; |
801 |
} |
802 |
childNumber += numDocuments; |
803 |
|
804 |
p.modificationDate = xml.getStringProperty("modificationDate");
|
805 |
p.modified = xml.getBooleanProperty("modified");
|
806 |
p.name = xml.getStringProperty("name");
|
807 |
p.owner = xml.getStringProperty("owner");
|
808 |
p.selectionColor = StringUtilities.string2Color(xml.getStringProperty( |
809 |
"selectionColor"));
|
810 |
|
811 |
p.setLinkTable(); |
812 |
String strProj = xml.getStringProperty("projection"); |
813 |
|
814 |
if (strProj != null) { |
815 |
p.setProjection( CRSFactory.getCRS(strProj)); |
816 |
} |
817 |
PostProcessSupport.executeCalls(); |
818 |
}catch (Exception e) { |
819 |
throw new OpenException(e,p.getClass().getName()); |
820 |
} |
821 |
// p.setSignature( p.hashCode());
|
822 |
return p;
|
823 |
|
824 |
} |
825 |
|
826 |
// private void setSignature(int signature) {
|
827 |
// this.signatureAtStartup = computeSignature();
|
828 |
// }
|
829 |
|
830 |
/**
|
831 |
* Reestablece los link que ten?a cada tabla con las dem?s.
|
832 |
*/
|
833 |
public void setLinkTable() { |
834 |
ArrayList tables = getDocumentsByType(ProjectTableFactory.registerName);
|
835 |
|
836 |
for (int i = 0; i < tables.size(); i++) { |
837 |
for (int j = 0; j < tables.size(); j++) { |
838 |
/*System.out.println("name = " +
|
839 |
((ProjectTable) tables.get(j)).getModelo().getName());
|
840 |
System.out.println("linktable = " +
|
841 |
((ProjectTable) tables.get(i)).getLinkTable());
|
842 |
*/
|
843 |
try {
|
844 |
if ((((ProjectTable) tables.get(i)).getLinkTable() != null) && |
845 |
((ProjectTable) tables.get(i)).getLinkTable().equals(((ProjectTable) tables |
846 |
.get( |
847 |
j)).getModelo().getRecordset().getName())) { |
848 |
LinkSelectionListener lsl; |
849 |
|
850 |
lsl = new LinkSelectionListener(((ProjectTable) tables.get(
|
851 |
i)).getModelo().getRecordset(), |
852 |
((ProjectTable) tables.get(j)).getModelo().getRecordset(), |
853 |
((ProjectTable) tables.get(i)).getField1(), |
854 |
((ProjectTable) tables.get(i)).getField2()); |
855 |
|
856 |
(((ProjectTable) tables.get(i)).getModelo().getRecordset()) |
857 |
.addSelectionListener(lsl); |
858 |
|
859 |
} |
860 |
} catch (DriverLoadException e) {
|
861 |
// TODO Auto-generated catch block
|
862 |
e.printStackTrace(); |
863 |
} |
864 |
} |
865 |
} |
866 |
} |
867 |
|
868 |
/**
|
869 |
* Obtiene la vista que contiene a la capa que se pasa como par?metro
|
870 |
*
|
871 |
* @param layer Capa cuya vista se quiere obtener
|
872 |
*
|
873 |
* @return
|
874 |
*
|
875 |
* @throws RuntimeException Si la capa que se pasa como par?metro no se
|
876 |
* encuentra en ninguna vista
|
877 |
*/
|
878 |
public String getView(FLayer layer) { |
879 |
ArrayList views=getDocumentsByType(ProjectViewFactory.registerName);
|
880 |
for (int v = 0; v < views.size(); v++) { |
881 |
ProjectView pView = (ProjectView) views.get(v); |
882 |
FLayers layers = pView.getMapContext().getLayers(); |
883 |
if (isView(layers,layer))return pView.getName(); |
884 |
} |
885 |
|
886 |
throw new RuntimeException("The layer is not in a view"); |
887 |
} |
888 |
|
889 |
public boolean isView(FLayers layers, FLayer layer) { |
890 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
891 |
if (layers.getLayer(i) instanceof FLayers){ |
892 |
return isView((FLayers)layers.getLayer(i),layer);
|
893 |
} |
894 |
if (layers.getLayer(i) == layer) {
|
895 |
return true; |
896 |
} |
897 |
} |
898 |
return false; |
899 |
} |
900 |
|
901 |
/**
|
902 |
* Devuelve la vista cuyo nombre coincide (sensible a mayusculas) con el
|
903 |
* que se pasa como par?metro. Devuelve null si no hay ninguna vista con
|
904 |
* ese nombre
|
905 |
*
|
906 |
* @param viewName Nombre de la vista que se quiere obtener
|
907 |
*
|
908 |
* @return DOCUMENT ME!
|
909 |
*/
|
910 |
/*public ProjectView getViewByName(String viewName) {
|
911 |
ArrayList views=getDocuments(PluginServices.getText(this,"Vista"));
|
912 |
Object o = getProjectDocumentByName(viewName, PluginServices.getText(this,"Vista"));
|
913 |
|
914 |
if (o == null) {
|
915 |
return null;
|
916 |
}
|
917 |
|
918 |
return (ProjectView) o;
|
919 |
}
|
920 |
*/
|
921 |
/**
|
922 |
* DOCUMENT ME!
|
923 |
*
|
924 |
* @return DOCUMENT ME!
|
925 |
*/
|
926 |
public IProjection getProjection() {
|
927 |
if (projection == null) |
928 |
projection = Project.defaultProjection; |
929 |
return projection;
|
930 |
} |
931 |
|
932 |
/**
|
933 |
* DOCUMENT ME!
|
934 |
*
|
935 |
* @param defaultProjection DOCUMENT ME!
|
936 |
*/
|
937 |
public void setProjection(IProjection projection) { |
938 |
this.projection = projection;
|
939 |
} |
940 |
|
941 |
|
942 |
/**
|
943 |
* Sets the projection used when no projection is defined
|
944 |
* @param defaultProjection DOCUMENT ME!
|
945 |
*/
|
946 |
public static void setDefaultProjection(IProjection defaultProjection) { |
947 |
Project.defaultProjection = defaultProjection; |
948 |
} |
949 |
|
950 |
public static IProjection getDefaultProjection() { |
951 |
return Project.defaultProjection;
|
952 |
} |
953 |
|
954 |
/**
|
955 |
* Obtiene un documento a partir de su nombre y el nombre de registro en el pointExtension,
|
956 |
* este ?ltimo se puede obtener del Project****Factory.registerName.
|
957 |
*
|
958 |
* @param name Nombre del documento
|
959 |
* @param type nombre de registro en el extensionPoint
|
960 |
*
|
961 |
* @return Documento
|
962 |
*/
|
963 |
public ProjectDocument getProjectDocumentByName(String name, String type) { |
964 |
ArrayList docs=getDocumentsByType(type);
|
965 |
for (Iterator iter = docs.iterator(); iter.hasNext();) { |
966 |
ProjectDocument elem = (ProjectDocument) iter.next(); |
967 |
|
968 |
if (elem.getName().equals(name)) {
|
969 |
return elem;
|
970 |
} |
971 |
} |
972 |
|
973 |
return null; |
974 |
} |
975 |
|
976 |
/**
|
977 |
* DOCUMENT ME!
|
978 |
*
|
979 |
* @param name
|
980 |
*
|
981 |
* @return
|
982 |
*/
|
983 |
/*public ProjectTable getTableByName(String name) {
|
984 |
ArrayList tables=getDocuments(PluginServices.getText(this,"Tabla"));
|
985 |
Object o = getProjectElementByName(name, tables);
|
986 |
|
987 |
if (o == null) {
|
988 |
return null;
|
989 |
}
|
990 |
|
991 |
return (ProjectTable) o;
|
992 |
}
|
993 |
*/
|
994 |
/**
|
995 |
* DOCUMENT ME!
|
996 |
*
|
997 |
* @param name
|
998 |
*
|
999 |
* @return
|
1000 |
*/
|
1001 |
/*public ProjectMap getLayoutByName(String name) {
|
1002 |
Object o = getProjectElementByName(name, maps);
|
1003 |
|
1004 |
if (o == null) {
|
1005 |
return null;
|
1006 |
}
|
1007 |
|
1008 |
return (ProjectMap) o;
|
1009 |
}
|
1010 |
*/
|
1011 |
public SelectableDataSource getDataSourceByLayer(FLayer layer) throws DriverException { |
1012 |
ArrayList tables = getDocumentsByType(ProjectTableFactory.registerName);
|
1013 |
SelectableDataSource dataSource = null;
|
1014 |
try {
|
1015 |
for (int i = 0; i < tables.size(); i++) { |
1016 |
ProjectTable pt = (ProjectTable) tables.get(i); |
1017 |
if (pt.getOriginal() == ((AlphanumericData) layer).getRecordset()){
|
1018 |
dataSource = pt.getModelo().getRecordset(); |
1019 |
break;
|
1020 |
}else if (pt.getModelo() == ((AlphanumericData) layer).getRecordset()){ |
1021 |
|
1022 |
dataSource = pt.getModelo().getRecordset(); |
1023 |
|
1024 |
break;
|
1025 |
} |
1026 |
} |
1027 |
} catch (DriverLoadException e) {
|
1028 |
// TODO Auto-generated catch block
|
1029 |
e.printStackTrace(); |
1030 |
} |
1031 |
|
1032 |
if (dataSource == null){ |
1033 |
//No se ha creado la tabla asociada al tema
|
1034 |
dataSource = ((AlphanumericData) layer).getRecordset(); |
1035 |
} |
1036 |
|
1037 |
return dataSource;
|
1038 |
|
1039 |
} |
1040 |
|
1041 |
/**
|
1042 |
* Recorremos las capas y las tablas del proyecto, y creamos una lista
|
1043 |
* con todos los datasources de GDBMS que estamos usando.
|
1044 |
* Luego recorremos los que est?n registrados, y borramos
|
1045 |
* aquellos que no est?n siendo usados, es decir, aquellos
|
1046 |
* que no est?n en nuestra lista (un Hash con clave el nombre
|
1047 |
* del GDBMS)
|
1048 |
*
|
1049 |
*/
|
1050 |
private void cleanBadReferences() |
1051 |
{ |
1052 |
ArrayList tables=getDocumentsByType(ProjectTableFactory.registerName);
|
1053 |
Hashtable usedDataSources = new Hashtable(); |
1054 |
// Primero las tablas
|
1055 |
int i, j;
|
1056 |
try {
|
1057 |
for (i=0; i<tables.size(); i++) |
1058 |
{ |
1059 |
ProjectTable t = (ProjectTable) tables.get(i); |
1060 |
SelectableDataSource ds; |
1061 |
|
1062 |
ds = t.getModelo().getRecordset(); |
1063 |
|
1064 |
if (t.getOriginal() != null) |
1065 |
usedDataSources.put(t.getOriginal().getRecordset().getName(), t.getOriginal()); |
1066 |
usedDataSources.put(ds.getName(), ds); |
1067 |
} |
1068 |
} catch (DriverLoadException e) {
|
1069 |
// TODO Auto-generated catch block
|
1070 |
e.printStackTrace(); |
1071 |
} |
1072 |
// Ahora las vistas
|
1073 |
ArrayList views=getDocumentsByType(ProjectViewFactory.registerName);
|
1074 |
try {
|
1075 |
for (i=0; i<views.size(); i++) |
1076 |
{ |
1077 |
ProjectView pv = (ProjectView) views.get(i); |
1078 |
|
1079 |
FLayers lyrs = pv.getMapContext().getLayers(); |
1080 |
|
1081 |
for (j=0; j<lyrs.getLayersCount(); j++) |
1082 |
{ |
1083 |
FLayer lyr = lyrs.getLayer(j); |
1084 |
if (lyr instanceof FLyrVect) |
1085 |
{ |
1086 |
FLyrVect lyrVect = (FLyrVect) lyr; |
1087 |
if (lyrVect.isAvailable())
|
1088 |
usedDataSources.put(lyrVect.getRecordset().getName(), lyrVect.getSource().getRecordset()); |
1089 |
} |
1090 |
} |
1091 |
MapContext aux = pv.getMapOverViewContext(); |
1092 |
if (aux != null) |
1093 |
{ |
1094 |
FLayers lyrsOverview = aux.getLayers(); |
1095 |
for (j=0; j<lyrsOverview.getLayersCount(); j++) |
1096 |
{ |
1097 |
FLayer lyr = lyrsOverview.getLayer(j); |
1098 |
if (lyr instanceof FLyrVect) |
1099 |
{ |
1100 |
FLyrVect lyrVect = (FLyrVect) lyr; |
1101 |
usedDataSources.put(lyrVect.getSource().getRecordset().getName(), lyrVect.getSource().getRecordset()); |
1102 |
} |
1103 |
} |
1104 |
} |
1105 |
|
1106 |
} // for i
|
1107 |
} catch (DriverLoadException e) {
|
1108 |
// TODO Auto-generated catch block
|
1109 |
e.printStackTrace(); |
1110 |
} catch (DriverException e) {
|
1111 |
// TODO Auto-generated catch block
|
1112 |
e.printStackTrace(); |
1113 |
} |
1114 |
// Recorremos los dataSources y los borramos si no
|
1115 |
// los estamos usando.
|
1116 |
SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
|
1117 |
try {
|
1118 |
for (i=0; i < infos.length; i++) |
1119 |
{ |
1120 |
if (!usedDataSources.containsKey(infos[i].name))
|
1121 |
{ |
1122 |
DataSource ds;
|
1123 |
ds = LayerFactory.getDataSourceFactory().createRandomDataSource(infos[i].name); |
1124 |
ds.remove(); |
1125 |
} |
1126 |
} |
1127 |
} catch (DriverLoadException e) {
|
1128 |
// TODO Auto-generated catch block
|
1129 |
e.printStackTrace(); |
1130 |
} catch (NoSuchTableException e) {
|
1131 |
// TODO Auto-generated catch block
|
1132 |
e.printStackTrace(); |
1133 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
1134 |
// TODO Auto-generated catch block
|
1135 |
e.printStackTrace(); |
1136 |
} |
1137 |
} |
1138 |
|
1139 |
/**
|
1140 |
* DOCUMENT ME!
|
1141 |
*
|
1142 |
* @return DOCUMENT ME!
|
1143 |
* @throws SaveException
|
1144 |
* @throws XMLException
|
1145 |
* @throws SaveException
|
1146 |
*/
|
1147 |
public XMLEntity getWindowInfoXMLEntity(IWindow window) throws SaveException { |
1148 |
if (window!=null && PluginServices.getMDIManager().getWindowInfo(window)!=null) { |
1149 |
WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(window); |
1150 |
XMLEntity xml = new XMLEntity();
|
1151 |
//xml.putProperty("nameClass", this.getClass().getName());
|
1152 |
try{
|
1153 |
xml.setName("ViewInfoProperties");
|
1154 |
xml.putProperty("className", this.getClass().getName()); |
1155 |
xml.putProperty("X", vi.getX());
|
1156 |
xml.putProperty("Y", vi.getY());
|
1157 |
xml.putProperty("Width", vi.getWidth());
|
1158 |
xml.putProperty("Height", vi.getHeight());
|
1159 |
xml.putProperty("isVisible", vi.isVisible());
|
1160 |
xml.putProperty("isResizable", vi.isResizable());
|
1161 |
xml.putProperty("isMaximizable", vi.isMaximizable());
|
1162 |
xml.putProperty("isModal", vi.isModal());
|
1163 |
xml.putProperty("isModeless", vi.isModeless());
|
1164 |
xml.putProperty("isClosed", vi.isClosed());
|
1165 |
if (vi.isMaximized()==true) { |
1166 |
xml.putProperty("isMaximized", vi.isMaximized());
|
1167 |
xml.putProperty("normalX", vi.getNormalX());
|
1168 |
xml.putProperty("normalY", vi.getNormalY());
|
1169 |
xml.putProperty("normalWidth", vi.getNormalWidth());
|
1170 |
xml.putProperty("normalHeight", vi.getNormalHeight());
|
1171 |
} |
1172 |
}catch (Exception e) { |
1173 |
throw new SaveException(e,this.getClass().getName()); |
1174 |
} |
1175 |
return xml;
|
1176 |
} |
1177 |
return null; |
1178 |
} |
1179 |
|
1180 |
public static WindowInfo createWindowInfoFromXMLEntity(XMLEntity xml) |
1181 |
{ |
1182 |
WindowInfo result = new WindowInfo();
|
1183 |
result.setX(xml.getIntProperty("X"));
|
1184 |
result.setY(xml.getIntProperty("Y"));
|
1185 |
result.setHeight(xml.getIntProperty("Height"));
|
1186 |
result.setWidth(xml.getIntProperty("Width"));
|
1187 |
result.setClosed(xml.getBooleanProperty("isClosed"));
|
1188 |
if (xml.contains("isMaximized")) { |
1189 |
boolean maximized = xml.getBooleanProperty("isMaximized"); |
1190 |
result.setMaximized(maximized); |
1191 |
if (maximized==true) { |
1192 |
result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
1193 |
} |
1194 |
else {
|
1195 |
result.setNormalBounds(result.getBounds()); |
1196 |
} |
1197 |
} |
1198 |
|
1199 |
return result;
|
1200 |
} |
1201 |
|
1202 |
public static WindowInfo getSeedProjectWindow() { |
1203 |
return seedProjectWindow;
|
1204 |
} |
1205 |
|
1206 |
public XMLEntity getSourceInfoXMLEntity(SourceInfo di) {
|
1207 |
XMLEntity child = new XMLEntity();
|
1208 |
|
1209 |
|
1210 |
if (di instanceof ObjectSourceInfo) { |
1211 |
ObjectSourceInfo driver = (ObjectSourceInfo) di; |
1212 |
child.putProperty("type", "sameDriverFile"); |
1213 |
child.putProperty("gdbmsname", driver.name);
|
1214 |
} else if (di instanceof FileSourceInfo) { |
1215 |
FileSourceInfo vfdi = (FileSourceInfo) di; |
1216 |
child.putProperty("type", "otherDriverFile"); |
1217 |
child.putProperty("gdbmsname", vfdi.name);
|
1218 |
child.putProperty("file", vfdi.file);
|
1219 |
child.putProperty("driverName", vfdi.driverName);
|
1220 |
} else if (di instanceof DBSourceInfo) { |
1221 |
DBTableSourceInfo dbdi = (DBTableSourceInfo) di; |
1222 |
child.putProperty("type", "db"); |
1223 |
child.putProperty("gdbmsname", dbdi.name);
|
1224 |
child.putProperty("dbms", dbdi.dbms);
|
1225 |
child.putProperty("host", dbdi.host);
|
1226 |
child.putProperty("port", dbdi.port);
|
1227 |
child.putProperty("user", dbdi.user);
|
1228 |
child.putProperty("password", dbdi.password);
|
1229 |
child.putProperty("dbName", dbdi.dbName);
|
1230 |
child.putProperty("tableName", dbdi.tableName);
|
1231 |
child.putProperty("driverInfo", dbdi.driverName);
|
1232 |
} |
1233 |
|
1234 |
return child;
|
1235 |
} |
1236 |
/**
|
1237 |
* Devuelve un arrayList con todos los documentos del tipo especificado como par?metro.
|
1238 |
*
|
1239 |
* @param registerName nombre de registro en el extensionPoint
|
1240 |
*
|
1241 |
* @return Documentos del tipo especificado
|
1242 |
*/
|
1243 |
public ArrayList getDocumentsByType(String registerName) { |
1244 |
ArrayList docuArray=new ArrayList(); |
1245 |
for (int i=0;i<documents.size();i++) { |
1246 |
ProjectDocument projectDocument=(ProjectDocument)documents.get(i); |
1247 |
ProjectDocumentFactory pdf=projectDocument.getProjectDocumentFactory(); |
1248 |
if (pdf==null) |
1249 |
continue;
|
1250 |
if (pdf.getRegisterName().equals(registerName)) {
|
1251 |
docuArray.add(projectDocument); |
1252 |
} |
1253 |
} |
1254 |
return docuArray;
|
1255 |
} |
1256 |
/**
|
1257 |
* Devuelve un arrayList con todos los documentos.
|
1258 |
*
|
1259 |
* @return Documentos
|
1260 |
*/
|
1261 |
public ArrayList getDocuments() { |
1262 |
ArrayList docuArray=new ArrayList(); |
1263 |
for (int i=0;i<documents.size();i++) { |
1264 |
ProjectDocument projectDocument=(ProjectDocument)documents.get(i); |
1265 |
docuArray.add(projectDocument); |
1266 |
} |
1267 |
return docuArray;
|
1268 |
} |
1269 |
/**
|
1270 |
* Inserta un documento.
|
1271 |
*
|
1272 |
* @param doc Documento
|
1273 |
*/
|
1274 |
public void addDocument(ProjectDocument doc) { |
1275 |
documents.add(doc); |
1276 |
doc.addPropertyChangeListener(this);
|
1277 |
modified = true;
|
1278 |
change.firePropertyChange("", null, null); |
1279 |
doc.setProject(this, 0); |
1280 |
doc.afterAdd(); |
1281 |
|
1282 |
} |
1283 |
/**
|
1284 |
* Borra un documento.
|
1285 |
*
|
1286 |
* @param doc Documento
|
1287 |
*/
|
1288 |
public void delDocument(ProjectDocument doc) { |
1289 |
documents.remove(doc); |
1290 |
modified = true;
|
1291 |
change.firePropertyChange("", null, null); |
1292 |
doc.afterRemove(); |
1293 |
} |
1294 |
|
1295 |
/**
|
1296 |
* Sets the default selection color that will be used in subsequent
|
1297 |
* projects.
|
1298 |
*
|
1299 |
* @param color
|
1300 |
*/
|
1301 |
public static void setDefaultSelectionColor(Color color) { |
1302 |
defaultSelectionColor = color; |
1303 |
} |
1304 |
|
1305 |
/**
|
1306 |
* Returns the current default selection color defined which is the
|
1307 |
* color defined when the user does not define any other one
|
1308 |
* @return java.awt.Color
|
1309 |
*/
|
1310 |
public static Color getDefaultColor() { |
1311 |
// TODO es millorable?
|
1312 |
XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
1313 |
if (xml.contains("DefaultSelectionColor")) |
1314 |
defaultSelectionColor = StringUtilities. |
1315 |
string2Color(xml.getStringProperty("DefaultSelectionColor"));
|
1316 |
return defaultSelectionColor;
|
1317 |
} |
1318 |
|
1319 |
// public boolean hasChanged() {
|
1320 |
// return signatureAtStartup != computeSignature();
|
1321 |
// }
|
1322 |
|
1323 |
// public int computeSignature() {
|
1324 |
//
|
1325 |
//// /* TODO method also present in ProjectMap, ProjectTable,
|
1326 |
//// * ProjectView and ProjectExtent
|
1327 |
//// */
|
1328 |
// int result = 17;
|
1329 |
////
|
1330 |
//// Class clazz = getClass();
|
1331 |
//// Field[] fields = clazz.getDeclaredFields();
|
1332 |
//// for (int i = 0; i < fields.length; i++) {
|
1333 |
//// try {
|
1334 |
//// // don't compute following fields
|
1335 |
//// if (fields[i].getName().equals("modificationDate")
|
1336 |
//// || fields[i].getName().equals("creationDate")
|
1337 |
//// || fields[i].getName().equals("signatureAtStartup")
|
1338 |
//// || fields[i].getName().equals("change")
|
1339 |
//// || Modifier.isStatic(fields[i].getModifiers()))
|
1340 |
//// continue;
|
1341 |
////
|
1342 |
////
|
1343 |
//// String type = fields[i].getType().getName();
|
1344 |
//// if (type.equals("boolean")) {
|
1345 |
//// result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
|
1346 |
//// } else if (type.equals("java.lang.String")) {
|
1347 |
//// Object v = fields[i].get(this);
|
1348 |
//// if (v == null) {
|
1349 |
//// result += 37;
|
1350 |
//// continue;
|
1351 |
//// }
|
1352 |
//// char[] chars = ((String) v).toCharArray();
|
1353 |
//// for (int j = 0; j < chars.length; j++) {
|
1354 |
//// result += 37 + (int) chars[i];
|
1355 |
//// }
|
1356 |
//// } else if (type.equals("byte")) {
|
1357 |
//// result += 37 + (int) fields[i].getByte(this);
|
1358 |
//// } else if (type.equals("char")) {
|
1359 |
//// result += 37 + (int) fields[i].getChar(this);
|
1360 |
//// } else if (type.equals("short")) {
|
1361 |
//// result += 37 + (int) fields[i].getShort(this);
|
1362 |
//// } else if (type.equals("int")) {
|
1363 |
//// result += 37 + fields[i].getInt(this);
|
1364 |
//// } else if (type.equals("long")) {
|
1365 |
//// long f = fields[i].getLong(this) ;
|
1366 |
//// result += 37 + (f ^ (f >>> 32));
|
1367 |
//// } else if (type.equals("float")) {
|
1368 |
//// result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
|
1369 |
//// } else if (type.equals("double")) {
|
1370 |
//// long f = Double.doubleToLongBits(fields[i].getDouble(this));
|
1371 |
//// result += 37 + (f ^ (f >>> 32));
|
1372 |
//// } else {
|
1373 |
////// Object obj = fields[i].get(this);
|
1374 |
////// result += 37 + ((obj != null)? obj.hashCode() : 0);
|
1375 |
//// }
|
1376 |
//// } catch (Exception e) { e.printStackTrace(); }
|
1377 |
////
|
1378 |
//// }
|
1379 |
////
|
1380 |
//// for (int i = 0; i < views.size(); i++) {
|
1381 |
//// ProjectView e = (ProjectView) views.get(i);
|
1382 |
//// result += 37 + e.computeSignature();
|
1383 |
//// }
|
1384 |
////
|
1385 |
//// for (int i = 0; i < tables.size(); i++) {
|
1386 |
//// ProjectTable e = (ProjectTable) tables.get(i);
|
1387 |
//// result += 37 + e.computeSignature();
|
1388 |
//// }
|
1389 |
////
|
1390 |
//// for (int i = 0; i < maps.size(); i++) {
|
1391 |
//// ProjectMap e = (ProjectMap) maps.get(i);
|
1392 |
//// result += 37 + e.computeSignature();
|
1393 |
//// }
|
1394 |
////
|
1395 |
//// for (int i = 0; i < extents.size(); i++) {
|
1396 |
//// ProjectExtent e = (ProjectExtent) extents.get(i);
|
1397 |
//// result += 37 + e.computeSignature();
|
1398 |
//// }
|
1399 |
//
|
1400 |
//
|
1401 |
// return result;
|
1402 |
// }
|
1403 |
|
1404 |
} |