001: /*
002: * Copyright (C) 2003 Joseph Mocker
003: * mock-sf@misfit.dhs.org
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019:
020: package net.sourceforge.squirrel_sql.plugins.sqlbookmark;
021:
022: import java.awt.event.ActionEvent;
023:
024: import javax.swing.JMenuItem;
025:
026: import net.sourceforge.squirrel_sql.client.IApplication;
027: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
028: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
029: import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
030: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
031: import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
032: import net.sourceforge.squirrel_sql.client.session.ISession;
033: import net.sourceforge.squirrel_sql.client.session.action.ISQLPanelAction;
034: import net.sourceforge.squirrel_sql.fw.util.Resources;
035:
036: /**
037: * Initiates execution of a bookmark when user clicks on a bookmark
038: * menu item.
039: *
040: * @author Joseph Mocker
041: */
042: public class RunBookmarkAction extends SquirrelAction implements
043: ISQLPanelAction {
044: private static final long serialVersionUID = 1L;
045:
046: /**
047: * Current session to load the bookmark into
048: */
049: transient private ISession session;
050:
051: /**
052: * Handle to the main plugin object
053: */
054: transient private SQLBookmarkPlugin plugin;
055:
056: public RunBookmarkAction(IApplication app, Resources rsrc,
057: SQLBookmarkPlugin plugin) throws IllegalArgumentException {
058: super (app, rsrc);
059: if (plugin == null) {
060: throw new IllegalArgumentException("null IPlugin passed");
061: }
062: this .plugin = plugin;
063: }
064:
065: public void actionPerformed(ActionEvent evt) {
066: if (session != null) {
067: Object source = evt.getSource();
068: if (source instanceof JMenuItem) {
069: JMenuItem item = (JMenuItem) source;
070:
071: Bookmark bookmark = plugin.getBookmarkManager().get(
072: item.getText());
073:
074: ISQLEntryPanel sqlEntryPanel;
075:
076: if (session.getActiveSessionWindow() instanceof SessionInternalFrame) {
077: sqlEntryPanel = ((SessionInternalFrame) session
078: .getActiveSessionWindow()).getSQLPanelAPI()
079: .getSQLEntryPanel();
080: } else if (session.getActiveSessionWindow() instanceof SQLInternalFrame) {
081: sqlEntryPanel = ((SQLInternalFrame) session
082: .getActiveSessionWindow()).getSQLPanelAPI()
083: .getSQLEntryPanel();
084: } else {
085: return;
086: }
087:
088: if (bookmark != null)
089: new RunBookmarkCommand(getParentFrame(evt),
090: session, bookmark, plugin, sqlEntryPanel)
091: .execute();
092: }
093: }
094: }
095:
096: public void setSQLPanel(ISQLPanelAPI panel) {
097: if (null != panel) {
098: session = panel.getSession();
099: } else {
100: session = null;
101: }
102: setEnabled(null != session);
103: }
104:
105: }
|