001: package net.sourceforge.squirrel_sql.client.session.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.client.IApplication;
029: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
030: import net.sourceforge.squirrel_sql.client.session.ISession;
031: import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
032: import net.sourceforge.squirrel_sql.fw.util.FileExtensionFilter;
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: /**
039: * This <CODE>Action</CODE> dumps the current session status to an XML file.
040: *
041: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
042: */
043: public class DumpSessionAction extends SquirrelAction implements
044: ISessionAction {
045: /** Internationalized strings for this class. */
046: private static final StringManager s_stringMgr = StringManagerFactory
047: .getStringManager(DumpSessionAction.class);
048:
049: /** Logger for this class. */
050: private final static ILogger s_log = LoggerController
051: .createLogger(DumpSessionAction.class);
052:
053: /** Current session. */
054: private ISession _session;
055:
056: /**
057: * Ctor.
058: *
059: * @param app Application API.
060: */
061: public DumpSessionAction(IApplication app) {
062: super (app);
063: }
064:
065: /**
066: * Set the current session.
067: *
068: * @param session The current session.
069: */
070: public void setSession(ISession session) {
071: _session = session;
072: }
073:
074: /**
075: * Perform this action.
076: *
077: * @param evt The current event.
078: */
079: public void actionPerformed(ActionEvent evt) {
080: final Frame parentFrame = getParentFrame(evt);
081: FileExtensionFilter[] filters = new FileExtensionFilter[1];
082: filters[0] = new FileExtensionFilter("Text files",
083: new String[] { ".txt" });
084: // i18n[DumpSessionAction.warning=<HTML><BODY><B>Warning:</B> Plain<BR>text passwords<BR>may be saved<BR>in this file.</BODY></HTML>]
085: String label = s_stringMgr
086: .getString("DumpSessionAction.warning");
087: final JLabel lbl = new JLabel(label);
088: lbl.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
089: final File outFile = Dialogs.selectFileForWriting(parentFrame,
090: filters, lbl);
091: if (outFile != null) {
092: DumpSessionCommand cmd = new DumpSessionCommand(outFile);
093: cmd.setSession(_session);
094: try {
095: cmd.execute();
096:
097: // i18n[DumpSessionAction.success=Session successfuly dumped to: {0}]
098: final String msg = s_stringMgr.getString(
099: "DumpSessionAction.success", outFile
100: .getAbsolutePath());
101:
102: _session.showMessage(msg);
103: } catch (Throwable ex) {
104: // i18n[DumpSessionAction.error=Error occured dumping session: {0}]
105: final String msg = s_stringMgr.getString(
106: "DumpSessionAction.error", ex);
107: _session.showErrorMessage(msg);
108: s_log.error(msg, ex);
109: }
110: }
111: }
112: }
|