Statistics
| Revision:

root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocument.java @ 12136

History | View | Annotate | Download (11.6 KB)

1 7304 caballero
/* 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 7343 caballero
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 10666 caballero
import java.util.HashMap;
49
import java.util.Iterator;
50 7304 caballero
51 7343 caballero
import com.hardcode.driverManager.DriverLoadException;
52 7304 caballero
import com.iver.andami.messages.NotificationManager;
53
import com.iver.andami.ui.mdiManager.IWindow;
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56
import com.iver.cit.gvsig.fmap.layers.CancelationException;
57
import com.iver.cit.gvsig.fmap.layers.XMLException;
58
import com.iver.cit.gvsig.project.Project;
59
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
60
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
61 8975 cesar
import com.iver.cit.gvsig.project.documents.gui.WindowData;
62 7304 caballero
import com.iver.utiles.XMLEntity;
63
import com.iver.utiles.extensionPoints.ExtensionPoint;
64
import com.iver.utiles.extensionPoints.ExtensionPoints;
65
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
66
67
68
/**
69
 * Clase base de los elementos del proyecto (mapas, tablas y vistas)
70
 *
71
 * @author Fernando Gonz?lez Cort?s
72
 */
73
public abstract class ProjectDocument implements Serializable {
74 10666 caballero
        public static HashMap NUMS = new HashMap();
75 7304 caballero
        protected PropertyChangeSupport change;
76
        protected Project project;
77
        protected int index;
78
        protected String name;
79
        protected String creationDate;
80
        protected String owner;
81
        protected String comment;
82
        private boolean locked = false;
83 8975 cesar
        protected WindowData windowData = null;
84 7689 cesar
85 7343 caballero
        private ProjectDocumentFactory projectDocumentFactory;
86 7304 caballero
        /**
87
         * Creates a new ProjectElement object.
88
         */
89
        public ProjectDocument() {
90
                creationDate = DateFormat.getDateInstance().format(new Date());
91
                change = new PropertyChangeSupport(this);
92
        }
93
94
        /**
95
         * @see java.lang.Object#toString()
96
         */
97
        public String toString() {
98
                return name;
99
        }
100
101
        /**
102
         * Obtiene el nombre del elemento
103
         *
104
         * @return
105
         */
106
        public String getName() {
107
                return name;
108
        }
109
110
        /**
111
         * Establece el nombre del elemento
112
         *
113
         * @param string
114
         */
115
        public void setName(String string) {
116
                String oldValue = name;
117
                name = string;
118
                change.firePropertyChange("name", oldValue, name);
119
        }
120
121
        /**
122
         * Obtiene la fecha de creaci?n del elemento
123
         *
124
         * @return
125
         */
126
        public String getCreationDate() {
127
                return creationDate;
128
        }
129
130
        /**
131
         * Obtiene el propietario del elemento
132
         *
133
         * @return
134
         */
135
        public String getOwner() {
136
                return owner;
137
        }
138
139
        /**
140
         * Establece la fecha de creaci?n del elemento.
141
         *
142
         * @param string
143
         */
144
        public void setCreationDate(String string) {
145
                creationDate = string;
146
                change.firePropertyChange("creationDate", creationDate, creationDate);
147
        }
148
149
        /**
150
         * Establece el propietario del elemento
151
         *
152
         * @param string
153
         */
154
        public void setOwner(String string) {
155
                owner = string;
156
                change.firePropertyChange("owner", owner, owner);
157
        }
158
159
        /**
160
         * Obtiene los comentarios del proyecto
161
         *
162
         * @return
163
         */
164
        public String getComment() {
165
                return comment;
166
        }
167
168
        /**
169
         * Establece los comentarios del proyecto
170
         *
171
         * @param string
172
         */
173
        public void setComment(String string) {
174
                comment = string;
175
                change.firePropertyChange("comment", comment, comment);
176
        }
177
178
        /**
179
         * A?ade un listener para los cambios en las bounded properties
180
         *
181
         * @param listener
182
         */
183
        public synchronized void addPropertyChangeListener(
184
                PropertyChangeListener listener) {
185
                change.addPropertyChangeListener(listener);
186
        }
187
188
        /**
189
         * DOCUMENT ME!
190
         *
191
         * @return DOCUMENT ME!
192
         * @throws XMLException
193
         * @throws SaveException
194
         */
195
        public XMLEntity getXMLEntity() throws SaveException {
196
                XMLEntity xml = new XMLEntity();
197
                try{
198
                //xml.putProperty("nameRegister",this.getRegisterName());
199 7343 caballero
                xml.putProperty("className", projectDocumentFactory.getRegisterName());
200 7304 caballero
                xml.putProperty("comment", comment);
201
                xml.putProperty("creationDate", creationDate);
202
                xml.putProperty("name", name);
203
                xml.putProperty("owner", owner);
204
                }catch (Exception e) {
205
                        throw new SaveException(e,this.getClass().getName());
206
                }
207
                return xml;
208
        }
209
210
    /**
211
     * DOCUMENT ME!
212
     *
213
     * @param xml DOCUMENT ME!
214
     * @param p DOCUMENT ME!
215
     *
216
     * @return DOCUMENT ME!
217
     * @throws XMLException
218
     * @throws DriverException
219
     * @throws DriverIOException
220
     * @throws CancelationException
221
     * @throws ClassNotFoundException
222
     * @throws InstantiationException
223
     * @throws IllegalAccessException
224
     * @throws DriverIOException
225
     * @throws DriverLoadException
226
     */
227
    public static ProjectDocument createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{
228
        ProjectDocument pe = null;
229
230
            Class clase;
231
                        try {
232
                                clase = Class.forName(xml.getStringProperty("className"));
233
                        pe = (ProjectDocument) clase.newInstance();
234
                        } catch (ClassNotFoundException e) {
235
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
236
                            e);
237
                        } catch (InstantiationException e) {
238
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
239
                            e);
240
                        } catch (IllegalAccessException e) {
241
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
242
                            e);
