Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / DefaultProject.java @ 32880

History | View | Annotate | Download (23.8 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.DefaultViewDocument;
65
import org.gvsig.app.project.documents.view.ViewManager;
66
import org.gvsig.fmap.mapcontext.MapContext;
67
import org.gvsig.fmap.mapcontext.layers.FLayer;
68
import org.gvsig.fmap.mapcontext.layers.FLayers;
69
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
70
import org.gvsig.tools.ToolsLocator;
71
import org.gvsig.tools.dynobject.DynStruct;
72
import org.gvsig.tools.persistence.PersistenceManager;
73
import org.gvsig.tools.persistence.Persistent;
74
import org.gvsig.tools.persistence.PersistentState;
75
import org.gvsig.tools.persistence.exception.PersistenceClassNotRegistered;
76
import org.gvsig.tools.persistence.exception.PersistenceException;
77
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException;
78
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
79
import org.gvsig.utils.StringUtilities;
80

    
81

    
82
/**
83
 * Clase que representa un proyecto de gvSIG
84
 *
85
 * @author 2004-2005 Fernando Gonz?lez Cort?s
86
 * @author 2006-2009 Jose Manuel Vivo
87
 * @author 2005-         Vicente Caballero
88
 * @author 2009-         Joaquin del Cerro
89
 * 
90
 */
91

    
92
public class DefaultProject implements Serializable, PropertyChangeListener, Project {
93

    
94
        /**
95
         * @deprecated see ApplicationLocator.getManager().getVersion()
96
         */
97
        public static String VERSION = Version.format();
98

    
99
        /**
100
         * 
101
         */
102
        private static final long serialVersionUID = -4449622027521773178L;
103

    
104
        //private static final  Logger logger = LoggerFactory.getLogger(Project .class);
105

    
106
        private static ProjectPreferences preferences = new ProjectPreferences();
107

    
108
        /**
109
         * Index used by the generator of unique names of documents.
110
         */
111
        private Map<String, Integer> nextDocumentIndexByType = new HashMap<String, Integer>();
112

    
113
        private PropertyChangeSupport change;
114

    
115
        private boolean modified = false;
116

    
117
        private String name = null;
118

    
119
        private String creationDate = null;
120

    
121
        private String modificationDate = null;
122

    
123
        private String owner = null;
124

    
125
        private String comments = null;
126

    
127
        private Color selectionColor = null;
128

    
129
        private List<Document> documents = null;
130

    
131
        private List<ProjectExtent> extents = null;
132

    
133
        private IProjection projection;
134

    
135
        /**
136
         * Creates a new Project object.
137
         */
138
        DefaultProject() {
139
                this.change = new PropertyChangeSupport(this);
140
                this.clean();
141
        }
142

    
143
        protected void clean() {
144
                this.owner = "";
145
                this.comments = "";
146
                this.name = PluginServices.getText(this, "untitled");
147
                this.creationDate = DateFormat.getDateInstance().format(new Date());
148
                this.modificationDate = this.creationDate;
149

    
150
                this.documents = new ArrayList<Document>();
151
                this.extents = new ArrayList<ProjectExtent>();
152

    
153
                this.setSelectionColor(getPreferences().getDefaultSelectionColor());
154
        
155
                this.projection = null ; // se inicializa en el getProjection()
156
        }
157
        
158
        
159
        public static ProjectPreferences getPreferences() {
160
                return preferences;
161
        }
162

    
163
        public void propertyChange(PropertyChangeEvent evt) {
164
                change.firePropertyChange(evt);
165
        }
166

    
167
        public synchronized void addPropertyChangeListener(
168
                        PropertyChangeListener arg0) {
169
                change.addPropertyChangeListener(arg0);
170
        }
171

    
172
        
173
        /**
174
         * Return the creation date of the project
175
         *
176
         * @return
177
         */
178
        public String getCreationDate() {
179
                return creationDate;
180
        }
181

    
182
        protected void setCreationDate(String creationDate) {
183
                this.creationDate = creationDate ;
184
                change.firePropertyChange("setCreationDate", null, null);
185
        }
186

    
187

    
188
        /**
189
         * Return the name of the project
190
         *
191
         * @return
192
         */
193
        public String getName() {
194
                return name;
195
        }
196

    
197
        /**
198
         * Set the name of he project.
199
         *
200
         * @param string
201
         */
202
        public void setName(String name) {
203
                this.name = name;
204
                change.firePropertyChange("setName", null, null);
205
        }
206

    
207
        /**
208
         * Return the comments associateds with the project
209
         *
210
         * @return comments
211
         */
212
        public String getComments() {
213
                return comments;
214
        }
215

    
216
        /**
217
         * Set the comments associateds with the project
218
         *
219
         * @param comments as string
220
         */
221
        public void setComments(String string) {
222
                comments = string;
223
                change.firePropertyChange("setComments", null, null);
224
        }
225

    
226
        /**
227
         * Retuen the modification date of the project.
228
         *
229
         * @return modification date as string
230
         */
231
        public String getModificationDate() {
232
                return modificationDate;
233
        }
234

    
235
        protected void setModificationDate(String string) {
236
                modificationDate = string;
237
                change.firePropertyChange("setModificationDate", null, null);
238
        }
239

    
240
        /**
241
         * Return the author of the project,
242
         *
243
         * @return author as string
244
         */
245
        public String getOwner() {
246
                return owner;
247
        }
248

    
249
        /**
250
         * Sets the author of the project
251
         *
252
         * @param author name as string
253
         */
254
        public void setOwner(String owner) {
255
                this.owner = owner;
256
                change.firePropertyChange("setOwner", null, null);
257
        }
258

    
259
        /**
260
         * Obtiene el color de selecci?n que se usar? en el proyecto
261
         *
262
         * @return
263
         */
264
        public Color getSelectionColor() {
265
                if (selectionColor == null) {
266
                        selectionColor = getPreferences().getDefaultSelectionColor();
267
                }
268
                return selectionColor;
269
        }
270

    
271
        /**
272
         * Sets the selecction color
273
         *
274
         * @param selection color as string
275
         */
276
        public void setSelectionColor(String selectionColor) {
277
                this.setSelectionColor(StringUtilities.string2Color(selectionColor));
278
        }
279

    
280
        /**
281
         * Sets the selecction color
282
         *
283
         * @param selection color as Color
284
         */
285
        public void setSelectionColor(Color selectionColor) {
286
                this.selectionColor = selectionColor;
287
                MapContext.setSelectionColor(selectionColor);
288
                change.firePropertyChange("selectionColor", null, selectionColor);
289
        }
290

    
291
        public IProjection getProjection() {
292
                if (projection == null) {
293
                        projection =  getPreferences().getDefaultProjection();
294
                }
295
                return projection;
296
        }
297

    
298
        public void setProjection(IProjection projection) {
299
                this.projection = projection;
300
        }
301

    
302
        /**
303
         * Sets the modified state of project.
304
         * 
305
         * Can't set to not modified.
306
         *
307
         * @param modified as boolean
308
         */
309
        public void setModified(boolean modified) {
310
                this.modified = modified;
311
                if (modified==false) {
312
                        List<Document> documents = this.getDocuments();
313
                        for( int i=0 ; i<documents.size(); i++ ) {
314
                                documents.get(i).setModified(false);
315
                        }
316
                }
317
        }
318

    
319
         public boolean hasChanged() {
320
                 // we return true if the project is not empty (until we have a better method...)
321
                 if ((this.getDocuments().size() != 0) || modified) {
322
                         return true;
323
                 }
324
                 return false;
325
         }
326
        
327
                /**
328
                 * Return a list of documents in the project.
329
                 *
330
                 * @return documents as List of IProjectDocument
331
                 */
332
                public List<Document> getDocuments() {
333
                        return Collections.unmodifiableList(documents);
334
                }
335

    
336
        /**
337
         * Return a list with all documents of especified type.
338
         *
339
         * @param type of document
340
         *
341
         * @return List of IProjectDocument
342
         */
343
                public List<Document> getDocuments(String type) {
344
                        List<Document> docs = new ArrayList<Document>();
345
                        if( type != null ) {
346
                                for (Document document : this.documents) {
347
                                        if (type.equalsIgnoreCase(document.getTypeName())) {
348
                                                docs.add(document);
349
                                        }
350
                                }
351
                        }
352
                        return Collections.unmodifiableList(docs);
353
                }
354

    
355

    
356
        /**
357
         * Adds a document to the project
358
         *
359
         * @param document as IProjectDocument
360
         */
361
        public void add(Document document) {
362
                documents.add(document);
363
                document.addPropertyChangeListener(this);
364
                document.setProject(this);
365
        document.setName( 
366
                        this.getUniqueNameForDocument(
367
                                document.getTypeName(), 
368
                                document.getName()
369
                        )
370
        );
371
        document.afterAdd();
372
                this.setModified(true);
373
                change.firePropertyChange("addDocument",null, null);
374
        }
375

    
376
        /**
377
         * Remove a document of the project
378
         *
379
         * @param document as IProjectDocument
380
         */
381
        public void remove(Document doc) {
382
                documents.remove(doc);
383
                this.setModified(true);
384
                change.firePropertyChange("delDocument", null, null);
385
                doc.afterRemove();
386
        }
387

    
388
        public Iterator<Document> iterator() {
389
                return documents.iterator();
390
        }
391

    
392
        public boolean isEmpty() {
393
                return documents.isEmpty();
394
        }
395
                
396
        /**
397
         * Return the FeatureTableDocument associated with a layer
398
         *
399
         * @param layer
400
         *
401
         * @return FeatureTableDocument associated with the layer.
402
         */
403
        public TableDocument getTable(FLyrVect layer) {
404
                List<Document> tables = getDocuments(TableManager.TYPENAME);
405
                for (int i = 0; i < tables.size(); i++) {
406
                        TableDocument table = (TableDocument) tables.get(i);
407
                                if ( table.getStore().equals(layer.getFeatureStore())  ){
408
                                        return table;
409
                                }
410
                }
411

    
412
                return null;
413
        }
414

    
415
        /**
416
         * Return the view that contains the especified layer.
417
         *
418
         * @param layer
419
         *
420
         * @return name of the view that contains the layer
421
         *
422
         * @throws RuntimeException 
423
         *             Si la capa que se pasa como par?metro no se encuentra en
424
         *             ninguna vista
425
         */
426
        public String getViewName(FLayer layer) {
427
                List<Document> views = getDocuments(ViewManager.TYPENAME);
428
                for (int v = 0; v < views.size(); v++) {
429
                        DefaultViewDocument pView = (DefaultViewDocument) views.get(v);
430
                        FLayers layers = pView.getMapContext().getLayers();
431
                        if (isView(layers, layer)) {
432
                                return pView.getName();
433
                        }
434
                }
435

    
436
                throw new RuntimeException(MessageFormat.format("The layer '{1}' is not in a view",  layer.getName()));
437
        }
438

    
439
        private boolean isView(FLayers layers, FLayer layer) {
440
                for (int i = 0; i < layers.getLayersCount(); i++) {
441
                        if (layers.getLayer(i) instanceof FLayers) {
442
                                if (isView((FLayers) layers.getLayer(i), layer)){
443
                                        return true;
444
                                }
445
                        }
446
                        if (layers.getLayer(i) == layer) {
447
                                return true;
448
                        }
449
                }
450
                return false;
451
        }
452

    
453
        public void addExtent(ProjectExtent arg1) {
454
                extents.add(arg1);
455
                change.firePropertyChange("addExtent", null, null);
456
        }
457

    
458
        public ProjectExtent removeExtent(int arg0) {
459
                change.firePropertyChange("delExtent", null, null);
460
                return extents.remove(arg0);
461
        }
462

    
463
        public ProjectExtent[] getExtents() {
464
                return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]);
465
        }
