001: package net.sourceforge.squirrel_sql.client.session.action;
002:
003: /*
004: * Copyright (C) 2003-2004 Maury Hammel
005: * mjhammel@users.sourceforge.net
006: *
007: * Modifications Copyright (C) 2003-2004 Jason Height
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: * @author Maury Hammel
023: *
024: */
025: import java.awt.event.ActionEvent;
026:
027: import net.sourceforge.squirrel_sql.client.IApplication;
028: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
029: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
030: import net.sourceforge.squirrel_sql.fw.gui.CursorChanger;
031: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
032: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
033: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
034: import net.sourceforge.squirrel_sql.fw.util.StringManager;
035: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
036:
037: /**
038: * SQLFilterAction.java
039: *
040: * Created on March 22, 2003, 10:55 AM
041: *
042: * Adapted from SessionPropertiesAction.java by Colin Bell.
043: *
044: * TODO: CHange name to ContentsTabFilterAction
045: */
046: public class SQLFilterAction extends SquirrelAction implements
047: IObjectTreeAction {
048: private static final long serialVersionUID = 1L;
049:
050: transient private IObjectTreeAPI _tree;
051:
052: /** Internationalized strings for this class. */
053: private static final StringManager s_stringMgr = StringManagerFactory
054: .getStringManager(SQLFilterAction.class);
055:
056: /** Creates a new instance of SQLFilterAction
057: * @param app A reference to the SQuirreL application instance
058: */
059: public SQLFilterAction(IApplication app) {
060: super (app);
061: }
062:
063: /** Sets the _session variable with a reference to the current SQuirrel session
064: * instance.
065: * @param session A reference to the current SQuirrel session instance.
066: */
067: public void setObjectTree(IObjectTreeAPI tree) {
068: _tree = tree;
069: GUIUtils.processOnSwingEventThread(new Runnable() {
070: public void run() {
071: setEnabled(null != _tree);
072: }
073: });
074:
075: }
076:
077: /**
078: * Invoked when an action occurs.
079: *
080: * @param evt The event that triggered this procedure.
081: */
082: public void actionPerformed(ActionEvent evt) {
083: if (_tree != null) {
084: // Ensure that the proper type of Object is selected in the Object Tree before allowing the SQL Filter to be activated.
085: final IDatabaseObjectInfo selObjs[] = _tree
086: .getSelectedDatabaseObjects();
087: final int objectTotal = selObjs.length;
088:
089: if ((objectTotal == 1)
090: && ((selObjs[0].getDatabaseObjectType() == DatabaseObjectType.TABLE) || (selObjs[0]
091: .getDatabaseObjectType() == DatabaseObjectType.VIEW))) {
092: final IApplication app = getApplication();
093:
094: final CursorChanger cursorChg = new CursorChanger(app
095: .getMainFrame());
096: cursorChg.show();
097: try {
098: new SQLFilterCommand(_tree, selObjs[0]).execute();
099: } finally {
100: cursorChg.restore();
101: }
102: } else {
103: //i18n[SQLFilterAction.singleObjectMessage=You must have a
104: //single table or view selected to activate the SQL Filter]
105: String msg = s_stringMgr
106: .getString("SQLFilterAction.singleObjectMessage");
107: _tree.getSession().showMessage(msg);
108: }
109: }
110: }
111: }
|