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