001: package net.sourceforge.squirrel_sql.client.mainframe.action;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.Frame;
022: import java.awt.event.ActionEvent;
023: import java.io.File;
024:
025: import javax.swing.BorderFactory;
026: import javax.swing.JLabel;
027:
028: import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
029: import net.sourceforge.squirrel_sql.fw.gui.ErrorDialog;
030: import net.sourceforge.squirrel_sql.fw.util.FileExtensionFilter;
031: import net.sourceforge.squirrel_sql.fw.util.ICommand;
032: import net.sourceforge.squirrel_sql.fw.util.ListMessageHandler;
033: import net.sourceforge.squirrel_sql.fw.util.StringManager;
034: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
035: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
036: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
037:
038: import net.sourceforge.squirrel_sql.client.IApplication;
039: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
040:
041: /**
042: * This <CODE>Action</CODE> dumps the current session status to an XML file.
043: *
044: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
045: */
046: public class DumpApplicationAction extends SquirrelAction {
047: /** Internationalized strings for this class. */
048: private static final StringManager s_stringMgr = StringManagerFactory
049: .getStringManager(DumpApplicationAction.class);
050:
051: /** Logger for this class. */
052: private final static ILogger s_log = LoggerController
053: .createLogger(DumpApplicationAction.class);
054:
055: /**
056: * Ctor.
057: *
058: * @param app Application API.
059: */
060: public DumpApplicationAction(IApplication app) {
061: super (app);
062: }
063:
064: /**
065: * Perform this action.
066: *
067: * @param evt The current event.
068: */
069: public void actionPerformed(ActionEvent evt) {
070: final IApplication app = getApplication();
071: final Frame parentFrame = getParentFrame(evt);
072: final FileExtensionFilter[] filters = new FileExtensionFilter[1];
073: filters[0] = new FileExtensionFilter(s_stringMgr
074: .getString("DumpApplicationAction.textfiles"),
075: new String[] { ".txt" });
076: final JLabel lbl = new JLabel(s_stringMgr
077: .getString("DumpApplicationAction.warning"));
078: lbl.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
079: final File outFile = Dialogs.selectFileForWriting(parentFrame,
080: filters, lbl);
081: if (outFile != null) {
082: ListMessageHandler msgHandler = new ListMessageHandler();
083: ICommand cmd = new DumpApplicationCommand(app, outFile,
084: msgHandler);
085: try {
086: cmd.execute();
087: String[] msgs = msgHandler.getMessages();
088: String[] warnings = msgHandler.getWarningMessages();
089: Throwable[] errors = msgHandler.getExceptions();
090: if (msgs.length > 0 || errors.length > 0
091: || warnings.length > 0) {
092: for (int i = 0; i < msgs.length; ++i) {
093: app.showErrorDialog(msgs[i]);
094: }
095: for (int i = 0; i < warnings.length; ++i) {
096: app.showErrorDialog(warnings[i]);
097: }
098: for (int i = 0; i < errors.length; ++i) {
099: app.showErrorDialog(errors[i]);
100: }
101: } else {
102: final String msg = s_stringMgr.getString(
103: "DumpApplicationAction.success", outFile
104: .getAbsolutePath());
105: ErrorDialog dlg = new ErrorDialog(getApplication()
106: .getMainFrame(), msg);
107: // i18n[DumpApplicationAction.titleSuccess=Dump successful]
108: dlg
109: .setTitle(s_stringMgr
110: .getString("DumpApplicationAction.titleSuccess"));
111: dlg.setVisible(true);
112: }
113: } catch (Throwable ex) {
114: final String msg = s_stringMgr
115: .getString("DumpApplicationAction.failure");
116: app.showErrorDialog(msg, ex);
117: s_log.error(msg, ex);
118: }
119: }
120: }
121: }
|