Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ProjectExtension.java @ 27352

History | View | Annotate | Download (34.3 KB)

1 1103 fjp
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3 12698 cesar
 * Copyright (C) 2004-2007 IVER T.I. and Generalitat Valenciana.
4 1103 fjp
 *
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 312 fernando
package com.iver.cit.gvsig;
42
43 2242 jaume
import java.awt.Component;
44 6730 caballero
import java.io.BufferedReader;
45 2242 jaume
import java.io.File;
46 8455 cesar
import java.io.FileInputStream;
47 2242 jaume
import java.io.FileNotFoundException;
48 8455 cesar
import java.io.FileOutputStream;
49 2242 jaume
import java.io.FileReader;
50 6730 caballero
import java.io.IOException;
51 8455 cesar
import java.io.InputStream;
52 6730 caballero
import java.io.InputStreamReader;
53 8455 cesar
import java.io.OutputStreamWriter;
54 6730 caballero
import java.io.Reader;
55 8455 cesar
import java.io.UnsupportedEncodingException;
56 6730 caballero
import java.net.MalformedURLException;
57
import java.net.URL;
58 2242 jaume
import java.text.DateFormat;
59 22118 vcaballero
import java.util.ArrayList;
60 2242 jaume
import java.util.Date;
61 7222 jaume
import java.util.prefs.Preferences;
62 2242 jaume
63 12698 cesar
import javax.swing.ImageIcon;
64 2242 jaume
import javax.swing.JOptionPane;
65
66
import org.exolab.castor.xml.MarshalException;
67
import org.exolab.castor.xml.Marshaller;
68
import org.exolab.castor.xml.ValidationException;
69 17441 jdominguez
import org.gvsig.gui.beans.swing.JFileChooser;
70 2242 jaume
71
import com.iver.andami.Launcher;
72 596 fernando
import com.iver.andami.PluginServices;
73 12698 cesar
import com.iver.andami.Launcher.TerminationProcess;
74 692 fernando
import com.iver.andami.messages.NotificationManager;
75 596 fernando
import com.iver.andami.plugins.Extension;
76 12698 cesar
import com.iver.andami.plugins.IExtension;
77
import com.iver.andami.plugins.status.IExtensionStatus;
78
import com.iver.andami.plugins.status.IUnsavedData;
79
import com.iver.andami.plugins.status.UnsavedData;
80 7621 fjp
import com.iver.andami.ui.mdiManager.IWindow;
81 7689 cesar
import com.iver.andami.ui.mdiManager.WindowInfo;
82 12698 cesar
import com.iver.andami.ui.wizard.UnsavedDataPanel;
83 701 fernando
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
84 1221 fernando
import com.iver.cit.gvsig.project.Project;
85 312 fernando
import com.iver.cit.gvsig.project.ProjectFactory;
86 9690 caballero
import com.iver.cit.gvsig.project.documents.ProjectDocument;
87 7304 caballero
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
88 7343 caballero
import com.iver.cit.gvsig.project.documents.gui.ProjectWindow;
89 7304 caballero
import com.iver.cit.gvsig.project.documents.layout.ProjectMap;
90 7343 caballero
import com.iver.cit.gvsig.project.documents.layout.ProjectMapFactory;
91 9392 caballero
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
92 7343 caballero
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
93
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory;
94 596 fernando
import com.iver.utiles.GenericFileFilter;
95 436 vcaballero
import com.iver.utiles.XMLEntity;
96 6635 jmvivo
import com.iver.utiles.extensionPoints.ExtensionPoint;
97
import com.iver.utiles.extensionPoints.ExtensionPoints;
98
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
99 22118 vcaballero
import com.iver.utiles.save.AfterSavingListener;
100
import com.iver.utiles.save.BeforeSavingListener;
101
import com.iver.utiles.save.SaveEvent;
102 12698 cesar
import com.iver.utiles.swing.threads.IMonitorableTask;
103 8455 cesar
import com.iver.utiles.xml.XMLEncodingUtils;
104 436 vcaballero
import com.iver.utiles.xmlEntity.generate.XmlTag;
105 312 fernando
106 1219 vcaballero
107 312 fernando
/**
108
 * Extension que proporciona controles para crear proyectos nuevos, abrirlos y
109
 * guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos
110
 * en esta clase.
111
 *
112
 * @author Fernando Gonz?lez Cort?s
113 22118 vcaballero
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
114 312 fernando
 */
