Statistics
| Revision:

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

History | View | Annotate | Download (23.5 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.persistence.PersistenceClassNotRegistered;
72
import org.gvsig.tools.persistence.PersistenceException;
73
import org.gvsig.tools.persistence.PersistenceManager;
74
import org.gvsig.tools.persistence.PersistenceTypeNotSupportedException;
75
import org.gvsig.tools.persistence.PersistenceValidateExceptions;
76
import org.gvsig.tools.persistence.Persistent;
77
import org.gvsig.tools.persistence.PersistentState;
78
import org.gvsig.utils.StringUtilities;
79

    
80

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

    
91
public class DefaultProject implements Serializable, PropertyChangeListener, Persistent, Project {
92

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

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

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

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

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

    
112
        private PropertyChangeSupport change;
113

    
114
        private boolean modified = false;
115

    
116
        private String name = null;
117

    
118
        private String creationDate = null;
119

    
120
        private String modificationDate = null;
121

    
122
        private String owner = null;
123

    
124
        private String comments = null;
125

    
126
        private Color selectionColor = null;
127

    
128
        private List<Document> documents = null;
129

    
130
        private List<ProjectExtent> extents = null;
131

    
132
        // Lista de objetos del tipo camera. Necesarios para almacenar la posicion
133
        // del usuario haciendo uso de los marcadores
134
        private List<Object> cameras = null;
135

    
136
        private IProjection projection;
137

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

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

    
153
                this.documents = new ArrayList<Document>();
154
                this.extents = new ArrayList<ProjectExtent>();
155
                this.cameras = new ArrayList<Object>();
156

    
157
                this.setSelectionColor(getPreferences().getDefaultSelectionColor());
158
        
159
                this.projection = null ; // se inicializa en el getProjection()
160
        }
161
        
162
        
163
        public static ProjectPreferences getPreferences() {
164
                return preferences;
165
        }
166

    
167
        public void propertyChange(PropertyChangeEvent evt) {
168
                change.firePropertyChange(evt);
169
        }
170

    
171
        public synchronized void addPropertyChangeListener(
172
                        PropertyChangeListener arg0) {
173
                change.addPropertyChangeListener(arg0);
174
        }
175

    
176
        
177
        /**
178
         * Return the creation date of the project
179
         *
180
         * @return
181
         */
182
        public String getCreationDate() {
183
                return creationDate;
184
        }
185

    
186
        protected void setCreationDate(String creationDate) {
187
                this.creationDate = creationDate ;
188
                change.firePropertyChange("setCreationDate", null, null);
189
        }
190

    
191

    
192
        /**
193
         * Return the name of the project
194
         *
195
         * @return
196
         */
197
        public String getName() {
198
                return name;
199
        }
200

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

    
211
        /**
212
         * Return the comments associateds with the project
213
         *
214
         * @return comments
215
         */
216
        public String getComments() {
217
                return comments;
218
        }
219

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

    
230
        /**
231
         * Retuen the modification date of the project.
232
         *
233
         * @return modification date as string
234
         */
235
        public String getModificationDate() {
236
                return modificationDate;
237
        }
238

    
239
        protected void setModificationDate(String string) {
240
                modificationDate = string;
241
                change.firePropertyChange("setModificationDate", null, null);
242
        }
243

    
244
        /**
245
         * Return the author of the project,
246
         *
247
         * @return author as string
248
         */
249
        public String getOwner() {
250
                return owner;
251
        }
252

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

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

    
275
        /**
276
         * Sets the selecction color
277
         *
278
         * @param selection color as string
279
         */
280
        public void setSelectionColor(String selectionColor) {
281
                this.setSelectionColor(StringUtilities.string2Color(selectionColor));
282
        }
283

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

    
295
        public IProjection getProjection() {
296
                if (projection == null) {
297
                        projection =  getPreferences().getDefaultProjection();
298
                }
299
                return projection;
300
        }
301

    
302
        public void setProjection(IProjection projection) {
303
                this.projection = projection;
304
        }
305

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

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

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

    
359

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

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

    
392
        public Iterator<Document> iterator() {
393
                return documents.iterator();
394
        }
395

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

    
416
                return null;
417
        }
