001: package net.sourceforge.squirrel_sql.plugins.mysql.action;
002:
003: /*
004: * Copyright (C) 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.event.ActionEvent;
022:
023: import javax.swing.JOptionPane;
024:
025: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
026: import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
027: import net.sourceforge.squirrel_sql.fw.util.Resources;
028: import net.sourceforge.squirrel_sql.fw.util.StringManager;
029: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
030: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
031: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
032:
033: import net.sourceforge.squirrel_sql.client.IApplication;
034: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
035: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
036: import net.sourceforge.squirrel_sql.client.session.ISession;
037: import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
038:
039: import net.sourceforge.squirrel_sql.plugins.mysql.MysqlPlugin;
040:
041: /**
042: * This <TT>Action</TT> will allow the user to rename the currently selected
043: * table.
044: *
045: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
046: */
047: public class RenameTableAction extends SquirrelAction implements
048: ISessionAction {
049: /** Internationalized strings for this class. */
050: private static final StringManager s_stringMgr = StringManagerFactory
051: .getStringManager(RenameTableAction.class);
052:
053: /** Logger for this class. */
054: private final static ILogger s_log = LoggerController
055: .createLogger(RenameTableAction.class);
056:
057: /** Current session. */
058: private ISession _session;
059:
060: /** Current plugin. */
061: private final MysqlPlugin _plugin;
062:
063: public RenameTableAction(IApplication app, Resources rsrc,
064: MysqlPlugin plugin) {
065: super (app, rsrc);
066: _plugin = plugin;
067: }
068:
069: public void actionPerformed(ActionEvent evt) {
070: if (_session != null) {
071: final IObjectTreeAPI treeAPI = _session
072: .getSessionInternalFrame().getObjectTreeAPI();
073: final IDatabaseObjectInfo[] tables = treeAPI
074: .getSelectedDatabaseObjects();
075: if (tables.length == 1) {
076: final ITableInfo ti = (ITableInfo) tables[0];
077: final String msg = s_stringMgr.getString(
078: "RenameTableAction.newnameprompt", ti
079: .getQualifiedName());
080: final String title = s_stringMgr
081: .getString("RenameTableAction.rename");
082: final String newTableName = JOptionPane
083: .showInputDialog(null, msg, title,
084: JOptionPane.QUESTION_MESSAGE);
085: if (newTableName != null && newTableName.length() > 0) {
086: try {
087: new RenameTableCommand(_session, _plugin, ti,
088: newTableName).execute();
089: } catch (Throwable th) {
090: _session.showErrorMessage(th);
091: s_log.error("Error occured renaming table", th);
092: }
093: }
094: } else {
095: // i18n[mysql.selectSingleTable=Must select a single table]
096: _session.getApplication().showErrorDialog(
097: s_stringMgr
098: .getString("mysql.selectSingleTable"));
099: }
100: }
101: }
102:
103: /**
104: * Set the current session.
105: *
106: * @param session The current session.
107: */
108: public void setSession(ISession session) {
109: _session = session;
110: }
111: }
|