115 12698 cesar
public class ProjectExtension extends Extension implements IExtensionStatus {
116 6876 jaume
        private static String projectPath = null;
117 7304 caballero
        //private ProjectWindow projectFrame;
118 7343 caballero
        private ProjectWindow projectFrame;
119 1219 vcaballero
        private Project p;
120 7426 jaume
        private String lastPath;
121 7385 jaume
        private String lastSavePath;
122 7426 jaume
        private String templatesPath;
123 7689 cesar
        private WindowInfo seedProjectWindow;
124 17441 jdominguez
        public static final String LAYOUT_TEMPLATE_FILECHOOSER_ID = "LAYOUT_TEMPLATE_FILECHOOSER_ID";
125
        public static final String PROJECT_FILE_CHOOSER_ID = "PROJECT_FILECHOOSER_ID";
126 8455 cesar
        /**
127
         * Use UTF-8 for encoding, as it can represent characters from
128
         * any language.
129 8536 jaume
         *
130
         * Another sensible option would be
131 8455 cesar
         * encoding = System.getProperty("file.encoding");
132
         * but this would need some extra testing.
133
         */
134 10365 caballero
        public static String PROJECTENCODING = "UTF-8";
135 8536 jaume
136 1219 vcaballero
        /**
137 22118 vcaballero
         * <p>Identifier of the extension point used by <code>ProjectExtension</code> to manage {@link BeforeSavingListener BeforeSavingListener}s.</p>
138
         */
139
        public static final String BEFORE_SAVING_ID = "Before_Saving_PrjExt";
140
141
        /**
142
         * <p>Identifier of the extension point used by <code>ProjectExtension</code> to manage {@link BeforeSavingListener BeforeSavingListener}s.</p>
143
         */
144
        public static final String AFTER_SAVING_ID = "After_Saving_PrjExt";
145
146
        /**
147 5005 jorpiell
         * @see com.iver.mdiApp.plugins.IExtension#initialize()
148 1219 vcaballero
         */
149 5005 jorpiell
        public void initialize() {
150 2183 fernando
            try {
151
            Class.forName("javax.media.jai.EnumeratedParameter");
152
        } catch (ClassNotFoundException e) {
153
            NotificationManager.addError("La m?quina virtual con la que se ejecuta gvSIG no tiene JAI instalado", e);
154
        }
155 4748 fjp
156
                LayerFactory.setWritersPath(PluginServices.getPluginServices(this)
157 3666 fjp
                                  .getPluginDirectory()
158
                                  .getAbsolutePath() +
159
                                  File.separator + "drivers");
160 6153 caballero
161 4748 fjp
        LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
162 4140 caballero
                                  .getPluginDirectory()
163
                                  .getAbsolutePath() +
164 4748 fjp
                                  File.separator + "drivers");
165 8536 jaume
166 7699 cesar
        initializeDocumentActionsExtensionPoint();
167 7689 cesar
        registerDocuments();
168 4140 caballero
169 3666 fjp
        // Recuperamos el ?ltimo argumento, que se supone
170
        // que ser? el fichero .gvp que queremos abrir.
171 4140 caballero
        // (por enmedio pueden venir o no otros argumentos,
172 3666 fjp
        // por ejemplo el idioma)
173
        // TODO: Aqu? Jaume podr?a meter lo del backup del proyecto
174
        // que ha hecho para ValenciaUrban?stica
175 4140 caballero
176 18046 vcaballero
            registerIcons();
177 14821 jmvivo
178 12207 jcampos
        }
179 14821 jmvivo
180
        private void registerIcons(){
181 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
182 14821 jmvivo
                                "project-new",
183
                                this.getClass().getClassLoader().getResource("images/new.png")
184
                        );
185
186 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
187 14821 jmvivo
                                "project-open",
188
                                this.getClass().getClassLoader().getResource("images/open.png")
189
                        );
190
191 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
192 14821 jmvivo
                                "project-save",
193
                                this.getClass().getClassLoader().getResource("images/save.png")
194
                        );
195
196 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
197 14821 jmvivo
                                "project-save-as",
198
                                this.getClass().getClassLoader().getResource("images/save.png")
199
                        );
200
201 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
202 14821 jmvivo
                                "layout-template-open",
203
                                this.getClass().getClassLoader().getResource("images/opentemplate.png")
204
                        );
205
206 15647 jmvivo
                PluginServices.getIconTheme().registerDefault(
207 14821 jmvivo
                                "application-exit",
208
                                this.getClass().getClassLoader().getResource("images/salir.png")
209
                        );
210
        }
211 18046 vcaballero
        private void loadInitialProject(){
212 12207 jcampos
                String[] theArgs = PluginServices.getArguments();
213 3666 fjp
        String lastArg = theArgs[theArgs.length-1];
214
        if ((lastArg.endsWith(".gvp")) ||
215
                        (lastArg.endsWith(".GVP")))
216
        {
217
                PluginServices.getLogger().debug("Intentando cargar el proyecto " + lastArg);
218 6730 caballero
                //File projectFile = new File(lastArg);
219 10679 jaume
                setProject(readProject(lastArg));
220 3666 fjp
                PluginServices.getMainFrame().setTitle(p.getName());
221 7239 jmvivo
                projectPath = lastArg;
222 3666 fjp
        }
223
        else
224
        {
225 10679 jaume
                        setProject(ProjectFactory.createProject());
226 3666 fjp
                        p.setName(PluginServices.getText(this, "untitled"));
227
                        p.setModified(false);
228
                        PluginServices.getMainFrame().setTitle(PluginServices.getText(this, "sin_titulo"));
229
        }
230 18046 vcaballero
        }
231
        /**
232
         * @see com.iver.mdiApp.plugins.IExtension#postInitialize()
233
         */
234
        public void postInitialize() {
235
                loadInitialProject();
236 8536 jaume
                getProjectFrame().setProject(p);
237 7689 cesar
                p.restoreWindowProperties();
238 1219 vcaballero
        }
239 8536 jaume
240 9248 jjdelcerro
        public ProjectWindow getProjectFrame() {
241 8536 jaume
                if (projectFrame==null)
242
                                projectFrame = new ProjectWindow();
243
                return projectFrame;
244
        }
245 1219 vcaballero
        /**
246
         * Muestra la ventana con el gestor de proyectos.
247
         */
248
        public void showProjectWindow() {
249 7689 cesar
                if (seedProjectWindow!=null) {
250
                        if (seedProjectWindow.isClosed()) {
251
                                // if it was closed, we just don't open the window now
252
                                seedProjectWindow.setClosed(false);
253
                                return;
254
                        }
255
                        WindowInfo winProps = seedProjectWindow;
256
                        seedProjectWindow = null;
257 8536 jaume
                        PluginServices.getMDIManager().addWindow(getProjectFrame());
258
                        PluginServices.getMDIManager().changeWindowInfo(getProjectFrame(), winProps);
259 7689 cesar
                }
260
                else
261 8536 jaume
                        PluginServices.getMDIManager().addWindow(getProjectFrame());
262 312 fernando
        }
263 8536 jaume
264 7689 cesar
        /**
265
         * Muestra la ventana con el gestor de proyectos, con las propiedades
266
         * de ventana especificadas.
267
         */
268
        public void showProjectWindow(WindowInfo wi) {
269
                seedProjectWindow = wi;
270
                showProjectWindow();
271
        }
