Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectElement.java @ 6438

History | View | Annotate | Download (11 KB)

1 1222 fernando
/* 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;
42
43 1830 fernando
import com.hardcode.driverManager.DriverLoadException;
44 1222 fernando
45 5029 cesar
import com.iver.andami.PluginServices;
46 1222 fernando
import com.iver.andami.messages.NotificationManager;
47 5029 cesar
import com.iver.andami.ui.mdiManager.ViewInfo;
48 1830 fernando
49 1222 fernando
import com.iver.cit.gvsig.fmap.DriverException;
50
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
51
import com.iver.cit.gvsig.fmap.layers.CancelationException;
52
import com.iver.cit.gvsig.fmap.layers.XMLException;
53 3183 caballero
import com.iver.cit.gvsig.gui.project.OpenException;
54
import com.iver.cit.gvsig.gui.project.SaveException;
55 1830 fernando
56 1222 fernando
import com.iver.utiles.XMLEntity;
57
58 1830 fernando
import java.beans.PropertyChangeListener;
59
import java.beans.PropertyChangeSupport;
60 1222 fernando
61 1830 fernando
import java.io.Serializable;
62
63
import java.text.DateFormat;
64
65
import java.util.Date;
66
67
68 1222 fernando
/**
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 ProjectElement implements Serializable {
74 1830 fernando
        protected PropertyChangeSupport change;
75
        protected Project project;
76
        protected int index;
77
        protected String name;
78
        protected String creationDate;
79
        protected String owner;
80
        protected String comment;
81 5870 jaume
        private boolean locked = false;
82 5029 cesar
        protected com.iver.andami.ui.mdiManager.View view = null;
83
        // El viewInfo que 'levanto' desde el disco (.gvp)
84
        protected ViewInfo seedViewInfo=null;
85 1222 fernando
86 1830 fernando
        /**
87
         * Creates a new ProjectElement object.
88
         */
89
        public ProjectElement() {
90
                creationDate = DateFormat.getDateInstance().format(new Date());
91
                change = new PropertyChangeSupport(this);
92
        }
93 1222 fernando
94 1830 fernando
        /**
95
         * @see java.lang.Object#toString()
96
         */
97
        public String toString() {
98
                return name;
99
        }
100 1222 fernando
101 1830 fernando
        /**
102
         * Obtiene el nombre del elemento
103
         *
104
         * @return
105
         */
106
        public String getName() {
107
                return name;
108
        }
109 1222 fernando
110 1830 fernando
        /**
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 1222 fernando
121 1830 fernando
        /**
122
         * Obtiene la fecha de creaci?n del elemento
123
         *
124
         * @return
125
         */
126
        public String getCreationDate() {
127
                return creationDate;
128
        }
129 1222 fernando
130 1830 fernando
        /**
131
         * Obtiene el propietario del elemento
132
         *
133
         * @return
134
         */
135
        public String getOwner() {
136
                return owner;
137
        }
138 1222 fernando
139 1830 fernando
        /**
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 1222 fernando
149 1830 fernando
        /**
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 1222 fernando
159 1830 fernando
        /**
160
         * Obtiene los comentarios del proyecto
161
         *
162
         * @return
163
         */
164
        public String getComment() {
165
                return comment;
166
        }
167 1222 fernando
168 1830 fernando
        /**
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 1222 fernando
178 1830 fernando
        /**
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 1222 fernando
188 1830 fernando
        /**
189
         * DOCUMENT ME!
190
         *
191
         * @return DOCUMENT ME!
192
         * @throws XMLException
193 3183 caballero
         * @throws SaveException
194 1830 fernando
         */
195 3183 caballero
        public XMLEntity getXMLEntity() throws SaveException {
196 1830 fernando
                XMLEntity xml = new XMLEntity();
197 3183 caballero
                try{
198 1830 fernando
                xml.putProperty("className", this.getClass().getName());
199
                xml.putProperty("comment", comment);
200
                xml.putProperty("creationDate", creationDate);
201
                xml.putProperty("name", name);
202
                xml.putProperty("owner", owner);
203 3183 caballero
                }catch (Exception e) {
204
                        throw new SaveException(e,this.getClass().getName());
205
                }
206 1830 fernando
                return xml;
207
        }
