Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 9044

History | View | Annotate | Download (10.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.project.documents;
42

    
43
import java.beans.PropertyChangeListener;
44
import java.beans.PropertyChangeSupport;
45
import java.io.Serializable;
46
import java.text.DateFormat;
47
import java.util.Date;
48

    
49
import com.hardcode.driverManager.DriverLoadException;
50
import com.iver.andami.messages.NotificationManager;
51
import com.iver.andami.ui.mdiManager.IWindow;
52
import com.iver.cit.gvsig.fmap.DriverException;
53
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
54
import com.iver.cit.gvsig.fmap.layers.CancelationException;
55
import com.iver.cit.gvsig.fmap.layers.XMLException;
56
import com.iver.cit.gvsig.project.Project;
57
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
58
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
59
import com.iver.cit.gvsig.project.documents.gui.WindowData;
60
import com.iver.utiles.XMLEntity;
61
import com.iver.utiles.extensionPoints.ExtensionPoint;
62
import com.iver.utiles.extensionPoints.ExtensionPoints;
63
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
64

    
65

    
66
/**
67
 * Clase base de los elementos del proyecto (mapas, tablas y vistas)
68
 *
69
 * @author Fernando Gonz?lez Cort?s
70
 */
71
public abstract class ProjectDocument implements Serializable {
72
        protected PropertyChangeSupport change;
73
        protected Project project;
74
        protected int index;
75
        protected String name;
76
        protected String creationDate;
77
        protected String owner;
78
        protected String comment;
79
        private boolean locked = false;
80
        protected WindowData windowData = null;
81

    
82
        private ProjectDocumentFactory projectDocumentFactory;
83
        /**
84
         * Creates a new ProjectElement object.
85
         */
86
        public ProjectDocument() {
87
                creationDate = DateFormat.getDateInstance().format(new Date());
88
                change = new PropertyChangeSupport(this);
89
        }
90

    
91
        /**
92
         * @see java.lang.Object#toString()
93
         */
94
        public String toString() {
95
                return name;
96
        }
97

    
98
        /**
99
         * Obtiene el nombre del elemento
100
         *
101
         * @return
102
         */
103
        public String getName() {
104
                return name;
105
        }
106

    
107
        /**
108
         * Establece el nombre del elemento
109
         *
110
         * @param string
111
         */
112
        public void setName(String string) {
113
                String oldValue = name;
114
                name = string;
115
                change.firePropertyChange("name", oldValue, name);
116
        }
117

    
118
        /**
119
         * Obtiene la fecha de creaci?n del elemento
120
         *
121
         * @return
122
         */
123
        public String getCreationDate() {
124
                return creationDate;
125
        }
126

    
127
        /**
128
         * Obtiene el propietario del elemento
129
         *
130
         * @return
131
         */
132
        public String getOwner() {
133
                return owner;
134
        }
135

    
136
        /**
137
         * Establece la fecha de creaci?n del elemento.
138
         *
139
         * @param string
140
         */
141
        public void setCreationDate(String string) {
142
                creationDate = string;
143
                change.firePropertyChange("creationDate", creationDate, creationDate);
144
        }
145

    
146
        /**
147
         * Establece el propietario del elemento
148
         *
149
         * @param string
150
         */
151
        public void setOwner(String string) {
152
                owner = string;
153
                change.firePropertyChange("owner", owner, owner);
154
        }
155

    
156
        /**
157
         * Obtiene los comentarios del proyecto
158
         *
159
         * @return
160
         */
161
        public String getComment() {
162
                return comment;
163
        }
164

    
165
        /**
166
         * Establece los comentarios del proyecto
167
         *
168
         * @param string
169
         */
170
        public void setComment(String string) {
171
                comment = string;
172
                change.firePropertyChange("comment", comment, comment);
173
        }
174

    
175
        /**
176
         * A?ade un listener para los cambios en las bounded properties
177
         *
178
         * @param listener
179
         */
180
        public synchronized void addPropertyChangeListener(
181
                PropertyChangeListener listener) {
182
                change.addPropertyChangeListener(listener);
183
        }
184

    
185
        /**
186
         * DOCUMENT ME!
187
         *
188
         * @return DOCUMENT ME!
189
         * @throws XMLException
190
         * @throws SaveException
191
         */
192
        public XMLEntity getXMLEntity() throws SaveException {
193
                XMLEntity xml = new XMLEntity();
194
                try{
195
                //xml.putProperty("nameRegister",this.getRegisterName());
196
                xml.putProperty("className", projectDocumentFactory.getRegisterName());
197
                xml.putProperty("comment", comment);
198
                xml.putProperty("creationDate", creationDate);
199
                xml.putProperty("name", name);
200
                xml.putProperty("owner", owner);
201
                }catch (Exception e) {
202
                        throw new SaveException(e,this.getClass().getName());
203
                }
204
                return xml;
205
        }
206

    
207
    /**
208
     * DOCUMENT ME!
209
     *
210
     * @param xml DOCUMENT ME!
211
     * @param p DOCUMENT ME!
212
     *
213
     * @return DOCUMENT ME!
214
     * @throws XMLException
215
     * @throws DriverException
216
     * @throws DriverIOException
217
     * @throws CancelationException
218
     * @throws ClassNotFoundException
219
     * @throws InstantiationException
220
     * @throws IllegalAccessException
221
     * @throws DriverIOException
222
     * @throws DriverLoadException
223
     */
224
    public static ProjectDocument createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{
225
        ProjectDocument pe = null;
226

    
227
            Class clase;
228
                        try {
229
                                clase = Class.forName(xml.getStringProperty("className"));
230
                        pe = (ProjectDocument) clase.newInstance();
231
                        } catch (ClassNotFoundException e) {
232
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
233
                            e);
234
                        } catch (InstantiationException e) {
235
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
236
                            e);
237
                        } catch (IllegalAccessException e) {
238
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
239
                            e);
240
                        }