272 312 fernando
273 1219 vcaballero
        /**
274
         * Guarda el proyecto actual en disco.
275
         */
276 6190 caballero
        private boolean guardar() {
277
                boolean saved=false;
278 6876 jaume
//                if (p.getPath() == null) {
279
                if (projectPath == null) {
280 6190 caballero
                        saved=guardarDialogo();
281 312 fernando
                } else {
282 12698 cesar
                        long t1,t2;
283
                        t1 = System.currentTimeMillis();
284
                        saved=writeProject(new File(projectPath), p, false);
285
                        t2 = System.currentTimeMillis();
286
                        PluginServices.getLogger().info("Project saved. " +  (t2-t1) + " miliseconds");
287 8536 jaume
                        getProjectFrame().refreshControls();
288 312 fernando
                }
289 6190 caballero
                return saved;
290 312 fernando
        }
291 6876 jaume
292 6190 caballero
        private boolean guardarDialogo(){
293
                boolean saved=false;
294 7385 jaume
295
                if (lastSavePath == null)
296
                        lastSavePath = projectPath;
297
298 7444 jaume
299 17441 jdominguez
                Preferences prefs = Preferences.userRoot().node( "gvsig.foldering");
300
                JFileChooser jfc = new JFileChooser(PROJECT_FILE_CHOOSER_ID, prefs.get("ProjectsFolder", null));
301
302 12698 cesar
                jfc.setDialogTitle(PluginServices.getText(this, "guardar_proyecto"));
303 1271 vcaballero
                jfc.addChoosableFileFilter(new GenericFileFilter("gvp",
304 1226 vcaballero
                                PluginServices.getText(this, "tipo_fichero_proyecto")));
305 1219 vcaballero
306 1226 vcaballero
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
307 1254 vcaballero
                        File file=jfc.getSelectedFile();
308 6876 jaume
                        if (!(file.getPath().toLowerCase().endsWith(".gvp"))){
309 1271 vcaballero
                                file=new File(file.getPath()+".gvp");
310 1254 vcaballero
                        }
311 6190 caballero
                        saved=writeProject(file, p);
312 7385 jaume
                        String filePath = file.getAbsolutePath();
313
                        lastSavePath = filePath.substring(0, filePath.lastIndexOf(File.separatorChar));
314
315 8536 jaume
                        getProjectFrame().refreshControls();
316 1226 vcaballero
                }
317 6190 caballero
                return saved;
318 1226 vcaballero
        }
319 12698 cesar
320 1219 vcaballero
        /**
321 12698 cesar
         * Checks whether the project and related unsaved data is modified,
322
         *  and allows the user to save it.
323 1219 vcaballero
         *
324 12698 cesar
         * @return true if the data has been correctly saved, false otherwise
325 1219 vcaballero
         */
326 12698 cesar
        private boolean askSave() {
327 13456 jaume
                if (p != null && p.hasChanged()) {
328 12698 cesar
                        TerminationProcess process = Launcher.getTerminationProcess();
329
                        UnsavedDataPanel panel = process.getUnsavedDataPanel();
330
                        panel.setHeaderText(PluginServices.getText(this, "Select_resources_to_save_before_closing_current_project"));
331
                        panel.setAcceptText(
332
                                        PluginServices.getText(this, "save_resources"),
333
                                        PluginServices.getText(this, "Save_the_selected_resources_and_close_current_project"));
334
                        panel.setCancelText(
335
                                        PluginServices.getText(this, "Dont_close"),
336
                                        PluginServices.getText(this, "Return_to_current_project"));
337
                        int closeCurrProj = process.manageUnsavedData();
338
                        if (closeCurrProj==JOptionPane.NO_OPTION) {
339
                                // the user chose to return to current project
340
                                return false;
341
                        }
342 312 fernando
                }
343 12698 cesar
                return true;
344 312 fernando
        }
345
346 1219 vcaballero
        /**
347 5005 jorpiell
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
348 1219 vcaballero
         */
349
        public void execute(String actionCommand) {
350
                if (actionCommand.equals("NUEVO")) {
351 12698 cesar
                        if (!askSave()) {
352 1219 vcaballero
                                return;
353
                        }
354 14821 jmvivo
355 12698 cesar
                        projectPath=null;
356 9690 caballero
                        ProjectDocument.initializeNUMS();
357 6880 cesar
                        PluginServices.getMDIManager().closeAllWindows();
358 10679 jaume
                        setProject(ProjectFactory.createProject());
359 8536 jaume
                        getProjectFrame().setProject(p);
360 1219 vcaballero
                        showProjectWindow();
361 1412 fernando
                        PluginServices.getMainFrame().setTitle(PluginServices.getText(this, "sin_titulo"));
362 1219 vcaballero
                } else if (actionCommand.equals("ABRIR")) {
363 18046 vcaballero
                        if (!askSave())
364 1219 vcaballero
                                return;
365 4140 caballero
366 17441 jdominguez
                        Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
367
                        JFileChooser jfc = new JFileChooser(PROJECT_FILE_CHOOSER_ID, prefs.get("ProjectsFolder", null));
368 1271 vcaballero
                        jfc.addChoosableFileFilter(new GenericFileFilter("gvp",
369 1219 vcaballero
                                        PluginServices.getText(this, "tipo_fichero_proyecto")));
370
371
                        if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
372 9690 caballero
                                ProjectDocument.initializeNUMS();
373 6880 cesar
                                PluginServices.getMDIManager().closeAllWindows();
374 6876 jaume
375
                                File projectFile = jfc.getSelectedFile();
376
                                Project o = readProject(projectFile);
377
                                setPath(projectFile.getAbsolutePath());
378 7222 jaume
                                lastPath = getPath();
379 1219 vcaballero
                                if (o != null) {
380 10679 jaume
                                        setProject(o);
381 596 fernando
                                }
382 312 fernando
383 8536 jaume
                                getProjectFrame().setProject(p);
384 1412 fernando
                                PluginServices.getMainFrame().setTitle(p.getName());
385 8536 jaume
                                getProjectFrame().refreshControls();
386 11360 caballero
387 10679 jaume
//jaume                                p.setModified(true);
388 7689 cesar
                                p.restoreWindowProperties();
389 1219 vcaballero
                        }
390
                } else if (actionCommand.equals("GUARDAR")) {
391
                        guardar();
392 10679 jaume
//jaume                        p.setModified(false);
393 1226 vcaballero
                } else if (actionCommand.equals("GUARDAR_COMO")) {
394
                        guardarDialogo();
395 10679 jaume
//jaume                        p.setModified(false);
396 2242 jaume
                } else if (actionCommand.equals("SALIR")){
397 12698 cesar
                        Launcher.closeApplication();
398 3115 caballero
                } else if (actionCommand.compareTo("OPENTEMPLATE")==0){
399
                        openLayout();
400 10679 jaume
//jaume                        p.setModified(true);
401 1219 vcaballero
                }