466

    
467
        /**
468
         * Obtiene un documento a partir de su nombre y el nombre de registro en el
469
         * pointExtension, este ?ltimo se puede obtener del
470
         * Project****Factory.registerName.
471
         *
472
         * @param name
473
         *            Nombre del documento
474
         * @param type
475
         *            nombre de registro en el extensionPoint
476
         *
477
         * @return Documento
478
         */
479
        public Document getDocument(String name, String type) {
480
                if( type != null ) {
481
                        for (int i = 0; i < documents.size(); i++) {
482
                                Document document = documents.get(i);
483
                                if (type.equalsIgnoreCase(document.getTypeName()) && name.equalsIgnoreCase(document.getName())) {
484
                                        return document;
485
                                }
486
                        }
487
                }
488
                return null;
489
        }
490

    
491
        public String getUniqueNameForDocument(String type, String name) {
492
                Document document = getDocument(name, type);
493
                if( document == null ) {
494
                        return name;
495
                }
496
                
497
        String newName = null;
498
        int num = this.getNextDocumentIndex(type);
499
        while( document != null ) {
500
            newName = name + " - " + num++;
501
                    document = getDocument(newName, type);                
502
        } 
503
        this.setNextDocumentIndex(type, num);
504
        return newName;
505
        }
506
        