243
                        }
244
245
        return pe;
246
    }
247
248
        /**
249
         * DOCUMENT ME!
250
         *
251
         * @param xml DOCUMENT ME!
252
         * @param p DOCUMENT ME!
253
         *
254
         * @return DOCUMENT ME!
255
         *
256
         * @throws XMLException
257
         * @throws DriverException
258
         * @throws DriverIOException
259
         * @throws OpenException
260
         */
261
        public static ProjectDocument createFromXML(XMLEntity xml, Project p)
262
                throws XMLException, DriverException, DriverIOException, OpenException {
263 7343 caballero
                ProjectDocumentFactory pde = null;
264 7304 caballero
                try{
265
                        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
266
                        ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
267 7343 caballero
                        try {
268
                                pde = (ProjectDocumentFactory) extPoint.create(xml.getStringProperty("className"));
269
                        } catch (InstantiationException e) {
270
                                NotificationManager.addError("Clase de ProjectDocument no reconocida",
271
                                                e);
272
                        } catch (IllegalAccessException e) {
273
                                NotificationManager.addError("Clase de ProjectDocument no reconocida",
274
                                        e);
275
                        }
276 7754 jmvivo
                        ProjectDocument pe=pde.create(p);
277 10666 caballero
                        pe.setProjectDocumentFactory(pde);
278 7754 jmvivo
                        return pe;
279 7304 caballero
                }catch (Exception e) {
280 7343 caballero
                        throw new OpenException(e,pde.getNameType());
281 7304 caballero
                }
282
        }
283
284
        /**
285
         * DOCUMENT ME!
286
         *
287
         * @param xml DOCUMENT ME!
288
         * @param p DOCUMENT ME!
289
         *
290
         * @throws XMLException
291
         * @throws DriverException
292
         * @throws DriverIOException
293
         * @throws OpenException
294
         */
295 7754 jmvivo
        public void setXMLEntity(XMLEntity xml)
296
                throws XMLException, DriverException, DriverIOException, OpenException{
297 10666 caballero
298 7754 jmvivo
                this.setComment(xml.getStringProperty("comment"));
299
                this.setCreationDate(xml.getStringProperty("creationDate"));
300
                this.setName(xml.getStringProperty("name"));
301
                this.setOwner(xml.getStringProperty("owner"));
302 10666 caballero
303 7754 jmvivo
        }
304 7304 caballero
305
        /**
306
         * DOCUMENT ME!
307
         *
308
         * @param xml DOCUMENT ME!
309
         * @param p DOCUMENT ME!
310
         *
311
         * @throws XMLException
312
         * @throws DriverException
313
         * @throws DriverIOException
314
         */