402
        }
403 3115 caballero
        public void openLayout() {
404 3135 caballero
                //Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
405 3115 caballero
                Layout layout=null;
406 7426 jaume
407
                if (templatesPath == null) {
408
                        Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
409
                        templatesPath = prefs.get("TemplatesFolder", null);
410
                }
411
412 17441 jdominguez
                JFileChooser jfc = new JFileChooser(LAYOUT_TEMPLATE_FILECHOOSER_ID, templatesPath);
413 3115 caballero
                jfc.addChoosableFileFilter(new GenericFileFilter("gvt",
414
                                PluginServices.getText(this, "plantilla")));
415 312 fernando
416 3115 caballero
                if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
417
                        File file=jfc.getSelectedFile();
418
                        if (!(file.getPath().endsWith(".gvt") || file.getPath().endsWith(".GVT"))){
419
                                file=new File(file.getPath()+".gvt");
420
                        }
421
                        try {
422
                                File xmlFile = new File(file.getAbsolutePath());
423 18780 vcaballero
                                FileInputStream is = new FileInputStream(xmlFile);
424
                                Reader reader = XMLEncodingUtils.getReader(is);
425 3115 caballero
426
                                XmlTag tag = (XmlTag) XmlTag.unmarshal(reader);
427 3185 caballero
                                try {
428 18780 vcaballero
                                        XMLEntity xml=new XMLEntity(tag);
429
                                        if (xml.contains("followHeaderEncoding")) {
430
                                                layout = Layout.createLayout(xml,p);
431
                                        }
432
                                        else {
433
                                                reader = new FileReader(xmlFile);
434
                                                tag = (XmlTag) XmlTag.unmarshal(reader);
435
                                                xml=new XMLEntity(tag);
436
                                                layout = Layout.createLayout(xml,p);
437
                                        }
438
439 3185 caballero
                                } catch (OpenException e) {
440
                                        e.showError();
441
                                }
442 3115 caballero
                                //fPanelLegendManager.setRenderer(LegendFactory.createFromXML(new XMLEntity(tag)));
443
                        } catch (FileNotFoundException e) {
444
                                NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e);
445
                        } catch (MarshalException e) {
446 5503 cesar
                                NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e);
447 3115 caballero
                        } catch (ValidationException e) {
448 5503 cesar
                                NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e);
449 3115 caballero
                        }
450
                        ProjectMap pmap = ProjectFactory.createMap(file.getName());
451
                        pmap.setModel(layout);
452
                        pmap.getModel().setProjectMap(pmap);
453 7304 caballero
                        p.addDocument(pmap);
454 6880 cesar
                        PluginServices.getMDIManager().addWindow(layout);
455 4140 caballero
456
457 3115 caballero
                }
458
        }
459 1219 vcaballero
        /**
460
         * Escribe el proyecto en XML.
461
         *
462
         * @param file Fichero.
463
         * @param p Proyecto.
464
         */
465 6190 caballero
        public boolean writeProject(File file, Project p) {
466 8801 jaume
                return writeProject(file, p, true);
467
        }
468
469 8803 jaume
        /**
470
         * Escribe el proyecto en XML. Pero permite decidir si se
471
         * pide confirmaci?n para sobreescribir
472
         *
473
         * @param file Fichero.
474
         * @param p Proyecto.
475
         * @param askConfirmation boolean
476
         */