507
        private int getNextDocumentIndex(String type) {
508
                if( nextDocumentIndexByType.get(type) == null ) {
509
                        nextDocumentIndexByType.put(type, new Integer(1));
510
                        return 1;
511
                }
512
                return nextDocumentIndexByType.get(type).intValue();
513
        }
514

    
515
        private void setNextDocumentIndex(String type, int newIndex) {
516
                if( nextDocumentIndexByType.get(type) == null ) {
517
                        nextDocumentIndexByType.put(type, new Integer(newIndex));
518
                } else {
519
                        nextDocumentIndexByType.put(type, new Integer(newIndex));
520
                }
521
        }
522

    
523
        public void saveState(OutputStream out) {
524
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
525
                try {
526
                        manager.saveState( manager.getState(this), out);
527
                } catch (PersistenceTypeNotSupportedException e) {
528
                        // TODO Auto-generated catch block
529
                        e.printStackTrace();
530
                } catch (PersistenceClassNotRegistered e) {
531
                        // TODO Auto-generated catch block
532
                        e.printStackTrace();
533
                } catch (PersistenceException e) {
534
                        // TODO Auto-generated catch block
535
                        e.printStackTrace();
536
                } catch (PersistenceValidateExceptions e) {
537
                        // TODO Auto-generated catch block
538
                        e.printStackTrace();
539
                }
540
        }
