svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ProjectExtension.java @ 37546
History | View | Annotate | Download (24.6 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.extension; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.io.File; |
26 |
import java.text.MessageFormat; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
import java.util.prefs.Preferences; |
31 |
|
32 |
import javax.swing.JOptionPane; |
33 |
|
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
import org.gvsig.andami.Launcher; |
38 |
import org.gvsig.andami.Launcher.TerminationProcess; |
39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.messages.NotificationManager; |
41 |
import org.gvsig.andami.plugins.Extension; |
42 |
import org.gvsig.andami.plugins.IExtension; |
43 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
44 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
45 |
import org.gvsig.andami.plugins.status.UnsavedData; |
46 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
47 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
48 |
import org.gvsig.andami.ui.wizard.UnsavedDataPanel; |
49 |
import org.gvsig.app.project.Project; |
50 |
import org.gvsig.app.project.ProjectManager; |
51 |
import org.gvsig.app.project.documents.gui.ProjectWindow; |
52 |
import org.gvsig.app.project.documents.view.ViewManager; |
53 |
import org.gvsig.gui.beans.swing.JFileChooser; |
54 |
import org.gvsig.tools.ToolsLocator; |
55 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
56 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
57 |
import org.gvsig.utils.GenericFileFilter; |
58 |
import org.gvsig.utils.save.AfterSavingListener; |
59 |
import org.gvsig.utils.save.BeforeSavingListener; |
60 |
import org.gvsig.utils.save.SaveEvent; |
61 |
import org.gvsig.utils.swing.threads.IMonitorableTask; |
62 |
|
63 |
/**
|
64 |
* Extension que proporciona controles para crear proyectos nuevos, abrirlos y
|
65 |
* guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos
|
66 |
* en esta clase.
|
67 |
*
|
68 |
* @author Fernando Gonz?lez Cort?s
|
69 |
*/
|
70 |
public class ProjectExtension extends Extension implements IExtensionStatus { |
71 |
private static final Logger LOG = |
72 |
LoggerFactory.getLogger(ProjectExtension.class); |
73 |
|
74 |
private static String projectPath = null; |
75 |
private ProjectWindow projectFrame;
|
76 |
private Project p;
|
77 |
private String lastSavePath; |
78 |
private WindowInfo seedProjectWindow;
|
79 |
public static final String PROJECT_FILE_CHOOSER_ID = |
80 |
"PROJECT_FILECHOOSER_ID";
|
81 |
/**
|
82 |
* Use UTF-8 for encoding, as it can represent characters from
|
83 |
* any language.
|
84 |
*
|
85 |
* Another sensible option would be
|
86 |
* encoding = System.getProperty("file.encoding");
|
87 |
* but this would need some extra testing.
|
88 |
*
|
89 |
* @deprecated see PersistentManager
|
90 |
*/
|
91 |
public static String PROJECTENCODING = "UTF-8"; |
92 |
|
93 |
private List<BeforeSavingListener> beforeSavingListeners = |
94 |
new ArrayList<BeforeSavingListener>(); |
95 |
|
96 |
private List<AfterSavingListener> afterSavingListeners = |
97 |
new ArrayList<AfterSavingListener>(); |
98 |
|
99 |
/**
|
100 |
* @see com.iver.mdiApp.plugins.IExtension#initialize()
|
101 |
*/
|
102 |
public void initialize() { |
103 |
try {
|
104 |
Class.forName("javax.media.jai.EnumeratedParameter"); |
105 |
} catch (ClassNotFoundException e) { |
106 |
NotificationManager |
107 |
.addError( |
108 |
"La m?quina virtual con la que se ejecuta gvSIG no tiene JAI instalado",
|
109 |
e); |
110 |
} |
111 |
|
112 |
initializeDocumentActionsExtensionPoint(); |
113 |
registerIcons(); |
114 |
} |
115 |
|
116 |
private void registerIcons() { |
117 |
PluginServices.getIconTheme().registerDefault("project-new",
|
118 |
this.getClass().getClassLoader().getResource("images/new.png")); |
119 |
|
120 |
PluginServices.getIconTheme().registerDefault("project-open",
|
121 |
this.getClass().getClassLoader().getResource("images/open.png")); |
122 |
|
123 |
PluginServices.getIconTheme().registerDefault("project-save",
|
124 |
this.getClass().getClassLoader().getResource("images/save.png")); |
125 |
|
126 |
PluginServices.getIconTheme().registerDefault("project-save-as",
|
127 |
this.getClass().getClassLoader().getResource("images/save.png")); |
128 |
|
129 |
PluginServices.getIconTheme().registerDefault("application-exit",
|
130 |
this.getClass().getClassLoader().getResource("images/salir.png")); |
131 |
} |
132 |
|
133 |
private void loadInitialProject() { |
134 |
String[] theArgs = PluginServices.getArguments(); |
135 |
String lastArg = theArgs[theArgs.length - 1]; |
136 |
if ((lastArg.toLowerCase().endsWith(Project.FILE_EXTENSION
|
137 |
.toLowerCase()))) { |
138 |
PluginServices.getLogger().debug( |
139 |
"Intentando cargar el proyecto " + lastArg);
|
140 |
// File projectFile = new File(lastArg);
|
141 |
setProject(readProject(lastArg)); |
142 |
PluginServices.getMainFrame().setTitle(p.getName()); |
143 |
projectPath = lastArg; |
144 |
} else {
|
145 |
setProject(ProjectManager.getInstance().createProject()); |
146 |
p.setName(PluginServices.getText(this, "untitled")); |
147 |
p.setModified(false);
|
148 |
PluginServices.getMainFrame().setTitle( |
149 |
PluginServices.getText(this, "sin_titulo")); |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* @see com.iver.mdiApp.plugins.IExtension#postInitialize()
|
156 |
*/
|
157 |
public void postInitialize() { |
158 |
registerDocuments(); |
159 |
loadInitialProject(); |
160 |
getProjectFrame().setProject(p); |
161 |
showProjectWindow(); |
162 |
} |
163 |
|
164 |
public ProjectWindow getProjectFrame() {
|
165 |
if (projectFrame == null) { |
166 |
projectFrame = new ProjectWindow();
|
167 |
} |
168 |
return projectFrame;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Muestra la ventana con el gestor de proyectos.
|
173 |
*/
|
174 |
public void showProjectWindow() { |
175 |
if (seedProjectWindow != null) { |
176 |
if (seedProjectWindow.isClosed()) {
|
177 |
// if it was closed, we just don't open the window now
|
178 |
seedProjectWindow.setClosed(false);
|
179 |
return;
|
180 |
} |
181 |
WindowInfo winProps = seedProjectWindow; |
182 |
seedProjectWindow = null;
|
183 |
PluginServices.getMDIManager().addWindow(getProjectFrame()); |
184 |
PluginServices.getMDIManager().changeWindowInfo(getProjectFrame(), |
185 |
winProps); |
186 |
} else {
|
187 |
PluginServices.getMDIManager().addWindow(getProjectFrame()); |
188 |
} |
189 |
} |
190 |
|
191 |
/**
|
192 |
* Muestra la ventana con el gestor de proyectos, con las propiedades
|
193 |
* de ventana especificadas.
|
194 |
*/
|
195 |
public void showProjectWindow(WindowInfo wi) { |
196 |
seedProjectWindow = wi; |
197 |
showProjectWindow(); |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Guarda el proyecto actual en disco.
|
202 |
*/
|
203 |
private boolean guardar() { |
204 |
boolean saved = false; |
205 |
// if (p.getPath() == null) {
|
206 |
if (projectPath == null) { |
207 |
saved = guardarDialogo(); |
208 |
} else {
|
209 |
long t1, t2;
|
210 |
t1 = System.currentTimeMillis();
|
211 |
saved = writeProject(new File(projectPath), p, false); |
212 |
t2 = System.currentTimeMillis();
|
213 |
PluginServices.getLogger().info( |
214 |
"Project saved. " + (t2 - t1) + " miliseconds"); |
215 |
getProjectFrame().refreshControls(); |
216 |
} |
217 |
return saved;
|
218 |
} |
219 |
|
220 |
private boolean guardarDialogo() { |
221 |
boolean saved = false; |
222 |
|
223 |
if (lastSavePath == null) { |
224 |
lastSavePath = projectPath; |
225 |
} |
226 |
|
227 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
228 |
JFileChooser jfc =
|
229 |
new JFileChooser(PROJECT_FILE_CHOOSER_ID, prefs.get( |
230 |
"ProjectsFolder", null)); |
231 |
|
232 |
jfc.setDialogTitle(PluginServices.getText(this, "guardar_proyecto")); |
233 |
jfc.addChoosableFileFilter(new GenericFileFilter(
|
234 |
Project.FILE_EXTENSION, MessageFormat.format(
|
235 |
PluginServices.getText(this, "_gvSIG_file_project_({0})"), |
236 |
Project.FILE_EXTENSION))); |
237 |
|
238 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
239 |
File file = jfc.getSelectedFile();
|
240 |
if (!(file.getPath().toLowerCase().endsWith(Project.FILE_EXTENSION
|
241 |
.toLowerCase()))) { |
242 |
file = new File(file.getPath() + Project.FILE_EXTENSION); |
243 |
} |
244 |
saved = writeProject(file, p); |
245 |
String filePath = file.getAbsolutePath();
|
246 |
lastSavePath = |
247 |
filePath.substring(0, filePath.lastIndexOf(File.separatorChar)); |
248 |
|
249 |
getProjectFrame().refreshControls(); |
250 |
} |
251 |
return saved;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* Checks whether the project and related unsaved data is modified,
|
256 |
* and allows the user to save it.
|
257 |
*
|
258 |
* @return true if the data has been correctly saved, false otherwise
|
259 |
*/
|
260 |
private boolean askSave() { |
261 |
if (p != null && p.hasChanged()) { |
262 |
TerminationProcess process = Launcher.getTerminationProcess(); |
263 |
UnsavedDataPanel panel = process.getUnsavedDataPanel(); |
264 |
panel.setHeaderText(PluginServices.getText(this,
|
265 |
"Select_resources_to_save_before_closing_current_project"));
|
266 |
panel.setAcceptText(PluginServices.getText(this, "save_resources"), |
267 |
PluginServices.getText(this,
|
268 |
"Save_the_selected_resources_and_close_current_project"));
|
269 |
panel.setCancelText(PluginServices.getText(this, "Dont_close"), |
270 |
PluginServices.getText(this, "Return_to_current_project")); |
271 |
int closeCurrProj;
|
272 |
try {
|
273 |
closeCurrProj = process.manageUnsavedData(); |
274 |
if (closeCurrProj == JOptionPane.NO_OPTION) { |
275 |
// the user chose to return to current project
|
276 |
return false; |
277 |
} |
278 |
} catch (Exception e) { |
279 |
LOG.error("Some data can not be saved", e);
|
280 |
} |
281 |
} |
282 |
return true; |
283 |
} |
284 |
|
285 |
/**
|
286 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
287 |
*/
|
288 |
public void execute(String actionCommand) { |
289 |
if (actionCommand.equals("NUEVO")) { |
290 |
if (!askSave()) {
|
291 |
return;
|
292 |
} |
293 |
|
294 |
projectPath = null;
|
295 |
// ProjectDocument.initializeNUMS();
|
296 |
PluginServices.getMDIManager().closeAllWindows(); |
297 |
setProject(ProjectManager.getInstance().createProject()); |
298 |
getProjectFrame().setProject(p); |
299 |
showProjectWindow(); |
300 |
PluginServices.getMainFrame().setTitle( |
301 |
PluginServices.getText(this, "sin_titulo")); |
302 |
} else
|
303 |
if (actionCommand.equals("ABRIR")) { |
304 |
if (!askSave()) {
|
305 |
return;
|
306 |
} |
307 |
|
308 |
Preferences prefs =
|
309 |
Preferences.userRoot().node("gvsig.foldering"); |
310 |
JFileChooser jfc =
|
311 |
new JFileChooser(PROJECT_FILE_CHOOSER_ID, prefs.get( |
312 |
"ProjectsFolder", null)); |
313 |
jfc.addChoosableFileFilter(new GenericFileFilter(
|
314 |
Project.FILE_EXTENSION, PluginServices.getText(this,
|
315 |
"tipo_fichero_proyecto")));
|
316 |
|
317 |
if (jfc.showOpenDialog((Component) PluginServices |
318 |
.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
319 |
// ProjectDocument.initializeNUMS();
|
320 |
PluginServices.getMDIManager().closeAllWindows(); |
321 |
|
322 |
File projectFile = jfc.getSelectedFile();
|
323 |
Project o = readProject(projectFile); |
324 |
setPath(projectFile.getAbsolutePath()); |
325 |
// lastPath = getPath();
|
326 |
if (o != null) { |
327 |
setProject(o); |
328 |
} |
329 |
|
330 |
getProjectFrame().setProject(p); |
331 |
PluginServices.getMainFrame().setTitle(p.getName()); |
332 |
getProjectFrame().refreshControls(); |
333 |
|
334 |
// p.restoreWindowProperties();
|
335 |
} |
336 |
} else
|
337 |
if (actionCommand.equals("GUARDAR")) { |
338 |
guardar(); |
339 |
} else
|
340 |
if (actionCommand.equals("GUARDAR_COMO")) { |
341 |
guardarDialogo(); |
342 |
} else
|
343 |
if (actionCommand.equals("SALIR")) { |
344 |
Launcher.closeApplication(); |
345 |
} |
346 |
} |
347 |
|
348 |
/**
|
349 |
* Escribe el proyecto en XML.
|
350 |
*
|
351 |
* @param file
|
352 |
* Fichero.
|
353 |
* @param p
|
354 |
* Proyecto.
|
355 |
*/
|
356 |
public boolean writeProject(File file, Project p) { |
357 |
return writeProject(file, p, true); |
358 |
} |
359 |
|
360 |
/**
|
361 |
* Escribe el proyecto en XML. Pero permite decidir si se
|
362 |
* pide confirmaci?n para sobreescribir
|
363 |
*
|
364 |
* @param file
|
365 |
* Fichero.
|
366 |
* @param p
|
367 |
* Proyecto.
|
368 |
* @param askConfirmation
|
369 |
* boolean
|
370 |
*/
|
371 |
public boolean writeProject(File file, Project p, boolean askConfirmation) { |
372 |
if (askConfirmation && file.exists()) {
|
373 |
int resp =
|
374 |
JOptionPane.showConfirmDialog((Component) PluginServices |
375 |
.getMainFrame(), PluginServices.getText(this,
|
376 |
"fichero_ya_existe_seguro_desea_guardarlo"), PluginServices
|
377 |
.getText(this, "guardar"), JOptionPane.YES_NO_OPTION); |
378 |
if (resp != JOptionPane.YES_OPTION) { |
379 |
return false; |
380 |
} |
381 |
} |
382 |
NotificationManager.addInfo(PluginServices.getText(this,
|
383 |
"writinng_project") + ": " + file.getName()); |
384 |
|
385 |
// write it out as XML
|
386 |
try {
|
387 |
fireBeforeSavingFileEvent(new SaveEvent(this, |
388 |
SaveEvent.BEFORE_SAVING, file)); |
389 |
p.saveState(file); |
390 |
fireAfterSavingFileEvent(new SaveEvent(this, |
391 |
SaveEvent.AFTER_SAVING, file)); |
392 |
PluginServices.getMainFrame().setTitle(file.getName()); |
393 |
setPath(file.toString()); |
394 |
|
395 |
} catch (PersistenceException e) {
|
396 |
String messagestack = e.getLocalizedMessageStack();
|
397 |
NotificationManager.addError( |
398 |
PluginServices.getText(this, "error_writing_project") + ": " |
399 |
+ file.getName() + "\n" + messagestack, e);
|
400 |
return false; |
401 |
} catch (Exception e) { |
402 |
NotificationManager.addError( |
403 |
PluginServices.getText(this, "error_writing_project") + ": " |
404 |
+ file.getName(), e); |
405 |
return false; |
406 |
} |
407 |
NotificationManager.addInfo(PluginServices.getText(this,
|
408 |
"wrote_project") + ": " + file.getName()); |
409 |
return true; |
410 |
} |
411 |
|
412 |
public Project readProject(String path) { |
413 |
Project project = ProjectManager.getInstance().createProject(); |
414 |
|
415 |
project.loadState(new File(path)); |
416 |
return (Project) project;
|
417 |
} |
418 |
|
419 |
/**
|
420 |
* Lee del XML el proyecto.<br>
|
421 |
* <br>
|
422 |
*
|
423 |
* Reads the XML of the project.<br>
|
424 |
* It returns a project object holding all needed info that is not linked to
|
425 |
* the Project Dialog. <br>
|
426 |
* In case you want the project to be
|
427 |
* linked to the window you must set this object to the extension:<br>
|
428 |
*
|
429 |
* <b>Example:</b><br>
|
430 |
*
|
431 |
* ...<br>
|
432 |
* ...<br>
|
433 |
* Project p = ProjectExtension.readProject(projectFile);<br>
|
434 |
* ProjectExtension.setProject(p);
|
435 |
* ...<br>
|
436 |
* ...<br>
|
437 |
*
|
438 |
* @param file
|
439 |
* Fichero.
|
440 |
*
|
441 |
* @return Project
|
442 |
*
|
443 |
*/
|
444 |
public Project readProject(File file) { |
445 |
Project project = ProjectManager.getInstance().createProject(); |
446 |
|
447 |
project.loadState(file); |
448 |
return (Project) project;
|
449 |
} |
450 |
|
451 |
/**
|
452 |
* Devuelve el proyecto.
|
453 |
*
|
454 |
* @return Proyecto.
|
455 |
*/
|
456 |
public Project getProject() {
|
457 |
return p;
|
458 |
} |
459 |
|
460 |
/**
|
461 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
462 |
*/
|
463 |
public boolean isEnabled() { |
464 |
return true; |
465 |
} |
466 |
|
467 |
/**
|
468 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
469 |
*/
|
470 |
public boolean isVisible() { |
471 |
return true; |
472 |
} |
473 |
|
474 |
/**
|
475 |
* Sets the project
|
476 |
*
|
477 |
* @param p
|
478 |
*/
|
479 |
public void setProject(Project p) { |
480 |
getProjectFrame().setProject(p); |
481 |
this.p = p;
|
482 |
} |
483 |
|
484 |
private void registerDocuments() { |
485 |
ViewManager.register(); |
486 |
} |
487 |
|
488 |
private void initializeDocumentActionsExtensionPoint() { |
489 |
ExtensionPointManager epMan = ToolsLocator.getExtensionPointManager(); |
490 |
epMan.add("DocumentActions_View",
|
491 |
"Context menu options of the view document list"
|
492 |
+ " in the project window " + "(register instances of " |
493 |
+ "org.gvsig.app.project.AbstractDocumentContextMenuAction)");
|
494 |
} |
495 |
|
496 |
public static String getPath() { |
497 |
return projectPath;
|
498 |
} |
499 |
|
500 |
public static void setPath(String path) { |
501 |
projectPath = path; |
502 |
} |
503 |
|
504 |
public IWindow getProjectWindow() {
|
505 |
return getProjectFrame();
|
506 |
} |
507 |
|
508 |
public IExtensionStatus getStatus() {
|
509 |
return this; |
510 |
} |
511 |
|
512 |
public boolean hasUnsavedData() { |
513 |
return p.hasChanged();
|
514 |
} |
515 |
|
516 |
public IUnsavedData[] getUnsavedData() { |
517 |
if (hasUnsavedData()) {
|
518 |
UnsavedProject data = new UnsavedProject(this); |
519 |
IUnsavedData[] dataArray = { data };
|
520 |
return dataArray;
|
521 |
} else {
|
522 |
return null; |
523 |
} |
524 |
} |
525 |
|
526 |
/**
|
527 |
* Implements the IUnsavedData interface to show unsaved projects
|
528 |
* in the Unsavad Data dialog.
|
529 |
*
|
530 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
|
531 |
*/
|
532 |
public class UnsavedProject extends UnsavedData { |
533 |
|
534 |
public UnsavedProject(IExtension extension) {
|
535 |
super(extension);
|
536 |
} |
537 |
|
538 |
public String getDescription() { |
539 |
if (getPath() == null) { |
540 |
return PluginServices.getText(ProjectExtension.this,
|
541 |
"Unnamed_new_gvsig_project_");
|
542 |
} else {
|
543 |
return PluginServices.getText(ProjectExtension.this,
|
544 |
"Modified_project_");
|
545 |
} |
546 |
} |
547 |
|
548 |
public String getResourceName() { |
549 |
if (getPath() == null) { |
550 |
return PluginServices.getText(ProjectExtension.this, "Unnamed"); |
551 |
} else {
|
552 |
return getPath();
|
553 |
} |
554 |
|
555 |
} |
556 |
|
557 |
public boolean saveData() { |
558 |
return guardar();
|
559 |
} |
560 |
|
561 |
public String getIcon() { |
562 |
return "images/logoGVA.gif"; |
563 |
} |
564 |
} |
565 |
|
566 |
public IMonitorableTask[] getRunningProcesses() { |
567 |
// TODO Auto-generated method stub
|
568 |
return null; |
569 |
} |
570 |
|
571 |
public boolean hasRunningProcesses() { |
572 |
// TODO Auto-generated method stub
|
573 |
return false; |
574 |
} |
575 |
|
576 |
/**
|
577 |
* Adds the specified before saving listener to receive
|
578 |
* "before saving file events" from
|
579 |
* this component.
|
580 |
* If l is null, no exception is thrown and no action is performed.
|
581 |
*
|
582 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
583 |
*
|
584 |
* @param l
|
585 |
* the before saving listener.
|
586 |
* @see SaveEvent
|
587 |
* @see BeforeSavingListener
|
588 |
* @see #removeListener(BeforeSavingListener)
|
589 |
* @see #getBeforeSavingListeners
|
590 |
*/
|
591 |
public synchronized void addListener(BeforeSavingListener l) { |
592 |
if (l == null) { |
593 |
return;
|
594 |
} |
595 |
if (!this.beforeSavingListeners.contains(l)) { |
596 |
this.beforeSavingListeners.add(l);
|
597 |
} |
598 |
} |
599 |
|
600 |
/**
|
601 |
* Adds the specified after saving listener to receive
|
602 |
* "after saving file events" from
|
603 |
* this component.
|
604 |
* If l is null, no exception is thrown and no action is performed.
|
605 |
*
|
606 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
607 |
*
|
608 |
* @param l
|
609 |
* the after saving listener.
|
610 |
* @see SaveEvent
|
611 |
* @see AfterSavingListener
|
612 |
* @see #removeListener(AfterSavingListener)
|
613 |
* @see #getAfterSavingListeners()
|
614 |
*/
|
615 |
public synchronized void addListener(AfterSavingListener l) { |
616 |
if (l == null) { |
617 |
return;
|
618 |
} |
619 |
|
620 |
if (!this.afterSavingListeners.contains(l)) { |
621 |
this.afterSavingListeners.add(l);
|
622 |
} |
623 |
|
624 |
} |
625 |
|
626 |
/**
|
627 |
* Returns an array of all the before saving listeners
|
628 |
* registered on this component.
|
629 |
*
|
630 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
631 |
*
|
632 |
* @return all of this component's <code>BeforeSavingListener</code>s
|
633 |
* or an empty array if no key
|
634 |
* listeners are currently registered
|
635 |
*
|
636 |
* @see #addBeforeSavingListener(BeforeSavingListener)
|
637 |
* @see #removeBeforeSavingListener(BeforeSavingListener)
|
638 |
*/
|
639 |
public synchronized BeforeSavingListener[] getBeforeSavingListeners() { |
640 |
return this.beforeSavingListeners |
641 |
.toArray(new BeforeSavingListener[] {}); |
642 |
} |
643 |
|
644 |
/**
|
645 |
* Returns an array of all the after saving listeners
|
646 |
* registered on this component.
|
647 |
*
|
648 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
649 |
*
|
650 |
* @return all of this component's <code>AfterSavingListener</code>s
|
651 |
* or an empty array if no key
|
652 |
* listeners are currently registered
|
653 |
*
|
654 |
* @see #addAfterSavingListener(AfterSavingListener)
|
655 |
* @see #removeAfterSavingListener
|
656 |
*/
|
657 |
public synchronized AfterSavingListener[] getAfterSavingListeners() { |
658 |
return this.afterSavingListeners.toArray(new AfterSavingListener[] {}); |
659 |
|
660 |
} |
661 |
|
662 |
/**
|
663 |
* Removes the specified before saving listener so that it no longer
|
664 |
* receives save file events from this component. This method performs
|
665 |
* no function, nor does it throw an exception, if the listener
|
666 |
* specified by the argument was not previously added to this component.
|
667 |
* If listener <code>l</code> is <code>null</code>,
|
668 |
* no exception is thrown and no action is performed.
|
669 |
*
|
670 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
671 |
*
|
672 |
* @param l
|
673 |
* the before saving listener
|
674 |
* @see SaveEvent
|
675 |
* @see BeforeSavingListener
|
676 |
* @see #addListener(BeforeSavingListener)
|
677 |
* @see #getBeforeSavingListeners()
|
678 |
*/
|
679 |
public synchronized void removeListener(BeforeSavingListener l) { |
680 |
if (l == null) { |
681 |
return;
|
682 |
} |
683 |
|
684 |
this.beforeSavingListeners.remove(l);
|
685 |
} |
686 |
|
687 |
/**
|
688 |
* Removes the specified after saving listener so that it no longer
|
689 |
* receives save file events from this component. This method performs
|
690 |
* no function, nor does it throw an exception, if the listener
|
691 |
* specified by the argument was not previously added to this component.
|
692 |
* If listener <code>l</code> is <code>null</code>,
|
693 |
* no exception is thrown and no action is performed.
|
694 |
*
|
695 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
696 |
*
|
697 |
* @param l
|
698 |
* the after saving listener
|
699 |
* @see SaveEvent
|
700 |
* @see AfterSavingListener
|
701 |
* @see #addListener(AfterSavingListener)
|
702 |
* @see #getAfterSavingListeners()
|
703 |
*/
|
704 |
public synchronized void removeListener(AfterSavingListener l) { |
705 |
if (l == null) { |
706 |
return;
|
707 |
} |
708 |
|
709 |
this.afterSavingListeners.remove(l);
|
710 |
} |
711 |
|
712 |
/**
|
713 |
* Reports a before saving file event.
|
714 |
*
|
715 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
716 |
*
|
717 |
* @param evt
|
718 |
* the before saving file event
|
719 |
*/
|
720 |
protected void fireBeforeSavingFileEvent(SaveEvent evt) { |
721 |
if ((evt.getID() != SaveEvent.BEFORE_SAVING) || (evt.getFile() == null)) { |
722 |
return;
|
723 |
} |
724 |
|
725 |
Iterator<BeforeSavingListener> iter =
|
726 |
this.beforeSavingListeners.iterator();
|
727 |
|
728 |
while (iter.hasNext()) {
|
729 |
iter.next().beforeSaving(evt); |
730 |
} |
731 |
} |
732 |
|
733 |
/**
|
734 |
* Reports a after saving file event.
|
735 |
*
|
736 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es>
|
737 |
*
|
738 |
* @param evt
|
739 |
* the after saving file event
|
740 |
*/
|
741 |
protected void fireAfterSavingFileEvent(SaveEvent evt) { |
742 |
if ((evt.getID() != SaveEvent.AFTER_SAVING) || (evt.getFile() == null)) { |
743 |
return;
|
744 |
} |
745 |
Iterator<AfterSavingListener> iter =
|
746 |
this.afterSavingListeners.iterator();
|
747 |
|
748 |
while (iter.hasNext()) {
|
749 |
iter.next().afterSaving(evt); |
750 |
} |
751 |
|
752 |
} |
753 |
} |