208 1222 fernando
209 2183 fernando
    /**
210
     * DOCUMENT ME!
211
     *
212
     * @param xml DOCUMENT ME!
213
     * @param p DOCUMENT ME!
214
     *
215
     * @return DOCUMENT ME!
216
     * @throws XMLException
217
     * @throws DriverException
218
     * @throws DriverIOException
219
     * @throws CancelationException
220
     * @throws ClassNotFoundException
221
     * @throws InstantiationException
222
     * @throws IllegalAccessException
223
     * @throws DriverIOException
224
     * @throws DriverLoadException
225
     */
226
    public static ProjectElement createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{
227
        ProjectElement pe = null;
228
229
            Class clase;
230
                        try {
231
                                clase = Class.forName(xml.getStringProperty("className"));
232
                        pe = (ProjectElement) clase.newInstance();
233
                        } catch (ClassNotFoundException e) {
234
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
235
                            e);
236
                        } catch (InstantiationException e) {
237
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
238
                            e);
239
                        } catch (IllegalAccessException e) {
240
                    NotificationManager.addError("Clase de ProjectElement no reconocida",
241
                            e);
242
                        }
243
244
        pe.setComment(xml.getStringProperty("comment"));
245
        pe.setCreationDate(xml.getStringProperty("creationDate"));
246
        pe.setName(xml.getStringProperty("name"));
247
        pe.setOwner(xml.getStringProperty("owner"));
248
        pe.project = p;
249
250
                pe.setXMLEntity03(xml,p);
251
252
        return pe;
253
    }
254
255 1830 fernando
        /**
256
         * DOCUMENT ME!
257
         *
258
         * @param xml DOCUMENT ME!
259
         * @param p DOCUMENT ME!
260
         *
261
         * @return DOCUMENT ME!
262
         *
263
         * @throws XMLException
264
         * @throws DriverException
265
         * @throws DriverIOException
266 3183 caballero
         * @throws OpenException
267 1830 fernando
         */
268
        public static ProjectElement createFromXML(XMLEntity xml, Project p)
269 3183 caballero
                throws XMLException, DriverException, DriverIOException, OpenException {
270 1830 fernando
                ProjectElement pe = null;
271 3183 caballero
                try{
272 1830 fernando
                Class clase;
273
274
                try {
275
                        clase = Class.forName(xml.getStringProperty("className"));
276 1222 fernando
                        pe = (ProjectElement) clase.newInstance();
277 1830 fernando
                } catch (ClassNotFoundException e) {
278
                        NotificationManager.addError("Clase de ProjectElement no reconocida",
279
                                e);
280
                } catch (InstantiationException e) {
281
                        NotificationManager.addError("Clase de ProjectElement no reconocida",
282
                                e);
283
                } catch (IllegalAccessException e) {
284
                        NotificationManager.addError("Clase de ProjectElement no reconocida",
285
                                e);
286
                }
287 1222 fernando
288 1830 fernando
                pe.setComment(xml.getStringProperty("comment"));
289
                pe.setCreationDate(xml.getStringProperty("creationDate"));
290
                pe.setName(xml.getStringProperty("name"));
291
                pe.setOwner(xml.getStringProperty("owner"));
292
                pe.project = p;
293 3183 caballero
                }catch (Exception e) {
294
                        throw new OpenException(e,pe.getClass().getName());
295
                }
296 1830 fernando
                pe.setXMLEntity(xml, p);
297 1222 fernando
298 1830 fernando
                return pe;
299
        }
300 1222 fernando
301 1830 fernando
        /**
302
         * DOCUMENT ME!
303
         *
304
         * @param xml DOCUMENT ME!
305
         * @param p DOCUMENT ME!
306
         *
307
         * @throws XMLException
308
         * @throws DriverException
309
         * @throws DriverIOException
310 3183 caballero
         * @throws OpenException
311 1830 fernando
         */
312
        public abstract void setXMLEntity(XMLEntity xml, Project p)
313 3183 caballero
                throws XMLException, DriverException, DriverIOException, OpenException;
314 1830 fernando
315
        /**
316
         * DOCUMENT ME!
317
         *
318 2183 fernando
         * @param xml DOCUMENT ME!
319
         * @param p DOCUMENT ME!
320
         *
321
         * @throws XMLException
322
         * @throws DriverException
323
         * @throws DriverIOException
324
         */