541
        
542
        public void loadState(InputStream in) {
543
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
544
                try {
545
                        PersistentState state = manager.loadState(in);
546
                        this.loadFromState(state);
547
                } catch (PersistenceException e) {
548
                        // TODO Auto-generated catch block
549
                        e.printStackTrace();
550
                }
551
                
552
        }
553
        
554
        public void saveState(File out) {
555
                FileOutputStream fout;
556
                try {
557
                        fout = new FileOutputStream(out);
558
                        saveState(fout);
559
                } catch (FileNotFoundException e) {
560
                        // TODO Auto-generated catch block
561
                        e.printStackTrace();
562
                }
563
        }
564
        
565
        public void loadState(File in) {
566
                FileInputStream fin;
567
                try {
568
                        fin = new FileInputStream(in);
569
                        loadState(fin);
570
                } catch (FileNotFoundException e) {
571
                        // TODO Auto-generated catch block
572
                        e.printStackTrace();
573
                }
574
        }
575
        
576
        @SuppressWarnings("unchecked")
577
        public void loadFromState(PersistentState state)
578
                        throws PersistenceException {
579
                this.clean();
580
                
581
                this.setComments( state.getString("comments") );
582
                this.setCreationDate( state.getString("creationDate") );
583
                this.setModificationDate( state.getString("modificationDate") );
584
                this.setName( state.getString("name") );
585
                this.setOwner( state.getString("owner") );
586
                this.setSelectionColor( (Color)state.get("selectionColor") );
587
                this.setProjection( (IProjection) state.get("projection") );
588
                
589
                List<ProjectExtent> extents = (List<ProjectExtent>) state.get("extents");
590
                for( int i=0; i<extents.size(); i++) {
591
                        this.addExtent( extents.get(i) );
592
                }
593
                
594
                List<AbstractDocument> documents = (List<AbstractDocument>) state.get("documents");
595
                for( int i=0; i<documents.size(); i++) {
596
                        this.add( documents.get(i) );
597
                }
598

    
599
        }