418

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

    
440
                throw new RuntimeException(MessageFormat.format("The layer '{1}' is not in a view",  layer.getName()));
441
        }
442

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

    
457
        public void addExtent(ProjectExtent arg1) {
458
                extents.add(arg1);
459
                change.firePropertyChange("addExtent", null, null);
460
        }
461

    
462
        public ProjectExtent removeExtent(int arg0) {
463
                change.firePropertyChange("delExtent", null, null);
464
                return extents.remove(arg0);
465
        }
466

    
467
        public ProjectExtent[] getExtents() {
468
                return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]);
469
        }
470

    
471
        public void addCamera(Object arg1) {
472
                this.cameras.add(arg1);
473
                change.firePropertyChange("addCamera", null, null);
474
        }
475

    
476
        public Object removeCamera(int arg0) {
477
                change.firePropertyChange("delCamera", null, null);
478
                return this.cameras.remove(arg0);
479
        }
480

    
481
        public Object[] getCameras() {
482
                return this.cameras.toArray(new Object[0]);
483
        }
484

    
485

    
486
        /**
487
         * Obtiene un documento a partir de su nombre y el nombre de registro en el
488
         * pointExtension, este ?ltimo se puede obtener del
489
         * Project****Factory.registerName.
490
         *
491
         * @param name
492
         *            Nombre del documento
493
         * @param type
494
         *            nombre de registro en el extensionPoint
495
         *
496
         * @return Documento
497
         */
498
        public Document getDocument(String name, String type) {
499
                if( type != null ) {
500
                        for (int i = 0; i < documents.size(); i++) {
501
                                Document document = documents.get(i);
502
                                if (type.equalsIgnoreCase(document.getTypeName()) && name.equalsIgnoreCase(document.getName())) {
503
                                        return document;
504
                                }
505
                        }
506
                }
507
                return null;
508
        }
509

    
510
        public String getUniqueNameForDocument(String type, String name) {
511
                Document document = getDocument(name, type);
512
                if( document == null ) {
513
                        return name;
514
                }
515
                
516
        String newName = null;
517
        int num = this.getNextDocumentIndex(type);
518
        while( document != null ) {
519
            newName = name + " - " + num++;
520
                    document = getDocument(newName, type);                
521
        } 
522
        this.setNextDocumentIndex(type, num);
523
        return newName;
524
        }
525
        
526
        private int getNextDocumentIndex(String type) {
527
                if( nextDocumentIndexByType.get(type) == null ) {
528
                        nextDocumentIndexByType.put(type, new Integer(1));
529
                        return 1;
530
                }
531
                return nextDocumentIndexByType.get(type).intValue();
532
        }
533

    
534
        private void setNextDocumentIndex(String type, int newIndex) {
535
                if( nextDocumentIndexByType.get(type) == null ) {
536
                        nextDocumentIndexByType.put(type, new Integer(newIndex));
537
                } else {
538
                        nextDocumentIndexByType.put(type, new Integer(newIndex));
539
                }
540
        }
541

    
542
        public void saveState(OutputStream out) {
543
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
544
                try {
545
                        manager.saveState( manager.getState(this), out);
546
                } catch (PersistenceTypeNotSupportedException e) {
547
                        // TODO Auto-generated catch block
548
                        e.printStackTrace();
549
                } catch (PersistenceClassNotRegistered e) {
550
                        // TODO Auto-generated catch block
551
                        e.printStackTrace();
552
                } catch (PersistenceException e) {
553
                        // TODO Auto-generated catch block
554
                        e.printStackTrace();
555
                } catch (PersistenceValidateExceptions e) {
556
                        // TODO Auto-generated catch block
557
                        e.printStackTrace();
558
                }
559
        }