477 8802 jaume
        public boolean writeProject(File file, Project p, boolean askConfirmation) {
478
                if( askConfirmation && file.exists()){
479 6153 caballero
                        int resp = JOptionPane.showConfirmDialog(
480
                                        (Component) PluginServices.getMainFrame(),PluginServices.getText(this,"fichero_ya_existe_seguro_desea_guardarlo"),
481
                                        PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION);
482
                        if (resp != JOptionPane.YES_OPTION) {
483 6190 caballero
                                return false;
484 6153 caballero
                        }
485
                }
486 16775 vcaballero
                NotificationManager.addInfo(PluginServices.getText(this,"writinng_project")+ ": "+file.getName());
487 1219 vcaballero
                // write it out as XML
488 596 fernando
                try {
489 22118 vcaballero
                        fireBeforeSavingFileEvent(new SaveEvent(this, SaveEvent.BEFORE_SAVING, file));
490 8455 cesar
            FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
491 10365 caballero
            OutputStreamWriter writer = new OutputStreamWriter(fos, PROJECTENCODING);
492 1219 vcaballero
                        Marshaller m = new Marshaller(writer);
493 10365 caballero
                        m.setEncoding(PROJECTENCODING);
494 1254 vcaballero
                        p.setName(file.getName());
495 6876 jaume
                        // p.setPath(file.toString());
496 1219 vcaballero
                        p.setModificationDate(DateFormat.getDateInstance().format(new Date()));
497
                        p.setModified(false);
498 8455 cesar
                        XMLEntity xml = p.getXMLEntity();
499 10679 jaume
                        xml.putProperty("followHeaderEncoding", true, false);
500 8455 cesar
                        m.marshal(xml.getXmlTag());
501 22118 vcaballero
                        fireAfterSavingFileEvent(new SaveEvent(this, SaveEvent.AFTER_SAVING, file));
502 1412 fernando
                        PluginServices.getMainFrame().setTitle(file.getName());
503 6876 jaume
                        setPath(file.toString());
504
505 1219 vcaballero
                } catch (Exception e) {
506 23634 vcaballero
                        JOptionPane.showMessageDialog(
507
                                        (Component) PluginServices.getMainFrame(),PluginServices.getText(this,"error_writing_project")+":\n-"
508 23637 vcaballero
                                        + PluginServices.getText(this,"the_user_cannot_edit_the_project_because_it_has_not_write_permissions")+".",
509 23634 vcaballero
                                        PluginServices.getText(this,"warning"), JOptionPane.OK_OPTION);
510
//                        NotificationManager.addError(PluginServices.getText(this,"error_writing_project")+ ": "+file.getName(), e);
511 6190 caballero
                        return false;
512 1219 vcaballero
                }
513 16775 vcaballero
                NotificationManager.addInfo(PluginServices.getText(this,"wrote_project")+ ": "+file.getName());
514 6190 caballero
                return true;
515 1219 vcaballero
        }
516
517 6730 caballero
        public Project readProject(String path) {
518
                BufferedReader reader =null;
519
                try {
520
                URL url=null;
521
                        url = new URL(path);
522 8455 cesar
                        String encoding = XMLEncodingUtils.getEncoding(url.openStream());
523
                        InputStream is = url.openStream();
524
                        if (encoding!=null) {
525
                                Project proj=null;
526
                                try {
527
                                        reader = new BufferedReader(new InputStreamReader(is, encoding));
528
                                        proj=readProject(reader, true);
529
                                } catch (UnsupportedEncodingException e) {
530
                                        reader = new BufferedReader(new InputStreamReader(is));
531
                                        try {
532
                                                Project p=readProject(reader, false);
533
                                        } catch (UnsupportedEncodingException e1) {
534
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage()));
535 8536 jaume
                                                return null;
536 8455 cesar
                                        }
537
                                }
538
                                ProjectExtension.setPath(path);
539
                                return proj;
540
                        }
541
                        else {
542
                                reader = new BufferedReader(new InputStreamReader(is));
543
                                Project p;
544
                                try {
545
                                        p = readProject(reader, false);
546
                                } catch (UnsupportedEncodingException e) {
547
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e.getLocalizedMessage()));
548
                                        return null;
549
                                }
550
                                ProjectExtension.setPath(path); //p.setPath(null);
551
                                return p;
552
                        }
553 6730 caballero
                } catch (MalformedURLException e) {
554
                        File file=new File(path);
555
                        return readProject(file);
556
                } catch (IOException e) {
557
                        e.printStackTrace();
558 8455 cesar
                        return null;
559 6730 caballero
                }
560
        }
561
562 8455 cesar
        /**
563
         * Lee del XML el proyecto.<br><br>
564
         *
565
         * Reads the XML of the project.<br>
566
         * It returns a project object holding all needed info that is not linked to the Project Dialog. <br>In case you want the project to be
567
         * linked to the window you must set this object to the extension:<br>
568
         *
569
         * <b>Example:</b><br>
570
         *
571
         * ...<br>
572
         * ...<br>
573
         * Project p = ProjectExtension.readProject(projectFile);<br>
574
         * ProjectExtension.setProject(p);
575
         * ...<br>
576
         * ...<br>
577
         * @param file Fichero.
578
         *
579
         * @return Project
580
         *
581
         */
582 6730 caballero
        public Project readProject(File file) {
583
                File xmlFile = new File(file.getAbsolutePath());
584
                try {
585 8455 cesar
                        String encoding = XMLEncodingUtils.getEncoding(new FileInputStream(xmlFile));
586
                        InputStreamReader reader=null;
587
                        if (encoding!=null) {
588
                                try {
589
                                        reader = new InputStreamReader(new FileInputStream(xmlFile), encoding);
590
                                        return readProject(reader, true);
591
                                } catch (UnsupportedEncodingException e) {
592
                                        reader = new InputStreamReader(new FileInputStream(xmlFile));
593
                                        try {
594
                                                return readProject(reader, false);
595
                                        } catch (UnsupportedEncodingException e1) {
596
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage()));
597
                                                return null;
598
                                        }
599
                                }
600
                        }
601
                        else {
602
                                reader = new InputStreamReader(new FileInputStream(xmlFile));
603
                                try {
604
                                        return readProject(reader, false);
605
                                } catch (UnsupportedEncodingException e1) {
606
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage()));
607
                                        return null;
608
                                }
609
                        }
610 6730 caballero
                } catch (FileNotFoundException e) {
611
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "fichero_incorrecto"));
612
                        return null;
613
                }
614 8455 cesar
        }
615 8536 jaume
616 1219 vcaballero
        /**
617 2922 jaume
         * Lee del XML el proyecto.<br><br>
618 4140 caballero
         *
619 2922 jaume
         * Reads the XML of the project.<br>
620 8455 cesar
         * It returns a project object holding all needed info that is not linked to the Project Dialog. <br>In case you want the project to be
621
         * linked to the window you must set this object to the extension:<br>
622 4140 caballero
         *
623 2922 jaume
         * <b>Example:</b><br>
624 4140 caballero
         *
625 2922 jaume
         * ...<br>
626
         * ...<br>
627 3666 fjp
         * Project p = ProjectExtension.readProject(projectFile);<br>
628 2922 jaume
         * ProjectExtension.setProject(p);
629
         * ...<br>
630
         * ...<br>
631 8455 cesar
         * @param reader File reader
632
         * @param encodingFollowed Whether the encoded specified in the xml header was followed
633
         * when creating the reader. If the property followHeaderEncoding is false or not set,
634
         * then the encoding should have not been used when creating the reader, so it must be
635
         * recreated.
636 8536 jaume
         *
637 2922 jaume
         * @return Project
638 8536 jaume
         * @throws UnsupportedEncodingException
639 4140 caballero
         *
640 312 fernando
         */