600

    
601
        public void saveToState(PersistentState state) throws PersistenceException {
602
                state.set("version", VERSION);
603
                state.set("comments", getComments());
604
                state.set("creationDate", this.getCreationDate());
605

    
606
                state.set("modificationDate",  this.getModificationDate());
607
                state.set("name", this.getName());
608
                state.set("owner", this.getOwner());
609
                state.set("selectionColor", this.getSelectionColor());
610
                
611
                state.set("projection",  this.getProjection());
612

    
613
                state.set("extents", this.extents);
614
                state.set("documents", this.getDocuments());
615

    
616
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
617
                List<PersistentState> windowsStates = new ArrayList<PersistentState>();
618
                IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows();
619
                for (int i = windows.length - 1; i >= 0; i--) {
620
                        IWindow window = windows[i];
621
                        if( window instanceof Persistent ) {
622
                                try {
623
                                        windowsStates.add( persistenceManager.getState(windows));
624
                                } catch (PersistenceValidateExceptions e) {
625
                                        throw new PersistenceException(e);
626
                                }
627
                        }
628
                }
629
                state.set("windowsInformation", windowsStates);
630
                
631
        }
632
                        
633

    
634
        public static void registerPersistent() {
635
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
636
                DynStruct definition = manager.addDefinition(
637
                                DefaultProject.class,
638
                                "Project",
639
                                "Project Persistence definition",
640
                                null, 
641
                                null
642
                );
643
                definition.addDynFieldString("version").setMandatory(true);
644
                definition.addDynFieldString("comments").setMandatory(true);
645
                definition.addDynFieldString("creationDate").setMandatory(true);
646
                definition.addDynFieldString("modificationDate").setMandatory(true);
647
                definition.addDynFieldString("name").setMandatory(true);
648
                definition.addDynFieldString("owner").setMandatory(true);
649

    
650
                definition.addDynFieldObject("selectionColor").setMandatory(true);
651
                definition.addDynFieldObject("projection").setMandatory(true);
652

    
653
                definition.addDynFieldList("extents").setMandatory(true);
654

    
655
                definition.addDynFieldList("documents").setMandatory(true);
656
                
657
        }
658

    
659
        /**
660
         * @deprecated use getPreferences().setDefaultSelectionColor()
661
         */
662
        public static void setDefaultSelectionColor(Color color) {
663
                getPreferences().setDefaultSelectionColor(color);
664
        }
665

    
666
        /**
667
         * @deprecated use getPreferences().getDefaultSelectionColor()
668
         */
669
        
670
        public static Color getDefaultSelectionColor() {
671
                return getPreferences().getDefaultSelectionColor();
672
        }
673

    
674
        /**
675
         * @deprecated use getPreferences().getDefaultMapUnits()
676
         */