315 7754 jmvivo
        public void setXMLEntity03(XMLEntity xml)
316
                throws XMLException, DriverException, DriverIOException{
317 10666 caballero
318 7754 jmvivo
                        this.setComment(xml.getStringProperty("comment"));
319
                        this.setCreationDate(xml.getStringProperty("creationDate"));
320
                        this.setName(xml.getStringProperty("name"));
321
                        this.setOwner(xml.getStringProperty("owner"));
322 10666 caballero
323 7754 jmvivo
                }
324 7304 caballero
325
        /**
326
         * DOCUMENT ME!
327
         *
328
         * @return DOCUMENT ME!
329
         */
330
        public Project getProject() {
331
                return project;
332
        }
333
        /**
334
         * DOCUMENT ME!
335
         *
336
         * @param project DOCUMENT ME!
337
         */
338
        public void setProject(Project project, int index) {
339
                this.project = project;
340
                this.index = index;
341
        }
342
        public int getIndex() {
343
                return index;
344
        }
345
346
        /**
347
         * Locks this project element protecting it from deleting from the project.
348
         */
349
        public void lock() {
350
                locked = true;
351
        }
352
353
        /**
354
         * Unlocks this element. So, from now on, it can be removed from the project.
355
         */
356
        public void unlock() {
357
                locked = false;
358
        }
359
360
        /**
361
         * Tells whether if this project's element is locked/protected or not. A protected
362
         * element cannot be removed from the current project.
363
         *
364
         * @see <b>lock()</b> and <b>unlock()</b> methods.
365
         *
366
         * @return true if it is locked, false otherwise
367
         */
368
        public boolean isLocked() {
369
                return locked;
370
        }
371
372
        public abstract IWindow createWindow();
373
        public abstract IWindow getProperties();
374 7343 caballero
        public abstract void afterRemove();
375
        public abstract void afterAdd();
376 7304 caballero
377 7343 caballero
378
        public void setProjectDocumentFactory(
379
                        ProjectDocumentFactory projectDocumentFactory) {
380
                this.projectDocumentFactory = projectDocumentFactory;
381 7304 caballero
        }
382
383 7343 caballero
        public ProjectDocumentFactory getProjectDocumentFactory() {
384
                return projectDocumentFactory;
385
        }
386 10666 caballero
387 7754 jmvivo
        public abstract void exportToXML(XMLEntity root, Project project)  throws SaveException ;
388 10666 caballero
389 7754 jmvivo
        public abstract void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, DriverException, OpenException;
390 10666 caballero
391
392 7754 jmvivo
        public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project) throws XMLException, DriverException, OpenException{
393
                importFromXML(root,typeRoot, elementIndex,project,false);
394
        }
395 10666 caballero
396 8975 cesar
        /**
397
         * Get the layout properties (size, position, state of the components)
398
         * of the window associated with this ProjectDocument.
399
         * This is used to re-open the window with the same properties it had
400
         * when it was closed.
401 10666 caballero
         *
402 8975 cesar
         * @return A WindowData object storing the properties of the window.
403
         */
404
        public WindowData getWindowData() {
405
                return windowData;
406
        }
407 10666 caballero
408 8975 cesar
        /**
409
         * Store the layout properties (size, position, state of the components)
410
         * of the window associated with this ProjectDocument.
411
         * This is used to re-open the window with the same properties it had
412
         * when it was closed.
413
         */
414
        public void storeWindowData(WindowData data) {
415
                windowData = data;
416
        }
417 10666 caballero
        public static void initializeNUMS() {
418
                NUMS.clear();
419
                ExtensionPoints extensionPoints =
420
                        ExtensionPointsSingleton.getInstance();
421
                ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("Documents");
422
                Iterator iterator = extensionPoint.keySet().iterator();
423
                while (iterator.hasNext()) {
424
                        try {
425
                                ProjectDocumentFactory documentFactory = (ProjectDocumentFactory)extensionPoint.create((String)iterator.next());
426
                                NUMS.put(documentFactory.getRegisterName(),new Integer(0));
427
                        } catch (InstantiationException e) {
428
                                e.printStackTrace();
429
                        } catch (IllegalAccessException e) {
430
                                e.printStackTrace();
431
                        } catch (ClassCastException e) {
432
                                e.printStackTrace();
433
                        }
434
                }
435
436
437
        }
438 7304 caballero
}