641 9213 fdiaz
        public Project readProject(Reader reader, boolean encodingFollowed) throws UnsupportedEncodingException {
642 1219 vcaballero
                Project proj = null;
643
644
                try {
645 2183 fernando
                        XmlTag tag = (XmlTag) XmlTag.unmarshal(reader);
646 3167 caballero
                        XMLEntity xml=new XMLEntity(tag);
647
                        String VERSION=xml.getStringProperty("VERSION");
648 16775 vcaballero
                        NotificationManager.addInfo(PluginServices.getText(this,"openning_project")+ ": "+xml.getStringProperty("name"));
649 8536 jaume
650 8455 cesar
                        if (encodingFollowed) {
651
                                if (xml.contains("followHeaderEncoding")) {
652
                                        boolean useEncoding = xml.getBooleanProperty("followHeaderEncoding");
653
                                        if (!useEncoding) {
654
                                                throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe");
655
                                        }
656
                                }
657
                                else {
658
                                        // Old projects didn't contain followHeaderEncoding and they were
659
                                        // not correctly encoded. We throw an exception now, and we'll try
660
                                        // to reopen the project
661 8536 jaume
                                        // using the default system encoding.
662 8455 cesar
                                        throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe");
663
                                }
664
                        }
665 8536 jaume
666 2183 fernando
                        try {
667 3810 fjp
                                // if ((VERSION!=null) && (VERSION.equals("0.5") || VERSION.equals("0.4") || (VERSION.indexOf("GISPLANET") != -1))){
668
                                if (VERSION != null) {
669 3167 caballero
                                        proj = Project.createFromXML(xml);
670
                                }else{
671
                                        proj = Project.createFromXML03(new XMLEntity(tag));
672
                                }
673 16775 vcaballero
                                NotificationManager.addInfo(PluginServices.getText(this,"opened_project")+ ": "+xml.getStringProperty("name"));
674
675 2183 fernando
                                return proj;
676 3185 caballero
                        } catch (OpenException e){
677
                                e.showError();
678
                                //NotificationManager.addInfo("Al leer el proyecto", e);
679 3167 caballero
                        }
680 6730 caballero
                }  catch (MarshalException e) {
681 9237 caballero
                        PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e);
682 2695 nacho
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto"));
683 2419 caballero
                        //NotificationManager.addError("Al leer el proyecto", e);
684 1219 vcaballero
                } catch (ValidationException e) {
685 9213 fdiaz
                        PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e);
686 2695 nacho
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto"));
687 2419 caballero
                        //NotificationManager.addError("Al leer el proyecto", e);
688 4140 caballero
                }
689 16775 vcaballero
                NotificationManager.addInfo(PluginServices.getText(this,"error_openning_project"));
690
691 2183 fernando
                return null;
692 1219 vcaballero
        }
693
694
        /**
695
         * Devuelve el proyecto.
696
         *
697
         * @return Proyecto.
698
         */
699 312 fernando
        public Project getProject() {
700
                return p;
701
        }
702
703 596 fernando
        /**
704 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#isEnabled()
705 596 fernando
         */
706
        public boolean isEnabled() {
707
                return true;
708
        }
709
710
        /**
711 5005 jorpiell
         * @see com.iver.andami.plugins.IExtension#isVisible()
712 596 fernando
         */
713
        public boolean isVisible() {
714
                return true;
715
        }
716 4140 caballero
717 2879 jaume
        /**
718 2922 jaume
         * Sets the project
719 2879 jaume
         * @param p
720
         */
721 2922 jaume
        public void setProject(Project p){
722 8536 jaume
                getProjectFrame().setProject(p);
723 2922 jaume
                this.p=p;
724 2879 jaume
        }
725 6190 caballero
726 7304 caballero
        private void registerDocuments() {
727 7343 caballero
                ProjectViewFactory.register();
728
                ProjectTableFactory.register();
729
                ProjectMapFactory.register();
730 7304 caballero
        }
731 11360 caballero
732 7699 cesar
        private void initializeDocumentActionsExtensionPoint() {
733 6730 caballero
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
734 6672 jmvivo
                if (!extensionPoints.containsKey("DocumentActions_View")) {
735
                        extensionPoints.put(
736
                                new ExtensionPoint(
737
                                        "DocumentActions_View",
738 6730 caballero
                                        "Context menu options of the view document list" +
739
                                                " in the project window "+
740 6672 jmvivo
                                                "(register instances of " +
741
                                                "com.iver.cit.gvsig.project.AbstractDocumentContextMenuAction)"
742
                                )
743 6730 caballero
                        );
744 6672 jmvivo
                }
745
                if (!extensionPoints.containsKey("DocumentActions_Table")) {
746
                        extensionPoints.put(
747
                                new ExtensionPoint(
748
                                        "DocumentActions_Table",
749 6730 caballero
                                        "Context menu options of the table document list" +
750
                                                " in the project window "+
751 6672 jmvivo
                                                "(register instances of " +
752
                                                "com.iver.cit.gvsig.project.AbstractDocumentContextMenuAction)"
753
                                )
754
                        );
755
                }
756
                if (!extensionPoints.containsKey("DocumentActions_Map")) {
757
                        extensionPoints.put(
758
                                new ExtensionPoint(
759
                                        "DocumentActions_Map",
760 6730 caballero
                                        "Context menu options of the map document list" +
761
                                                " in the project window "+
762 6672 jmvivo
                                                "(register instances of " +
763
                                                "com.iver.cit.gvsig.project.AbstractDocumentContextMenuAction)"
764
                                )
765
                        );
766
                }
767 6635 jmvivo
        }
