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