svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ProjectExtension.java @ 41050
History | View | Annotate | Download (24.2 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.extension; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.io.File; |
28 |
import java.text.MessageFormat; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Iterator; |
31 |
import java.util.List; |
32 |
import java.util.prefs.Preferences; |
33 |
|
34 |
import javax.swing.JOptionPane; |
35 |
|
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.andami.IconThemeHelper; |
40 |
import org.gvsig.andami.Launcher; |
41 |
import org.gvsig.andami.Launcher.TerminationProcess; |
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.messages.NotificationManager; |
44 |
import org.gvsig.andami.plugins.Extension; |
45 |
import org.gvsig.andami.plugins.IExtension; |
46 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
47 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
48 |
import org.gvsig.andami.plugins.status.UnsavedData; |
49 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
50 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
51 |
import org.gvsig.andami.ui.wizard.UnsavedDataPanel; |
52 |
import org.gvsig.app.project.Project; |
53 |
import org.gvsig.app.project.ProjectManager; |
54 |
import org.gvsig.app.project.documents.gui.ProjectWindow; |
55 |
import org.gvsig.app.project.documents.view.ViewManager; |
56 |
import org.gvsig.gui.beans.swing.JFileChooser; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
59 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
60 |
import org.gvsig.utils.GenericFileFilter; |
61 |
import org.gvsig.utils.save.AfterSavingListener; |
62 |
import org.gvsig.utils.save.BeforeSavingListener; |
63 |
import org.gvsig.utils.save.SaveEvent; |
64 |
import org.gvsig.utils.swing.threads.IMonitorableTask; |
65 |
|
66 |
/**
|
67 |
* Extension que proporciona controles para crear proyectos nuevos, abrirlos y
|
68 |
* guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos
|
69 |
* en esta clase.
|
70 |
*
|
71 |
* @author Fernando Gonz?lez Cort?s
|
72 |
*/
|
73 |
public class ProjectExtension extends Extension implements IExtensionStatus { |
74 |
private static final Logger LOG = |
75 |
LoggerFactory.getLogger(ProjectExtension.class); |
76 |
|
77 |
private static String projectPath = null; |
78 |
private ProjectWindow projectFrame;
|
79 |
private Project p;
|
80 |
private String lastSavePath; |
81 |
private WindowInfo seedProjectWindow;
|
82 |
public static final String PROJECT_FILE_CHOOSER_ID = |
83 |
"PROJECT_FILECHOOSER_ID";
|
84 |
/**
|
85 |
* Use UTF-8 for encoding, as it can represent characters from
|
86 |
* any language.
|
87 |
*
|
88 |
* Another sensible option would be
|
89 |
* encoding = System.getProperty("file.encoding");
|
90 |
* but this would need some extra testing.
|
91 |
*
|
92 |
* @deprecated see PersistentManager
|
93 |
*/
|
94 |
public static String PROJECTENCODING = "UTF-8"; |
95 |
|
96 |
private List<BeforeSavingListener> beforeSavingListeners = |
97 |
new ArrayList<BeforeSavingListener>(); |
98 |
|
99 |
private List<AfterSavingListener> afterSavingListeners = |
100 |
new ArrayList<AfterSavingListener>(); |
101 |
|
102 |
/**
|
103 |
* @see com.iver.mdiApp.plugins.IExtension#initialize()
|
104 |
*/
|
105 |
public void initialize() { |
106 |
// try {
|
107 |
// Class.forName("javax.media.jai.EnumeratedParameter");
|
108 |
// } catch (ClassNotFoundException e) {
|
109 |
// NotificationManager
|
110 |
// .addError(
|
111 |
// "La m?quina virtual con la que se ejecuta gvSIG no tiene JAI instalado",
|
112 |
// e);
|
113 |
// }
|
114 |
|
115 |
initializeDocumentActionsExtensionPoint(); |
116 |
registerIcons(); |
117 |
} |
118 |
|
119 |
private void registerIcons() { |
120 |
IconThemeHelper.registerIcon("action", "application-project-new", this); |
121 |
IconThemeHelper.registerIcon("action", "application-project-open", this); |
122 |
IconThemeHelper.registerIcon("action", "application-project-save", this); |
123 |
IconThemeHelper.registerIcon("action", "application-project-save-as", this); |
124 |
|
125 |
IconThemeHelper.registerIcon("project", "project-icon", this); |
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 |
|
138 |
int last_bar = lastArg.lastIndexOf(File.separator); |
139 |
String tit = lastArg.substring(last_bar);
|
140 |
|
141 |
PluginServices.getMainFrame().setTitle(tit); |
142 |
projectPath = lastArg; |
143 |
} else {
|
144 |
setProject(ProjectManager.getInstance().createProject()); |
145 |
p.setName(PluginServices.getText(this, "untitled")); |
146 |
p.setModified(false);
|
147 |
PluginServices.getMainFrame().setTitle( |
148 |
PluginServices.getText(this, "sin_titulo")); |
149 |
} |
150 |
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* @see com.iver.mdiApp.plugins.IExtension#postInitialize()
|
155 |
*/
|
156 |
public void postInitialize() { |
157 |
registerDocuments(); |
158 |
loadInitialProject(); |
159 |
getProjectFrame().setProject(p); |
160 |
showProjectWindow(); |
161 |
} |
162 |
|
163 |
public ProjectWindow getProjectFrame() {
|
164 |
if (projectFrame == null) { |
165 |
projectFrame = new ProjectWindow();
|
166 |
} |
167 |
return projectFrame;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* Muestra la ventana con el gestor de proyectos.
|
172 |
*/
|
173 |
public void showProjectWindow() { |
174 |
if (seedProjectWindow != null) { |
175 |
if (seedProjectWindow.isClosed()) {
|
176 |
// if it was closed, we just don't open the window now
|
177 |
seedProjectWindow.setClosed(false);
|
178 |
return;
|
179 |
} |
180 |
WindowInfo winProps = seedProjectWindow; |
181 |
seedProjectWindow = null;
|
182 |
PluginServices.getMDIManager().addWindow(getProjectFrame()); |
183 |
PluginServices.getMDIManager().changeWindowInfo(getProjectFrame(), |
184 |
winProps); |
185 |
} else {
|
186 |
PluginServices.getMDIManager().addWindow(getProjectFrame()); |
187 |
} |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Muestra la ventana con el gestor de proyectos, con las propiedades
|
192 |
* de ventana especificadas.
|
193 |
*/
|
194 |
public void showProjectWindow(WindowInfo wi) { |
195 |
seedProjectWindow = wi; |
196 |
showProjectWindow(); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Guarda el proyecto actual en disco.
|
201 |
*/
|
202 |
private boolean guardar() { |
203 |
boolean saved = false; |
204 |
// if (p.getPath() == null) {
|
205 |
if (projectPath == null) { |
206 |
saved = guardarDialogo(); |
207 |
} else {
|
208 |
long t1, t2;
|
209 |
t1 = System.currentTimeMillis();
|
210 |
saved = writeProject(new File(projectPath), p, false); |
211 |
t2 = System.currentTimeMillis();
|
212 |
PluginServices.getLogger().info( |
213 |
"Project saved. " + (t2 - t1) + " miliseconds"); |
214 |
getProjectFrame().refreshControls(); |
215 |
} |
216 |
return saved;
|
217 |
} |
218 |
|
219 |
private boolean guardarDialogo() { |
220 |
boolean saved = false; |
221 |
|
222 |
if (lastSavePath == null) { |
223 |
lastSavePath = projectPath; |
224 |
} |
225 |
|
226 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
227 |
JFileChooser jfc =
|
228 |
new JFileChooser(PROJECT_FILE_CHOOSER_ID, prefs.get( |
229 |
"ProjectsFolder", null)); |
230 |
|
231 |
jfc.setDialogTitle(PluginServices.getText(this, "guardar_proyecto")); |
232 |
jfc.addChoosableFileFilter(new GenericFileFilter(
|
233 |
Project.FILE_EXTENSION, MessageFormat.format(
|
234 |
PluginServices.getText(this, "tipo_fichero_proyecto"), |
235 |
Project.FILE_EXTENSION))); |
236 |
|
237 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
238 |
File file = jfc.getSelectedFile();
|
239 |
if (!(file.getPath().toLowerCase().endsWith(Project.FILE_EXTENSION
|
240 |
.toLowerCase()))) { |
241 |
file = new File(file.getPath() + Project.FILE_EXTENSION); |
242 |
} |
243 |
saved = writeProject(file, p); |
244 |
String filePath = file.getAbsolutePath();
|
245 |
lastSavePath = |
246 |
filePath.substring(0, filePath.lastIndexOf(File.separatorChar)); |
247 |
|
248 |
getProjectFrame().refreshControls(); |
249 |
} |
250 |
return saved;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Checks whether the project and related unsaved data is modified,
|
255 |
* and allows the user to save it.
|
256 |
*
|
257 |
* @return true if the data has been correctly saved, false otherwise
|
258 |
*/
|
259 |
private boolean askSave() { |
260 |
if (p != null && p.hasChanged()) { |
261 |
TerminationProcess process = Launcher.getTerminationProcess(); |
262 |
UnsavedDataPanel panel = process.getUnsavedDataPanel(); |
263 |
panel.setHeaderText(PluginServices.getText(this,
|
264 |
"_Select_resources_to_save_before_closing_current_project"));
|
265 |
panel.setAcceptText(PluginServices.getText(this, "save_resources"), |
266 |
PluginServices.getText(this,
|
267 |
"Save_the_selected_resources_and_close_current_project"));
|
268 |
panel.setCancelText(PluginServices.getText(this, "Cancel"), |
269 |
PluginServices.getText(this, "Return_to_current_project")); |
270 |
int closeCurrProj;
|
271 |
try {
|
272 |
closeCurrProj = process.manageUnsavedData(); |
273 |
if (closeCurrProj == JOptionPane.NO_OPTION) { |
274 |
// the user chose to return to current project
|
275 |
return false; |
276 |
} |
277 |
} catch (Exception e) { |
278 |
LOG.error("Some data can not be saved", e);
|
279 |
} |
280 |
} |
281 |
return true; |
282 |
} |
283 |
|
284 |
/**
|
285 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
286 |
*/
|
287 |
public void execute(String actionCommand) { |
288 |
if (actionCommand.equals("application-project-new")) { |
289 |
if (!askSave()) {
|
290 |
return;
|
291 |
} |
292 |
|
293 |
projectPath = null;
|
294 |
// ProjectDocument.initializeNUMS();
|
295 |
PluginServices.getMDIManager().closeAllWindows(); |
296 |
setProject(ProjectManager.getInstance().createProject()); |
297 |
getProjectFrame().setProject(p); |
298 |
showProjectWindow(); |
299 |
PluginServices.getMainFrame().setTitle( |
300 |
PluginServices.getText(this, "sin_titulo")); |
301 |
} else if (actionCommand.equals("application-project-open")) { |
302 |
if (!askSave()) {
|
303 |
return;
|
304 |
} |
305 |
|
306 |
Preferences prefs =
|
307 |
Preferences.userRoot().node("gvsig.foldering"); |
308 |
JFileChooser jfc =
|
309 |
new JFileChooser(PROJECT_FILE_CHOOSER_ID, prefs.get( |
310 |
"ProjectsFolder", null)); |
311 |
jfc.addChoosableFileFilter(new GenericFileFilter(
|
312 |
Project.FILE_EXTENSION, PluginServices.getText(this,
|
313 |
"tipo_fichero_proyecto")));
|
314 |
|
315 |
if (jfc.showOpenDialog((Component) PluginServices |
316 |
.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
317 |
// ProjectDocument.initializeNUMS();
|
318 |
PluginServices.getMDIManager().closeAllWindows(); |
319 |
|
320 |
File projectFile = jfc.getSelectedFile();
|
321 |
Project o = readProject(projectFile); |
322 |
setPath(projectFile.getAbsolutePath()); |
323 |
// lastPath = getPath();
|
324 |
if (o != null) { |
325 |
setProject(o); |
326 |
} |
327 |
|
328 |
getProjectFrame().setProject(p); |
329 |
PluginServices.getMainFrame().setTitle(projectFile.getName()); |
330 |
getProjectFrame().refreshControls(); |
331 |
|
332 |
// p.restoreWindowProperties();
|
333 |
} |
334 |
} else if (actionCommand.equals("application-project-save")) { |
335 |
guardar(); |
336 |
} else if (actionCommand.equals("application-project-save-as")) { |
337 |
guardarDialogo(); |
338 |
} |
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(file.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 |
} |