768 6876 jaume
769
        public static String getPath() {
770
                return projectPath;
771
        }
772
773
        public static void setPath(String path) {
774
                projectPath = path;
775
        }
776
777 7608 cesar
        public IWindow getProjectWindow() {
778 8536 jaume
                return getProjectFrame();
779 7608 cesar
        }
780 14821 jmvivo
781
782 12698 cesar
        public IExtensionStatus getStatus() {
783
                return this;
784
        }
785 14821 jmvivo
786 12698 cesar
        public boolean hasUnsavedData() {
787
                return p.hasChanged();
788
        }
789 14821 jmvivo
790 12698 cesar
        public IUnsavedData[] getUnsavedData() {
791
                if (hasUnsavedData()) {
792
                        UnsavedProject data = new UnsavedProject(this);
793
                        IUnsavedData[] dataArray = {data};
794
                        return dataArray;
795
                }
796
                else
797
                        return null;
798
        }
799 14821 jmvivo
800 12698 cesar
        /**
801
         * Implements the IUnsavedData interface to show unsaved projects
802
         * in the Unsavad Data dialog.
803 14821 jmvivo
         *
804 12698 cesar
         * @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
805
         */
806
        public class UnsavedProject  extends UnsavedData {
807 14821 jmvivo
808 12698 cesar
                public UnsavedProject(IExtension extension) {
809
                        super(extension);
810
                }
811
812
                public String getDescription() {
813
                        if (getPath()==null) {
814
                                return PluginServices.getText(ProjectExtension.this, "Unnamed_new_gvsig_project_");
815
                        }
816
                        else {
817
                                return PluginServices.getText(ProjectExtension.this, "Modified_project_");
818
                        }
819
                }
820
821
                public String getResourceName() {
822
                        if (getPath()==null) {
823
                                return PluginServices.getText(ProjectExtension.this, "Unnamed");
824
                        }
825
                        else {
826
                                return getPath();
827
                        }
828 14821 jmvivo
829 12698 cesar
                }
830
831
                public boolean saveData() {
832
                        return guardar();
833
                }
834 14821 jmvivo
835 12698 cesar
                public ImageIcon getIcon() {
836
                        try {
837
                                URL imagePath = PluginServices.getPluginServices(ProjectExtension.this).getClassLoader().getResource("images/logoGVA.gif");
838
                                return new ImageIcon(imagePath);
839
                        }
840
                        catch (Exception ex) {}
841
                        return null;
842
                }
843
        }
844
845
        public IMonitorableTask[] getRunningProcesses() {
846
                // TODO Auto-generated method stub
847
                return null;
848
        }
849
        public boolean hasRunningProcesses() {
850
                // TODO Auto-generated method stub
851
                return false;
852
        }
853 23634 vcaballero
854 22118 vcaballero
    /**
855
     * Adds the specified before saving listener to receive "before saving file events" from
856
     * this component.
857
     * If l is null, no exception is thrown and no action is performed.
858 23634 vcaballero
     *
859 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
860
     *
861
     * @param    l the before saving listener.
862
     * @see      SaveEvent
863
     * @see      BeforeSavingListener
864
     * @see      #removeListener(BeforeSavingListener)
865
     * @see      #getBeforeSavingListeners
866
     */
867
    public synchronized void addListener(BeforeSavingListener l) {
868
        if (l == null) {
869
            return;
870
        }
871 12698 cesar
872 22118 vcaballero
        ExtensionPoints ePs = ((ExtensionPoints) ExtensionPointsSingleton.getInstance());
873
874
        if (ePs.get(BEFORE_SAVING_ID) == null) {
875
                ArrayList aL = new ArrayList();
876
                aL.add(l);
877
878
                ePs.add(BEFORE_SAVING_ID, "", aL);
879
                return;
880
        }
881
882
        ((ArrayList)((ExtensionPoint)ePs.get(BEFORE_SAVING_ID)).get("")).add(l);
883
    }
884 23634 vcaballero
885 22118 vcaballero
    /**
886
     * Adds the specified after saving listener to receive "after saving file events" from
887
     * this component.
888
     * If l is null, no exception is thrown and no action is performed.
889 23634 vcaballero
     *
890 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
891 23634 vcaballero
     *
892 22118 vcaballero
     * @param    l the after saving listener.
893
     * @see      SaveEvent
894
     * @see      AfterSavingListener
895
     * @see      #removeListener(AfterSavingListener)
896
     * @see      #getAfterSavingListeners()
897
     */
898
    public synchronized void addListener(AfterSavingListener l) {
899
        if (l == null) {
900
            return;
901
        }
902
903
        ExtensionPoints ePs = ((ExtensionPoints) ExtensionPointsSingleton.getInstance());
904
905
        if (ePs.get(AFTER_SAVING_ID) == null) {
906
                ArrayList aL = new ArrayList();
907
                aL.add(l);
908
909
                ePs.add(AFTER_SAVING_ID, "", aL);
910
                return;
911
        }
912
913
        ((ArrayList)((ExtensionPoint)ePs.get(AFTER_SAVING_ID)).get("")).add(l);
914
    }
915
916
    /**
917
     * Returns an array of all the before saving listeners
918
     * registered on this component.
919 23634 vcaballero
     *
920 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
921 23634 vcaballero
     *
922 22118 vcaballero
     * @return all of this component's <code>BeforeSavingListener</code>s
923
     *         or an empty array if no key
924
     *         listeners are currently registered
925
     *
926
     * @see      #addBeforeSavingListener(BeforeSavingListener)
927
     * @see      #removeBeforeSavingListener(BeforeSavingListener)
928
     */
