root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / DefaultProject.java @ 34288
History | View | Annotate | Download (25.1 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2009 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2004-2009 IVER TI
|
26 |
*
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.app.project; |
30 |
|
31 |
import java.awt.Color; |
32 |
import java.beans.PropertyChangeEvent; |
33 |
import java.beans.PropertyChangeListener; |
34 |
import java.beans.PropertyChangeSupport; |
35 |
import java.io.File; |
36 |
import java.io.FileInputStream; |
37 |
import java.io.FileNotFoundException; |
38 |
import java.io.FileOutputStream; |
39 |
import java.io.InputStream; |
40 |
import java.io.OutputStream; |
41 |
import java.io.Serializable; |
42 |
import java.text.DateFormat; |
43 |
import java.text.MessageFormat; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Collections; |
46 |
import java.util.Date; |
47 |
import java.util.HashMap; |
48 |
import java.util.Iterator; |
49 |
import java.util.List; |
50 |
import java.util.Map; |
51 |
|
52 |
import org.cresques.cts.IProjection; |
53 |
import org.slf4j.Logger; |
54 |
import org.slf4j.LoggerFactory; |
55 |
|
56 |
import org.gvsig.andami.PluginServices; |
57 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
58 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
59 |
import org.gvsig.app.extension.Version; |
60 |
import org.gvsig.app.project.documents.AbstractDocument; |
61 |
import org.gvsig.app.project.documents.Document; |
62 |
import org.gvsig.app.project.documents.exceptions.SaveException; |
63 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
64 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
65 |
import org.gvsig.app.project.documents.table.TableDocument; |
66 |
import org.gvsig.app.project.documents.table.TableManager; |
67 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
68 |
import org.gvsig.app.project.documents.view.ViewManager; |
69 |
import org.gvsig.fmap.dal.DataTypes; |
70 |
import org.gvsig.fmap.mapcontext.MapContext; |
71 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
72 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
73 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
74 |
import org.gvsig.tools.ToolsLocator; |
75 |
import org.gvsig.tools.dynobject.DynField; |
76 |
import org.gvsig.tools.dynobject.DynStruct; |
77 |
import org.gvsig.tools.persistence.PersistenceManager; |
78 |
import org.gvsig.tools.persistence.Persistent; |
79 |
import org.gvsig.tools.persistence.PersistentContext; |
80 |
import org.gvsig.tools.persistence.PersistentState; |
81 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
82 |
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions; |
83 |
import org.gvsig.utils.StringUtilities; |
84 |
|
85 |
/**
|
86 |
* Clase que representa un proyecto de gvSIG
|
87 |
*
|
88 |
* @author 2004-2005 Fernando Gonz?lez Cort?s
|
89 |
* @author 2006-2009 Jose Manuel Vivo
|
90 |
* @author 2005- Vicente Caballero
|
91 |
* @author 2009- Joaquin del Cerro
|
92 |
*
|
93 |
*/
|
94 |
|
95 |
public class DefaultProject implements Serializable, PropertyChangeListener, Project { |
96 |
|
97 |
private Logger LOG = LoggerFactory.getLogger(DefaultProject.class); |
98 |
/**
|
99 |
* @deprecated see ApplicationLocator.getManager().getVersion()
|
100 |
*/
|
101 |
public static String VERSION = Version.format(); |
102 |
|
103 |
|
104 |
/**
|
105 |
*
|
106 |
*/
|
107 |
private static final long serialVersionUID = -4449622027521773178L; |
108 |
|
109 |
//private static final Logger logger = LoggerFactory.getLogger(Project .class);
|
110 |
|
111 |
private static ProjectPreferences preferences = new ProjectPreferences(); |
112 |
|
113 |
/**
|
114 |
* Index used by the generator of unique names of documents.
|
115 |
*/
|
116 |
private Map<String, Integer> nextDocumentIndexByType = new HashMap<String, Integer>(); |
117 |
|
118 |
private PropertyChangeSupport change; |
119 |
|
120 |
private boolean modified = false; |
121 |
|
122 |
private String name = null; |
123 |
|
124 |
private String creationDate = null; |
125 |
|
126 |
private String modificationDate = null; |
127 |
|
128 |
private String owner = null; |
129 |
|
130 |
private String comments = null; |
131 |
|
132 |
private Color selectionColor = null; |
133 |
|
134 |
private List<Document> documents = null; |
135 |
|
136 |
private List<ProjectExtent> extents = null; |
137 |
|
138 |
private IProjection projection;
|
139 |
|
140 |
/**
|
141 |
* Creates a new Project object.
|
142 |
*/
|
143 |
DefaultProject() { |
144 |
this.change = new PropertyChangeSupport(this); |
145 |
this.clean();
|
146 |
} |
147 |
|
148 |
protected void clean() { |
149 |
this.owner = ""; |
150 |
this.comments = ""; |
151 |
this.name = PluginServices.getText(this, "untitled"); |
152 |
this.creationDate = DateFormat.getDateInstance().format(new Date()); |
153 |
this.modificationDate = this.creationDate; |
154 |
|
155 |
this.documents = new ArrayList<Document>(); |
156 |
this.extents = new ArrayList<ProjectExtent>(); |
157 |
|
158 |
this.setSelectionColor(getPreferences().getDefaultSelectionColor());
|
159 |
|
160 |
this.projection = null ; // se inicializa en el getProjection() |
161 |
} |
162 |
|
163 |
|
164 |
public static ProjectPreferences getPreferences() { |
165 |
return preferences;
|
166 |
} |
167 |
|
168 |
public void propertyChange(PropertyChangeEvent evt) { |
169 |
change.firePropertyChange(evt); |
170 |
} |
171 |
|
172 |
public synchronized void addPropertyChangeListener( |
173 |
PropertyChangeListener arg0) {
|
174 |
change.addPropertyChangeListener(arg0); |
175 |
} |
176 |
|
177 |
|
178 |
/**
|
179 |
* Return the creation date of the project
|
180 |
*
|
181 |
* @return
|
182 |
*/
|
183 |
public String getCreationDate() { |
184 |
return creationDate;
|
185 |
} |
186 |
|
187 |
protected void setCreationDate(String creationDate) { |
188 |
this.creationDate = creationDate ;
|
189 |
change.firePropertyChange("setCreationDate", null, null); |
190 |
} |
191 |
|
192 |
|
193 |
/**
|
194 |
* Return the name of the project
|
195 |
*
|
196 |
* @return
|
197 |
*/
|
198 |
public String getName() { |
199 |
return name;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* Set the name of he project.
|
204 |
*
|
205 |
* @param string
|
206 |
*/
|
207 |
public void setName(String name) { |
208 |
this.name = name;
|
209 |
change.firePropertyChange("setName", null, null); |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Return the comments associateds with the project
|
214 |
*
|
215 |
* @return comments
|
216 |
*/
|
217 |
public String getComments() { |
218 |
return comments;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* Set the comments associateds with the project
|
223 |
*
|
224 |
* @param comments as string
|
225 |
*/
|
226 |
public void setComments(String string) { |
227 |
comments = string; |
228 |
change.firePropertyChange("setComments", null, null); |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Retuen the modification date of the project.
|
233 |
*
|
234 |
* @return modification date as string
|
235 |
*/
|
236 |
public String getModificationDate() { |
237 |
return modificationDate;
|
238 |
} |
239 |
|
240 |
protected void setModificationDate(String string) { |
241 |
modificationDate = string; |
242 |
change.firePropertyChange("setModificationDate", null, null); |
243 |
} |
244 |
|
245 |
/**
|
246 |
* Return the author of the project,
|
247 |
*
|
248 |
* @return author as string
|
249 |
*/
|
250 |
public String getOwner() { |
251 |
return owner;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* Sets the author of the project
|
256 |
*
|
257 |
* @param author name as string
|
258 |
*/
|
259 |
public void setOwner(String owner) { |
260 |
this.owner = owner;
|
261 |
change.firePropertyChange("setOwner", null, null); |
262 |
} |
263 |
|
264 |
/**
|
265 |
* Obtiene el color de selecci?n que se usar? en el proyecto
|
266 |
*
|
267 |
* @return
|
268 |
*/
|
269 |
public Color getSelectionColor() { |
270 |
if (selectionColor == null) { |
271 |
selectionColor = getPreferences().getDefaultSelectionColor(); |
272 |
} |
273 |
return selectionColor;
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* Sets the selecction color
|
278 |
*
|
279 |
* @param selection color as string
|
280 |
*/
|
281 |
public void setSelectionColor(String selectionColor) { |
282 |
this.setSelectionColor(StringUtilities.string2Color(selectionColor));
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Sets the selecction color
|
287 |
*
|
288 |
* @param selection color as Color
|
289 |
*/
|
290 |
public void setSelectionColor(Color selectionColor) { |
291 |
this.selectionColor = selectionColor;
|
292 |
MapContext.setSelectionColor(selectionColor); |
293 |
change.firePropertyChange("selectionColor", null, selectionColor); |
294 |
} |
295 |
|
296 |
public IProjection getProjection() {
|
297 |
if (projection == null) { |
298 |
projection = getPreferences().getDefaultProjection(); |
299 |
} |
300 |
return projection;
|
301 |
} |
302 |
|
303 |
public void setProjection(IProjection projection) { |
304 |
this.projection = projection;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Sets the modified state of project.
|
309 |
*
|
310 |
* Can't set to not modified.
|
311 |
*
|
312 |
* @param modified as boolean
|
313 |
*/
|
314 |
public void setModified(boolean modified) { |
315 |
this.modified = modified;
|
316 |
if (modified==false) { |
317 |
List<Document> documents = this.getDocuments(); |
318 |
for( int i=0 ; i<documents.size(); i++ ) { |
319 |
documents.get(i).setModified(false);
|
320 |
} |
321 |
} |
322 |
} |
323 |
|
324 |
public boolean hasChanged() { |
325 |
// we return true if the project is not empty (until we have a better method...)
|
326 |
if ((this.getDocuments().size() != 0) || modified) { |
327 |
return true; |
328 |
} |
329 |
return false; |
330 |
} |
331 |
|
332 |
/**
|
333 |
* Return a list of documents in the project.
|
334 |
*
|
335 |
* @return documents as List of IProjectDocument
|
336 |
*/
|
337 |
public List<Document> getDocuments() { |
338 |
return Collections.unmodifiableList(documents); |
339 |
} |
340 |
|
341 |
/**
|
342 |
* Return a list with all documents of especified type.
|
343 |
*
|
344 |
* @param type of document
|
345 |
*
|
346 |
* @return List of IProjectDocument
|
347 |
*/
|
348 |
public List<Document> getDocuments(String type) { |
349 |
List<Document> docs = new ArrayList<Document>(); |
350 |
if( type != null ) { |
351 |
for (Document document : this.documents) { |
352 |
if (type.equalsIgnoreCase(document.getTypeName())) {
|
353 |
docs.add(document); |
354 |
} |
355 |
} |
356 |
} |
357 |
return Collections.unmodifiableList(docs); |
358 |
} |
359 |
|
360 |
|
361 |
/**
|
362 |
* Adds a document to the project
|
363 |
*
|
364 |
* @param document as IProjectDocument
|
365 |
*/
|
366 |
public void add(Document document) { |
367 |
documents.add(document); |
368 |
document.addPropertyChangeListener(this);
|
369 |
document.setProject(this);
|
370 |
document.setName( |
371 |
this.getUniqueNameForDocument(
|
372 |
document.getTypeName(), |
373 |
document.getName() |
374 |
) |
375 |
); |
376 |
document.afterAdd(); |
377 |
this.setModified(true); |
378 |
change.firePropertyChange("addDocument",null, null); |
379 |
} |
380 |
|
381 |
/**
|
382 |
* Remove a document of the project
|
383 |
*
|
384 |
* @param document as IProjectDocument
|
385 |
*/
|
386 |
public void remove(Document doc) { |
387 |
documents.remove(doc); |
388 |
this.setModified(true); |
389 |
change.firePropertyChange("delDocument", null, null); |
390 |
doc.afterRemove(); |
391 |
} |
392 |
|
393 |
public Iterator<Document> iterator() { |
394 |
return documents.iterator();
|
395 |
} |
396 |
|
397 |
public boolean isEmpty() { |
398 |
return documents.isEmpty();
|
399 |
} |
400 |
|
401 |
/**
|
402 |
* Return the FeatureTableDocument associated with a layer
|
403 |
*
|
404 |
* @param layer
|
405 |
*
|
406 |
* @return FeatureTableDocument associated with the layer.
|
407 |
*/
|
408 |
public TableDocument getTable(FLyrVect layer) {
|
409 |
List<Document> tables = getDocuments(TableManager.TYPENAME); |
410 |
for (int i = 0; i < tables.size(); i++) { |
411 |
TableDocument table = (TableDocument) tables.get(i); |
412 |
if ( table.getStore().equals(layer.getFeatureStore()) ){
|
413 |
return table;
|
414 |
} |
415 |
} |
416 |
|
417 |
return null; |
418 |
} |
419 |
|
420 |
/**
|
421 |
* Return the view that contains the especified layer.
|
422 |
*
|
423 |
* @param layer
|
424 |
*
|
425 |
* @return name of the view that contains the layer
|
426 |
*
|
427 |
* @throws RuntimeException
|
428 |
* Si la capa que se pasa como par?metro no se encuentra en
|
429 |
* ninguna vista
|
430 |
*/
|
431 |
public String getViewName(FLayer layer) { |
432 |
List<Document> views = getDocuments(ViewManager.TYPENAME); |
433 |
for (int v = 0; v < views.size(); v++) { |
434 |
DefaultViewDocument pView = (DefaultViewDocument) views.get(v); |
435 |
FLayers layers = pView.getMapContext().getLayers(); |
436 |
if (isView(layers, layer)) {
|
437 |
return pView.getName();
|
438 |
} |
439 |
} |
440 |
|
441 |
throw new RuntimeException(MessageFormat.format("The layer '{1}' is not in a view", layer.getName())); |
442 |
} |
443 |
|
444 |
private boolean isView(FLayers layers, FLayer layer) { |
445 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
446 |
if (layers.getLayer(i) instanceof FLayers) { |
447 |
if (isView((FLayers) layers.getLayer(i), layer)){
|
448 |
return true; |
449 |
} |
450 |
} |
451 |
if (layers.getLayer(i) == layer) {
|
452 |
return true; |
453 |
} |
454 |
} |
455 |
return false; |
456 |
} |
457 |
|
458 |
public void addExtent(ProjectExtent arg1) { |
459 |
extents.add(arg1); |
460 |
change.firePropertyChange("addExtent", null, null); |
461 |
} |
462 |
|
463 |
public ProjectExtent removeExtent(int arg0) { |
464 |
change.firePropertyChange("delExtent", null, null); |
465 |
return extents.remove(arg0);
|
466 |
} |
467 |
|
468 |
public ProjectExtent[] getExtents() { |
469 |
return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]); |
470 |
} |
471 |
|
472 |
/**
|
473 |
* Obtiene un documento a partir de su nombre y el nombre de registro en el
|
474 |
* pointExtension, este ?ltimo se puede obtener del
|
475 |
* Project****Factory.registerName.
|
476 |
*
|
477 |
* @param name
|
478 |
* Nombre del documento
|
479 |
* @param type
|
480 |
* nombre de registro en el extensionPoint
|
481 |
*
|
482 |
* @return Documento
|
483 |
*/
|
484 |
public Document getDocument(String name, String type) { |
485 |
if( type != null ) { |
486 |
for (int i = 0; i < documents.size(); i++) { |
487 |
Document document = documents.get(i);
|
488 |
if (type.equalsIgnoreCase(document.getTypeName()) && name.equalsIgnoreCase(document.getName())) {
|
489 |
return document;
|
490 |
} |
491 |
} |
492 |
} |
493 |
return null; |
494 |
} |
495 |
|
496 |
public String getUniqueNameForDocument(String type, String name) { |
497 |
Document document = getDocument(name, type);
|
498 |
if( document == null ) { |
499 |
return name;
|
500 |
} |
501 |
|
502 |
String newName = null; |
503 |
int num = this.getNextDocumentIndex(type); |
504 |
while( document != null ) { |
505 |
newName = name + " - " + num++;
|
506 |
document = getDocument(newName, type); |
507 |
} |
508 |
this.setNextDocumentIndex(type, num);
|
509 |
return newName;
|
510 |
} |
511 |
|
512 |
private int getNextDocumentIndex(String type) { |
513 |
if( nextDocumentIndexByType.get(type) == null ) { |
514 |
nextDocumentIndexByType.put(type, new Integer(1)); |
515 |
return 1; |
516 |
} |
517 |
return nextDocumentIndexByType.get(type).intValue();
|
518 |
} |
519 |
|
520 |
private void setNextDocumentIndex(String type, int newIndex) { |
521 |
if( nextDocumentIndexByType.get(type) == null ) { |
522 |
nextDocumentIndexByType.put(type, new Integer(newIndex)); |
523 |
} else {
|
524 |
nextDocumentIndexByType.put(type, new Integer(newIndex)); |
525 |
} |
526 |
} |
527 |
|
528 |
public void saveState(File out) throws PersistenceException { |
529 |
FileOutputStream fout;
|
530 |
try {
|
531 |
fout = new FileOutputStream(out); |
532 |
saveState(fout, new File(out.getParent())); |
533 |
} catch (FileNotFoundException e) { |
534 |
throw new PersistenceException(e); |
535 |
} |
536 |
} |
537 |
|
538 |
public void saveState(OutputStream out) throws PersistenceException { |
539 |
saveState(out, null);
|
540 |
} |
541 |
|
542 |
public void saveState(OutputStream out, File rootFolder) throws PersistenceException { |
543 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
544 |
PersistentState state=null;
|
545 |
state = manager.getState(this,true); |
546 |
try {
|
547 |
if( rootFolder!=null ) { |
548 |
relativizeFiles(state, rootFolder); |
549 |
} |
550 |
} catch(Exception ex) { |
551 |
state.getContext().addError(ex); |
552 |
} |
553 |
manager.saveState( state, out); |
554 |
if( state.getContext().getErrors() != null ) { |
555 |
throw state.getContext().getErrors();
|
556 |
} |
557 |
} |
558 |
|
559 |
private void relativizeFiles(PersistentState state, File rootFolder) { |
560 |
PersistentContext context = state.getContext(); |
561 |
|
562 |
@SuppressWarnings("unchecked") |
563 |
Iterator<PersistentState> statesIterator = context.iterator();
|
564 |
while( statesIterator.hasNext() ) {
|
565 |
PersistentState aState = statesIterator.next(); |
566 |
DynStruct definition = aState.getDefinition(); |
567 |
DynField[] fields = definition.getDynFields();
|
568 |
for (DynField field : fields) {
|
569 |
if( field.getType() == DataTypes.FILE ||
|
570 |
field.getType() == DataTypes.FOLDER ) { |
571 |
try {
|
572 |
File value = aState.getFile(field.getName());
|
573 |
value = relativizeFile(value, rootFolder); |
574 |
aState.set(field.getName(), value ); |
575 |
} catch (PersistenceException e) {
|
576 |
LOG.warn("Can't relativice field '"+field.getName()+"' for class '"+definition.getName()+"'.",e); |
577 |
} |
578 |
} |
579 |
} |
580 |
} |
581 |
} |
582 |
|
583 |
private File relativizeFile(File file, File rootFolder) { |
584 |
// TODO: falta por implementar.
|
585 |
return file;
|
586 |
} |
587 |
|
588 |
public void loadState(InputStream in) { |
589 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
590 |
try {
|
591 |
PersistentState state = manager.loadState(in); |
592 |
this.loadFromState(state);
|
593 |
} catch (PersistenceException e) {
|
594 |
// TODO Auto-generated catch block
|
595 |
e.printStackTrace(); |
596 |
} |
597 |
|
598 |
} |
599 |
|
600 |
public void loadState(File in) { |
601 |
FileInputStream fin;
|
602 |
try {
|
603 |
fin = new FileInputStream(in); |
604 |
loadState(fin); |
605 |
} catch (FileNotFoundException e) { |
606 |
// TODO Auto-generated catch block
|
607 |
e.printStackTrace(); |
608 |
} |
609 |
} |
610 |
|
611 |
@SuppressWarnings("unchecked") |
612 |
public void loadFromState(PersistentState state) |
613 |
throws PersistenceException {
|
614 |
this.clean();
|
615 |
|
616 |
this.setComments( state.getString("comments") ); |
617 |
this.setCreationDate( state.getString("creationDate") ); |
618 |
this.setModificationDate( state.getString("modificationDate") ); |
619 |
this.setName( state.getString("name") ); |
620 |
this.setOwner( state.getString("owner") ); |
621 |
this.setSelectionColor( (Color)state.get("selectionColor") ); |
622 |
this.setProjection( (IProjection) state.get("projection") ); |
623 |
|
624 |
List<ProjectExtent> extents = (List<ProjectExtent>) state.get("extents"); |
625 |
for( int i=0; i<extents.size(); i++) { |
626 |
this.addExtent( extents.get(i) );
|
627 |
} |
628 |
|
629 |
List<AbstractDocument> documents = (List<AbstractDocument>) state.get("documents"); |
630 |
for( int i=0; i<documents.size(); i++) { |
631 |
this.add( documents.get(i) );
|
632 |
} |
633 |
|
634 |
} |
635 |
|
636 |
public void saveToState(PersistentState state) throws PersistenceException { |
637 |
state.set("version", VERSION);
|
638 |
state.set("comments", getComments());
|
639 |
state.set("creationDate", this.getCreationDate()); |
640 |
|
641 |
state.set("modificationDate", this.getModificationDate()); |
642 |
state.set("name", this.getName()); |
643 |
state.set("owner", this.getOwner()); |
644 |
state.set("selectionColor", this.getSelectionColor()); |
645 |
|
646 |
state.set("projection", this.getProjection()); |
647 |
|
648 |
state.set("extents", this.extents); |
649 |
state.set("documents", this.getDocuments()); |
650 |
|
651 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
652 |
List<PersistentState> windowsStates = new ArrayList<PersistentState>(); |
653 |
IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows();
|
654 |
for (int i = windows.length - 1; i >= 0; i--) { |
655 |
IWindow window = windows[i]; |
656 |
if( window instanceof Persistent ) { |
657 |
try {
|
658 |
windowsStates.add( persistenceManager.getState(window)); |
659 |
} catch (PersistenceValidateExceptions e) {
|
660 |
throw new PersistenceException(e); |
661 |
} |
662 |
} |
663 |
} |
664 |
LOG.warn("DefaultProject::saveToState, falta por persistir 'windowsInformation'");
|
665 |
//state.set("windowsInformation", windowsStates);
|
666 |
|
667 |
} |
668 |
|
669 |
|
670 |
public static void registerPersistent() { |
671 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
672 |
DynStruct definition = manager.addDefinition( |
673 |
DefaultProject.class, |
674 |
"Project",
|
675 |
"Project Persistence definition",
|
676 |
null,
|
677 |
null
|
678 |
); |
679 |
definition.addDynFieldString("version").setMandatory(true); |
680 |
definition.addDynFieldString("comments").setMandatory(true); |
681 |
definition.addDynFieldString("creationDate").setMandatory(true); |
682 |
definition.addDynFieldString("modificationDate").setMandatory(true); |
683 |
definition.addDynFieldString("name").setMandatory(true); |
684 |
definition.addDynFieldString("owner").setMandatory(true); |
685 |
|
686 |
definition.addDynFieldObject("selectionColor").setClassOfValue(Color.class).setMandatory(true); |
687 |
definition.addDynFieldObject("projection").setClassOfValue(IProjection.class).setMandatory(true); |
688 |
|
689 |
definition.addDynFieldList("extents").setClassOfItems(ProjectExtent.class).setMandatory(true); |
690 |
|
691 |
definition.addDynFieldList("documents").setClassOfItems(Document.class).setMandatory(true); |
692 |
|
693 |
AbstractDocument.registerPersistent();
|
694 |
} |
695 |
|
696 |
/**
|
697 |
* @deprecated use getPreferences().setDefaultSelectionColor()
|
698 |
*/
|
699 |
public static void setDefaultSelectionColor(Color color) { |
700 |
getPreferences().setDefaultSelectionColor(color); |
701 |
} |
702 |
|
703 |
/**
|
704 |
* @deprecated use getPreferences().getDefaultSelectionColor()
|
705 |
*/
|
706 |
|
707 |
public static Color getDefaultSelectionColor() { |
708 |
return getPreferences().getDefaultSelectionColor();
|
709 |
} |
710 |
|
711 |
/**
|
712 |
* @deprecated use getPreferences().getDefaultMapUnits()
|
713 |
*/
|
714 |
public static int getDefaultMapUnits() { |
715 |
return getPreferences().getDefaultMapUnits();
|
716 |
} |
717 |
|
718 |
/**
|
719 |
* @deprecated use getPreferences().getDefaultDistanceUnits()
|
720 |
*/
|
721 |
public static int getDefaultDistanceUnits() { |
722 |
return getPreferences().getDefaultDistanceUnits();
|
723 |
} |
724 |
|
725 |
/**
|
726 |
* @deprecated use getPreferences().getDefaultDistanceArea()
|
727 |
*/
|
728 |
public static int getDefaultDistanceArea() { |
729 |
return getPreferences().getDefaultDistanceArea();
|
730 |
} |
731 |
|
732 |
/**
|
733 |
* @deprecated use getPreferences().setDefaultMapUnits()
|
734 |
*/
|
735 |
public static void setDefaultMapUnits(int mapUnits) { |
736 |
getPreferences().setDefaultMapUnits(mapUnits); |
737 |
} |
738 |
|
739 |
/**
|
740 |
* @deprecated use getPreferences().setDefaultDistanceUnits()
|
741 |
*/
|
742 |
public static void setDefaultDistanceUnits(int distanceUnits) { |
743 |
getPreferences().setDefaultDistanceUnits(distanceUnits); |
744 |
} |
745 |
|
746 |
/**
|
747 |
* @deprecated use getPreferences().setDefaultDistanceArea()
|
748 |
*/
|
749 |
public static void setDefaultDistanceArea(int distanceArea) { |
750 |
getPreferences().setDefaultDistanceArea(distanceArea); |
751 |
} |
752 |
|
753 |
/**
|
754 |
* @deprecated use getPreferences().setDefaultProjection()
|
755 |
*/
|
756 |
public static void setDefaultProjection(IProjection defaultProjection) { |
757 |
getPreferences().setDefaultProjection(defaultProjection); |
758 |
} |
759 |
|
760 |
/**
|
761 |
* @deprecated use getPreferences().getDefaultProjection()
|
762 |
*/
|
763 |
public static IProjection getDefaultProjection() { |
764 |
return getPreferences().getDefaultProjection();
|
765 |
} |
766 |
|
767 |
/**
|
768 |
* @deprecated see {@link #setSelectionColor(String)}, to be remove in gvSIG 2.1.0
|
769 |
*/
|
770 |
public void setColor(String color) { |
771 |
this.setSelectionColor(StringUtilities.string2Color(color));
|
772 |
} |
773 |
|
774 |
/**
|
775 |
* Return the selection color
|
776 |
*
|
777 |
* @return selection color as string
|
778 |
* @deprecated use {@link #getSelectionColor()}
|
779 |
*/
|
780 |
public String getColor() { |
781 |
return StringUtilities.color2String(selectionColor);
|
782 |
} |
783 |
|
784 |
|
785 |
/**
|
786 |
* Devuelve a partir del nombre la tabla asociada.
|
787 |
*
|
788 |
* @param name
|
789 |
* Nombre.
|
790 |
* @deprecated utilizar getProjectDocumentByName(...);
|
791 |
* @return ProjectTable de la tabla asociada.
|
792 |
*/
|
793 |
public TableDocument getTable(String name) { |
794 |
return (TableDocument) this.getDocument(name,TableManager.TYPENAME); |
795 |
} |
796 |
|
797 |
/**
|
798 |
* Return the list of maps of the project
|
799 |
*
|
800 |
* @return tables as ArrayList of IProjectDocument
|
801 |
*
|
802 |
* @deprecated see {@link #getDocumentsByType(String)}
|
803 |
*/
|
804 |
public List<Document> getMaps() { |
805 |
return getDocuments(LayoutManager.TYPENAME); |
806 |
} |
807 |
|
808 |
/**
|
809 |
* Add a {@link LayoutDocument} to the project
|
810 |
*
|
811 |
* @deprecated see {@link #add(Document)}
|
812 |
*/
|
813 |
public void addMap(LayoutDocument m) { |
814 |
add(m); |
815 |
} |
816 |
|
817 |
/**
|
818 |
* Remove a map of the project
|
819 |
*
|
820 |
* @param index of the map as integer
|
821 |
*
|
822 |
* @deprecated see {@link #remove(Document)}
|
823 |
*/
|
824 |
public void delMap(int i) { |
825 |
List<Document> list = getDocuments(LayoutManager.TYPENAME); |
826 |
remove(list.get(i)); |
827 |
} |
828 |
|
829 |
|
830 |
/**
|
831 |
* Return the list of tables of the project
|
832 |
*
|
833 |
* @return tables as ArrayList of ProjectDocument
|
834 |
*
|
835 |
* @deprecated see {@link #getDocumentsByType(String)}
|
836 |
*/
|
837 |
public List<Document> getTables() { |
838 |
return getDocuments(TableManager.TYPENAME);
|
839 |
} |
840 |
|
841 |
/**
|
842 |
* Add a {@link TableDocument } to the project
|
843 |
*
|
844 |
* @deprecated see {@link #add(AbstractDocument)}
|
845 |
*/
|
846 |
public void addTable(TableDocument t) { |
847 |
add(t); |
848 |
} |
849 |
|
850 |
/**
|
851 |
* Remove a {@link TableDocument } of the project
|
852 |
*
|
853 |
* @param index of the table as integer
|
854 |
*
|
855 |
* @deprecated see {@link #remove(AbstractDocument)}
|
856 |
*/
|
857 |
public void delTable(int i) { |
858 |
List<Document> list = getDocuments(TableManager.TYPENAME); |
859 |
remove(list.get(i)); |
860 |
} |
861 |
|
862 |
/**
|
863 |
* Return the list of views of the project
|
864 |
*
|
865 |
* @return views as ArrayList of ProjectDocument
|
866 |
*
|
867 |
* @deprecated see {@link #getDocumentsByType(String)}
|
868 |
*/
|
869 |
public List<Document> getViews() { |
870 |
return getDocuments(ViewManager.TYPENAME);
|
871 |
} |
872 |
|
873 |
/**
|
874 |
* Add a view to the project
|
875 |
*
|
876 |
* @deprecated see {@link #add(AbstractDocument)}
|
877 |
*/
|
878 |
public void addView(DefaultViewDocument v) { |
879 |
add(v); |
880 |
} |
881 |
|
882 |
/**
|
883 |
* Remove a view of the project
|
884 |
*
|
885 |
* @param index of the view as integer
|
886 |
*
|
887 |
* @deprecated see {@link #remove(AbstractDocument)}
|
888 |
*/
|
889 |
public void delView(int i) { |
890 |
List<Document> list = getDocuments(ViewManager.TYPENAME); |
891 |
remove(list.get(i)); |
892 |
} |
893 |
|
894 |
/**
|
895 |
* @deprecated see {@link #getDocument(String, String)}
|
896 |
*/
|
897 |
public Document getProjectDocumentByName(String name, String type) { |
898 |
return this.getDocument(name, type); |
899 |
} |
900 |
|
901 |
/**
|
902 |
* @deprecated see {@link #getDocuments(String)}
|
903 |
*/
|
904 |
public List<Document> getDocumentsByType(String type) { |
905 |
return this.getDocuments(type); |
906 |
} |
907 |
|
908 |
/**
|
909 |
* @deprecated aun por decidir que API darle al copy/paste
|
910 |
*/
|
911 |
public String exportToXML(AbstractDocument[] selectedItems) throws SaveException { |
912 |
// FIXME jjdc:hay que decirdir que API darle al copy/paste
|
913 |
throw new UnsupportedOperationException("This method is not supported"); |
914 |
} |
915 |
|
916 |
/**
|
917 |
* @deprecated aun por decidir que API darle al copy/paste
|
918 |
*/
|
919 |
public void importFromXML(String sourceString, String docType) { |
920 |
// FIXME jjdc:hay que decirdir que API darle al copy/paste
|
921 |
throw new UnsupportedOperationException("This method is not supported"); |
922 |
} |
923 |
|
924 |
/**
|
925 |
* @deprecated aun por decidir que API darle al copy/paste
|
926 |
*/
|
927 |
public boolean isValidXMLForImport(String sourceString, String docType) { |
928 |
// FIXME jjdc:hay que decirdir que API darle al copy/paste
|
929 |
throw new UnsupportedOperationException("This method is not supported"); |
930 |
} |
931 |
|
932 |
public boolean canImportDocuments(String data, String doctype) { |
933 |
// TODO Auto-generated method stub
|
934 |
return false; |
935 |
} |
936 |
|
937 |
public String exportDocumentsAsText(List<Document> documents) { |
938 |
// TODO Auto-generated method stub
|
939 |
return null; |
940 |
} |
941 |
|
942 |
public void importDocuments(String data, String doctype) { |
943 |
// TODO Auto-generated method stub
|
944 |
|
945 |
} |
946 |
|
947 |
public Document getActiveDocument() { |
948 |
try {
|
949 |
SingletonWindow window = (SingletonWindow) PluginServices.getMDIManager().getActiveWindow(); |
950 |
Document doc = (Document) window.getWindowModel(); |
951 |
return doc;
|
952 |
} catch(Exception ex) { |
953 |
return null; |
954 |
} |
955 |
} |
956 |
} |