677
        public static int getDefaultMapUnits() {
678
                return getPreferences().getDefaultMapUnits();
679
        }
680

    
681
        /**
682
         * @deprecated use getPreferences().getDefaultDistanceUnits()
683
         */
684
        public static int getDefaultDistanceUnits() {
685
                return getPreferences().getDefaultDistanceUnits();
686
        }
687
        
688
        /**
689
         * @deprecated use getPreferences().getDefaultDistanceArea()
690
         */
691
        public static int getDefaultDistanceArea() {
692
                return getPreferences().getDefaultDistanceArea();
693
        }
694
        
695
        /**
696
         * @deprecated use getPreferences().setDefaultMapUnits()
697
         */
698
        public static void setDefaultMapUnits(int mapUnits) {
699
                getPreferences().setDefaultMapUnits(mapUnits);
700
        }
701

    
702
        /**
703
         * @deprecated use getPreferences().setDefaultDistanceUnits()
704
         */
705
        public static void setDefaultDistanceUnits(int distanceUnits) {
706
                getPreferences().setDefaultDistanceUnits(distanceUnits);
707
        }
708
        
709
        /**
710
         * @deprecated use getPreferences().setDefaultDistanceArea()
711
         */
712
        public static void setDefaultDistanceArea(int distanceArea) {
713
                getPreferences().setDefaultDistanceArea(distanceArea);
714
        }
715

    
716
        /**
717
         * @deprecated use getPreferences().setDefaultProjection()
718
         */
719
        public static void setDefaultProjection(IProjection defaultProjection) {
720
                getPreferences().setDefaultProjection(defaultProjection);
721
        }
722

    
723
        /**
724
         * @deprecated use getPreferences().getDefaultProjection()
725
         */
726
        public static IProjection getDefaultProjection() {
727
                return getPreferences().getDefaultProjection();
728
        }
729

    
730
        /**
731
         * @deprecated see {@link #setSelectionColor(String)}, to be remove in gvSIG 2.1.0
732
         */
733
        public void setColor(String color) {
734
                this.setSelectionColor(StringUtilities.string2Color(color));
735
        }
736

    
737
        /**
738
         * Return the selection color 
739
         *
740
         * @return selection color as string
741
         * @deprecated use {@link #getSelectionColor()}
742
         */
743
        public String getColor() {
744
                return StringUtilities.color2String(selectionColor);
745
        }
746

    
747

    
748
        /**
749
         * Devuelve a partir del nombre la tabla asociada.
750
         *
751
         * @param name
752
         *            Nombre.
753
         * @deprecated utilizar getProjectDocumentByName(...);
754
         * @return ProjectTable de la tabla asociada.
755
         */
756
        public TableDocument getTable(String name) {
757
                return (TableDocument) this.getDocument(name,TableManager.TYPENAME);
758
        }
759

    
760
        /**
761
         * Return the list of maps of the project
762
         *
763
         * @return tables as ArrayList of IProjectDocument
764
         * 
765
         * @deprecated see {@link #getDocumentsByType(String)}
766
         */
767
        public List<Document> getMaps() {
768
                return getDocuments(LayoutManager.TYPENAME);
769
        }
770

    
771
        /**
772
         * Add a  {@link LayoutDocument} to the project
773
         *
774
         * @deprecated see {@link #add(Document)}
775
         */
776
        public void addMap(LayoutDocument m) {
777
                add(m);
778
        }
779

    
780
        /**
781
         * Remove a  map of the project
782
         *
783
         * @param index of the map as integer
784
         * 
785
         * @deprecated see {@link #remove(Document)}
786
         */
787
        public void delMap(int i) {
788
                List<Document> list = getDocuments(LayoutManager.TYPENAME);
789
                remove(list.get(i));
790
        }
791

    
792

    
793
        /**
794
         * Return the list of tables of the project
795
         *
796
         * @return tables as ArrayList of ProjectDocument
797
         * 
798
         * @deprecated see {@link #getDocumentsByType(String)}
799
         */