241

    
242
        return pe;
243
    }
244

    
245
        /**
246
         * DOCUMENT ME!
247
         *
248
         * @param xml DOCUMENT ME!
249
         * @param p DOCUMENT ME!
250
         *
251
         * @return DOCUMENT ME!
252
         *
253
         * @throws XMLException
254
         * @throws DriverException
255
         * @throws DriverIOException
256
         * @throws OpenException
257
         */
258
        public static ProjectDocument createFromXML(XMLEntity xml, Project p)
259
                throws XMLException, DriverException, DriverIOException, OpenException {
260
                ProjectDocumentFactory pde = null;
261
                try{
262
                        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
263
                        ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
264
                        try {
265
                                pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
266
                        } catch (InstantiationException e) {
267
                                NotificationManager.addError("Clase de ProjectDocument no reconocida",
268
                                                e);
269
                        } catch (IllegalAccessException e) {
270
                                NotificationManager.addError("Clase de ProjectDocument no reconocida",
271
                                        e);
272
                        }
273
                        ProjectDocument pe=pde.create(p);
274
                        pe.setProjectDocumentFactory(pde);                
275
                        return pe;
276
                }catch (Exception e) {
277
                        throw new OpenException(e,pde.getNameType());
278
                }
279
        }
280

    
281
        /**
282
         * DOCUMENT ME!
283
         *
284
         * @param xml DOCUMENT ME!
285
         * @param p DOCUMENT ME!
286
         *
287
         * @throws XMLException
288
         * @throws DriverException
289
         * @throws DriverIOException
290
         * @throws OpenException
291
         */
292
        public void setXMLEntity(XMLEntity xml)
293
                throws XMLException, DriverException, DriverIOException, OpenException{
294
                
295
                this.setComment(xml.getStringProperty("comment"));
296
                this.setCreationDate(xml.getStringProperty("creationDate"));
297
                this.setName(xml.getStringProperty("name"));
298
                this.setOwner(xml.getStringProperty("owner"));
299
                
300
        }
301

    
302
        /**
303
         * DOCUMENT ME!
304
         *
305
         * @param xml DOCUMENT ME!
306
         * @param p DOCUMENT ME!
307
         *
308
         * @throws XMLException
309
         * @throws DriverException
310
         * @throws DriverIOException
311
         */
312
        public void setXMLEntity03(XMLEntity xml)
313
                throws XMLException, DriverException, DriverIOException{
314
                        
315
                        this.setComment(xml.getStringProperty("comment"));
316
                        this.setCreationDate(xml.getStringProperty("creationDate"));
317
                        this.setName(xml.getStringProperty("name"));
318
                        this.setOwner(xml.getStringProperty("owner"));
319
                        
320
                }
321

    
322
        /**
323
         * DOCUMENT ME!
324
         *
325
         * @return DOCUMENT ME!
326
         */
327
        public Project getProject() {
328
                return project;
329
        }
330
        /**
331
         * DOCUMENT ME!
332
         *
333
         * @param project DOCUMENT ME!
334
         */
335
        public void setProject(Project project, int index) {
336
                this.project = project;
337
                this.index = index;
338
        }
339
        public int getIndex() {
340
                return index;
341
        }
342

    
343
        /**
344
         * Locks this project element protecting it from deleting from the project.
345
         */
346
        public void lock() {
347
                locked = true;
348
        }
349

    
350
        /**
351
         * Unlocks this element. So, from now on, it can be removed from the project.
352
         */
353
        public void unlock() {
354
                locked = false;
355
        }
356

    
357
        /**
358
         * Tells whether if this project's element is locked/protected or not. A protected
359
         * element cannot be removed from the current project.
360
         *
361
         * @see <b>lock()</b> and <b>unlock()</b> methods.
362
         *
363
         * @return true if it is locked, false otherwise
364
         */
365
        public boolean isLocked() {
366
                return locked;
367
        }
368

    
369
        public abstract IWindow createWindow();
370
        public abstract IWindow getProperties();
371
        public abstract void afterRemove();
372
        public abstract void afterAdd();
373

    
374

    
375
        public void setProjectDocumentFactory(
376
                        ProjectDocumentFactory projectDocumentFactory) {
377
                this.projectDocumentFactory = projectDocumentFactory;
378
        }
379

    
380
        public ProjectDocumentFactory getProjectDocumentFactory() {
381
                return projectDocumentFactory;
382
        }
383
        
384
        public abstract void exportToXML(XMLEntity root, Project project)  throws SaveException ;
385
        
386
        public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, DriverException, OpenException;
387
                
388
        
389
        public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, DriverException, OpenException{
390
                importFromXML(root,typeRoot, elementIndex,project,false);
391
        }
392
        
393
        /**
394
         * Get the layout properties (size, position, state of the components)
395
         * of the window associated with this ProjectDocument.
396
         * This is used to re-open the window with the same properties it had
397
         * when it was closed.
398
         * 
399
         * @return A WindowData object storing the properties of the window.
400
         */
401
        public WindowData getWindowData() {
402
                return windowData;
403
        }
404
        
405
        /**
406
         * Store the layout properties (size, position, state of the components)
407
         * of the window associated with this ProjectDocument.
408
         * This is used to re-open the window with the same properties it had
409
         * when it was closed.
410
         */
411
        public void storeWindowData(WindowData data) {
412
                windowData = data;
413
        }
414
}