325
        public abstract void setXMLEntity03(XMLEntity xml, Project p)
326
                throws XMLException, DriverException, DriverIOException;
327
328
        /**
329
         * DOCUMENT ME!
330
         *
331 1830 fernando
         * @return DOCUMENT ME!
332
         */
333 1222 fernando
        public Project getProject() {
334
                return project;
335
        }
336 1830 fernando
337
        /**
338
         * DOCUMENT ME!
339
         *
340
         * @param project DOCUMENT ME!
341
         */
342
        public void setProject(Project project, int index) {
343 1222 fernando
                this.project = project;
344 1830 fernando
                this.index = index;
345 1222 fernando
        }
346 1830 fernando
        public int getIndex() {
347
                return index;
348
        }
349 5029 cesar
350
        public ViewInfo getViewInfo() {
351
                if (view==null)
352
                        return null;
353
                return PluginServices.getMDIManager().getViewInfo(view);
354
        }
355
356
/*        public void setViewInfo(ViewInfo viewInfo) {
357
                this.viewInfo = viewInfo;
358
        }*/
359
360
361
        public com.iver.andami.ui.mdiManager.View getAndamiView() {
362
                return view;
363
        }
364
365
        public void setAndamiView(com.iver.andami.ui.mdiManager.View view) {
366
                this.view = view;
367
        }
368
369
    /**
370
         * DOCUMENT ME!
371
         *
372
         * @return DOCUMENT ME!
373
     * @throws SaveException
374
         * @throws XMLException
375
         * @throws SaveException
376
         */
377
        public XMLEntity getViewInfoXMLEntity() throws SaveException {
378
                if (view!=null && PluginServices.getMDIManager().getViewInfo(view)!=null) {
379
                        ViewInfo vi = PluginServices.getMDIManager().getViewInfo(view);
380
                        XMLEntity xml = new XMLEntity();
381
                        //xml.putProperty("nameClass", this.getClass().getName());
382
                        try{
383
                                xml.setName("ViewInfoProperties");
384
                                xml.putProperty("className", this.getClass().getName());
385
                                xml.putProperty("X", vi.getX());
386
                                xml.putProperty("Y", vi.getY());
387
                                xml.putProperty("Width", vi.getWidth());
388
                                xml.putProperty("Height", vi.getHeight());
389
                                xml.putProperty("isVisible", vi.isVisible());
390
                                xml.putProperty("isResizable", vi.isResizable());
391
                                xml.putProperty("isMaximizable", vi.isMaximizable());
392
                                xml.putProperty("isModal", vi.isModal());
393
                                xml.putProperty("isModeless", vi.isModeless());
394
                                xml.putProperty("isClosed", vi.isClosed());
395
                                if (vi.isMaximized()==true) {
396
                                        xml.putProperty("isMaximized", vi.isMaximized());
397
                                        xml.putProperty("normalX", vi.getNormalX());
398
                                        xml.putProperty("normalY", vi.getNormalY());
399
                                        xml.putProperty("normalWidth", vi.getNormalWidth());
400
                                        xml.putProperty("normalHeight", vi.getNormalHeight());
401
                                }
402
                        }catch (Exception e) {
403
                                throw new SaveException(e,this.getClass().getName());
404
                        }
405
                        return xml;
406
                }
407
                else
408
                        return null;
409
        }
410
411
        public static ViewInfo createViewInfoFromXMLEntity(XMLEntity xml)
412
        {
413
                return Project.createViewInfoFromXMLEntity(xml);
414
        }
415
416
        public ViewInfo getSeedViewInfo() {
417
                return seedViewInfo;
418
        }
419 5870 jaume
420
        /**
421
         * Locks this project element protecting it from deleting from the project.
422
         */
423
        public void lock() {
424
                locked = true;
425
        }
426
427
        /**
428
         * Unlocks this element. So, from now on, it can be removed from the project.
429
         */
430
        public void unlock() {
431
                locked = false;
432
        }
433
434
        /**
435
         * Tells whether if this project's element is locked/protected or not. A protected
436
         * element cannot be removed from the current project.
437
         *
438
         * @see <b>lock()</b> and <b>unlock()</b> methods.
439
         *
440
         * @return true if it is locked, false otherwise
441
         */
442
        public boolean isLocked() {
443
                return locked;
444
        }
445 1222 fernando
}