800
        public List<Document> getTables() {
801
                return getDocuments(TableManager.TYPENAME);
802
        }
803

    
804
        /**
805
         * Add a  {@link TableDocument } to the project
806
         *
807
         * @deprecated see {@link #add(AbstractDocument)}
808
         */
809
        public void addTable(TableDocument t) {
810
                add(t);
811
        }
812

    
813
        /**
814
         * Remove a  {@link TableDocument } of the project
815
         *
816
         * @param index of the table as integer
817
         * 
818
         * @deprecated see {@link #remove(AbstractDocument)}
819
         */
820
        public void delTable(int i) {
821
                List<Document> list = getDocuments(TableManager.TYPENAME);
822
                remove(list.get(i));
823
        }
824

    
825
        /**
826
         * Return the list of views of the project
827
         *
828
         * @return views as ArrayList of ProjectDocument
829
         * 
830
         * @deprecated see {@link #getDocumentsByType(String)}
831
         */
832
        public List<Document> getViews() {
833
                return getDocuments(ViewManager.TYPENAME);
834
        }
835

    
836
        /**
837
         * Add a  view to the project
838
         *
839
         * @deprecated see {@link #add(AbstractDocument)}
840
         */
841
        public void addView(DefaultViewDocument v) {
842
                add(v);
843
        }
844

    
845
        /**
846
         * Remove a view of the project
847
         *
848
         * @param index of the view as integer
849
         * 
850
         * @deprecated see {@link #remove(AbstractDocument)}
851
         */
852
        public void delView(int i) {
853
                List<Document> list = getDocuments(ViewManager.TYPENAME);
854
                remove(list.get(i));
855
        }
856

    
857
        /**
858
         * @deprecated see {@link #getDocument(String, String)} 
859
         */
860
        public Document getProjectDocumentByName(String name, String type) {
861
                return this.getDocument(name, type);
862
        }
863

    
864
        /**
865
         * @deprecated see {@link #getDocuments(String)} 
866
         */
867
        public List<Document> getDocumentsByType(String type) {
868
                return this.getDocuments(type);
869
        }
870

    
871
        /**
872
         * @deprecated aun por decidir que API darle al copy/paste 
873
         */
874
        public String exportToXML(AbstractDocument[] selectedItems) throws SaveException {
875
                // FIXME jjdc:hay que decirdir que API darle al copy/paste
876
                throw new UnsupportedOperationException("This method is not supported");
877
        }
878

    
879
        /**
880
         * @deprecated aun por decidir que API darle al copy/paste 
881
         */
882
        public void importFromXML(String sourceString, String docType) {
883
                // FIXME jjdc:hay que decirdir que API darle al copy/paste
884
                throw new UnsupportedOperationException("This method is not supported");
885
        }
886

    
887
        /**
888
         * @deprecated aun por decidir que API darle al copy/paste 
889
         */
890
        public boolean isValidXMLForImport(String sourceString, String docType) {
891
                // FIXME jjdc:hay que decirdir que API darle al copy/paste
892
                throw new UnsupportedOperationException("This method is not supported");
893
        }
894

    
895
        public boolean canImportDocuments(String data, String doctype) {
896
                // TODO Auto-generated method stub
897
                return false;
898
        }
899

    
900
        public String exportDocumentsAsText(List<Document> documents) {
901
                // TODO Auto-generated method stub
902
                return null;
903
        }
904

    
905
        public void importDocuments(String data, String doctype) {
906
                // TODO Auto-generated method stub
907
                
908
        }
909

    
910
        public Document getActiveDocument() {
911
                try {
912
                        SingletonWindow window = (SingletonWindow) PluginServices.getMDIManager().getActiveWindow();
913
                        Document doc = (Document) window.getWindowModel();
914
                        return doc;
915
                } catch(Exception ex) {
916
                        return null;
917
                }
918
        }
919
}