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