560
        
561
        public void loadState(InputStream in) {
562
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
563
                try {
564
                        PersistentState state = manager.loadState(in);
565
                        this.loadFromState(state);
566
                } catch (PersistenceException e) {
567
                        // TODO Auto-generated catch block
568
                        e.printStackTrace();
569
                }
570
                
571
        }
572
        
573
        public void saveState(File out) {
574
                FileOutputStream fout;
575
                try {
576
                        fout = new FileOutputStream(out);
577
                        saveState(fout);
578
                } catch (FileNotFoundException e) {
579
                        // TODO Auto-generated catch block
580
                        e.printStackTrace();
581
                }
582
        }
583
        
584
        public void loadState(File in) {
585
                FileInputStream fin;
586
                try {
587
                        fin = new FileInputStream(in);
588
                        loadState(fin);
589
                } catch (FileNotFoundException e) {
590
                        // TODO Auto-generated catch block
591
                        e.printStackTrace();
592
                }
593
        }
594
        
595
        @SuppressWarnings("unchecked")
596
        public void loadFromState(PersistentState state)
597
                        throws PersistenceException {
598
                this.clean();
599
                
600
                this.setComments( state.getString("comments") );
601
                this.setCreationDate( state.getString("creationDate") );
602
                this.setModificationDate( state.getString("modificationDate") );
603
                this.setName( state.getString("name") );
604
                this.setOwner( state.getString("owner") );
605
                this.setSelectionColor( (Color)state.get("selectionColor") );
606
                this.setProjection( (IProjection) state.get("projection") );
607
                
608
                List<ProjectExtent> extents = (List<ProjectExtent>) state.get("extents");
609
                for( int i=0; i<extents.size(); i++) {
610
                        this.addExtent( extents.get(i) );
611
                }
612
                
613
                List<AbstractDocument> documents = (List<AbstractDocument>) state.get("documents");
614
                for( int i=0; i<documents.size(); i++) {
615
                        this.add( documents.get(i) );
616
                }
617

    
618
                List<Object> cameras = (List<Object>) state.get("cameras");
619
                for( int i=0; i<cameras.size(); i++) {
620
                        this.addCamera( cameras.get(i) );
621
                }
622
                
623
        }
624

    
625
        public void saveToState(PersistentState state) throws PersistenceException {
626
                state.set("VERSION", VERSION);
627
                state.set("comments", getComments());
628
                state.set("creationDate", this.getCreationDate());
629

    
630
                state.set("modificationDate",  this.getModificationDate());
631
                state.set("name", this.getName());
632
                state.set("owner", this.getOwner());
633
                state.set("selectionColor", this.getSelectionColor());
634
                
635
                state.set("projection",  this.getProjection());
636

    
637
                state.set("extents", this.getExtents());
638
                state.set("cameras", this.getCameras());
639
                state.set("documents", this.getDocuments());
640

    
641
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
642
                List<PersistentState> windowsStates = new ArrayList<PersistentState>();
643
                IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows();
644
                for (int i = windows.length - 1; i >= 0; i--) {
645
                        IWindow window = windows[i];
646
                        if( window instanceof Persistent ) {
647
                                try {
648
                                        windowsStates.add( persistenceManager.getState(windows));
649
                                } catch (PersistenceValidateExceptions e) {
650
                                        throw new PersistenceException(e);
651
                                }
652
                        }
653
                }
654
                state.set("windowsInformation", windowsStates);
655
                
656
        }
657
                        
658
        /**
659
         * @deprecated use getPreferences().setDefaultSelectionColor()
660
         */
661
        public static void setDefaultSelectionColor(Color color) {
662
                getPreferences().setDefaultSelectionColor(color);
663
        }
664

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

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

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

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

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

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

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

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

    
746

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

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

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

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

    
791

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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