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