929
    public synchronized BeforeSavingListener[] getBeforeSavingListeners() {
930
            ExtensionPoint eP = (ExtensionPoint)((ExtensionPoints) ExtensionPointsSingleton.getInstance()).get(BEFORE_SAVING_ID);
931 23634 vcaballero
932 22118 vcaballero
            if (eP == null)
933
                    return null;
934 23634 vcaballero
935 22118 vcaballero
            return eP.get("") == null ? null : (BeforeSavingListener[]) ((ArrayList)eP.get("")).toArray(new BeforeSavingListener[0]);
936
    }
937
938
    /**
939
     * Returns an array of all the after saving listeners
940
     * registered on this component.
941 23634 vcaballero
     *
942 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
943 23634 vcaballero
     *
944 22118 vcaballero
     * @return all of this component's <code>AfterSavingListener</code>s
945
     *         or an empty array if no key
946
     *         listeners are currently registered
947
     *
948
     * @see      #addAfterSavingListener(AfterSavingListener)
949
     * @see      #removeAfterSavingListener
950
     */
951
    public synchronized AfterSavingListener[] getAfterSavingListeners() {
952
            ExtensionPoint eP = (ExtensionPoint)((ExtensionPoints) ExtensionPointsSingleton.getInstance()).get(AFTER_SAVING_ID);
953
954
            if (eP == null)
955
                    return null;
956
957
            return eP.get("") == null ? null : (AfterSavingListener[]) ((ArrayList)eP.get("")).toArray(new AfterSavingListener[0]);
958
    }
959
960
    /**
961
     * Removes the specified before saving listener so that it no longer
962 23634 vcaballero
     * receives save file events from this component. This method performs
963
     * no function, nor does it throw an exception, if the listener
964 22118 vcaballero
     * specified by the argument was not previously added to this component.
965
     * If listener <code>l</code> is <code>null</code>,
966
     * no exception is thrown and no action is performed.
967 23634 vcaballero
     *
968 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
969 23634 vcaballero
     *
970 22118 vcaballero
     * @param    l   the before saving listener
971
     * @see      SaveEvent
972
     * @see      BeforeSavingListener
973
     * @see      #addListener(BeforeSavingListener)
974
     * @see      #getBeforeSavingListeners()
975
     */
976
    public synchronized void removeListener(BeforeSavingListener l) {
977
        if (l == null) {
978
            return;
979
        }
980
981
        ExtensionPoint eP = (ExtensionPoint)((ExtensionPoints) ExtensionPointsSingleton.getInstance()).get(BEFORE_SAVING_ID);
982
983
        if (eP != null) {
984 23634 vcaballero
                ((ArrayList)eP.get("")).remove(l);
985 22118 vcaballero
        }
986
    }
987
988
    /**
989
     * Removes the specified after saving listener so that it no longer
990 23634 vcaballero
     * receives save file events from this component. This method performs
991
     * no function, nor does it throw an exception, if the listener
992 22118 vcaballero
     * specified by the argument was not previously added to this component.
993
     * If listener <code>l</code> is <code>null</code>,
994
     * no exception is thrown and no action is performed.
995 23634 vcaballero
     *
996 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
997 23634 vcaballero
     *
998 22118 vcaballero
     * @param    l   the after saving listener
999
     * @see      SaveEvent
1000
     * @see      AfterSavingListener
1001
     * @see      #addListener(AfterSavingListener)
1002
     * @see      #getAfterSavingListeners()
1003
     */
1004
    public synchronized void removeListener(AfterSavingListener l) {
1005
        if (l == null) {
1006
            return;
1007
        }
1008
1009
        ExtensionPoint eP = (ExtensionPoint)((ExtensionPoints) ExtensionPointsSingleton.getInstance()).get(AFTER_SAVING_ID);
1010
1011
        if (eP != null) {
1012 23634 vcaballero
                ((ArrayList)eP.get("")).remove(l);
1013 22118 vcaballero
        }
1014
    }
1015
1016
    /**
1017
     * Reports a before saving file event.
1018 23634 vcaballero
     *
1019 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
1020 23634 vcaballero
     *
1021 22118 vcaballero
     * @param evt the before saving file event
1022
     */
1023
    protected void fireBeforeSavingFileEvent(SaveEvent evt) {
1024
        if ((evt.getID() != SaveEvent.BEFORE_SAVING) || (evt.getFile() == null)) {
1025
            return;
1026
        }
1027 23634 vcaballero
1028 22118 vcaballero
        ExtensionPoint eP = (ExtensionPoint)((ExtensionPoints) ExtensionPointsSingleton.getInstance()).get(BEFORE_SAVING_ID);
1029
1030
        if (eP != null) {
1031
                ArrayList listeners = ((ArrayList)eP.get(""));
1032
1033
                for (int i = 0; i < listeners.size(); i++)
1034
                                ((BeforeSavingListener)listeners.get(i)).beforeSaving(evt);
1035
        }
1036
    }
1037
1038
    /**
1039
     * Reports a after saving file event.
1040 23634 vcaballero
     *
1041 22118 vcaballero
     * @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
1042 23634 vcaballero
     *
1043 22118 vcaballero
     * @param evt the after saving file event
1044
     */
1045
    protected void fireAfterSavingFileEvent(SaveEvent evt) {
1046
        if ((evt.getID() != SaveEvent.AFTER_SAVING) || (evt.getFile() == null)) {
1047
            return;
1048
        }
1049
1050
        ExtensionPoint eP = (ExtensionPoint)((ExtensionPoints) ExtensionPointsSingleton.getInstance()).get(AFTER_SAVING_ID);
1051
1052
        if (eP != null) {
1053
                ArrayList listeners = ((ArrayList)eP.get(""));
1054
1055
                for (int i = 0; i < listeners.size(); i++)
1056
                                ((AfterSavingListener)listeners.get(i)).afterSaving(evt);
1057
        }
1058
    }
1059 312 fernando
}