001: package net.sourceforge.squirrel_sql.plugins.mysql.action;
002:
003: /*
004: * Copyright (C) 2003 Arun Kapilan.P
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: import java.awt.event.ActionEvent;
021:
022: import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
023: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
024: import net.sourceforge.squirrel_sql.fw.util.Resources;
025: import net.sourceforge.squirrel_sql.fw.util.StringManager;
026: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
027:
028: import net.sourceforge.squirrel_sql.plugins.mysql.MysqlPlugin;
029:
030: import net.sourceforge.squirrel_sql.client.IApplication;
031: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
032: import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
033: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
034: import net.sourceforge.squirrel_sql.client.session.ISession;
035: import net.sourceforge.squirrel_sql.client.session.action.ISessionAction;
036: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
037:
038: /**
039: * DropDatabaseAction.java
040: *
041: * Created on June 9, 2003, 1:55 PM
042: *
043: * @author Arun Kapilan.P
044: */
045: public class DropDatabaseAction extends SquirrelAction implements
046: ISessionAction {
047: private static final StringManager s_stringMgr = StringManagerFactory
048: .getStringManager(DropDatabaseAction.class);
049:
050: /** Title for confirmation dialog. */
051: // i18n[mysql.droppingDBs=Dropping database(s)]
052: private static final String TITLE = s_stringMgr
053: .getString("mysql.droppingDBs");
054:
055: /** Message for confirmation dialog. */
056: // i18n[mysql.sureDropping=Are you sure?]
057: private static final String MSG = s_stringMgr
058: .getString("mysql.sureDropping");
059:
060: /** Current session. */
061: private ISession _session;
062:
063: /** Current plugin. */
064: private final MysqlPlugin _plugin;
065:
066: public DropDatabaseAction(IApplication app, Resources rsrc,
067: MysqlPlugin plugin) {
068: super (app, rsrc);
069: _plugin = plugin;
070: }
071:
072: public void actionPerformed(ActionEvent evt) {
073: if (_session != null) {
074: IPlugin plugin = _session.getApplication()
075: .getDummyAppPlugin();
076: IObjectTreeAPI treeAPI = _session.getSessionInternalFrame()
077: .getObjectTreeAPI();
078: IDatabaseObjectInfo[] dbs = treeAPI
079: .getSelectedDatabaseObjects();
080: ObjectTreeNode[] nodes = treeAPI.getSelectedNodes();
081: if (dbs.length > 0) {
082: if (Dialogs.showYesNo(_session.getSessionSheet(), MSG,
083: TITLE)) {
084: try {
085: new DropDatabaseCommand(_session, _plugin, dbs)
086: .execute();
087: treeAPI.removeNodes(nodes);
088: } catch (Throwable th) {
089: _session.showErrorMessage(th);
090: }
091: }
092: }
093: }
094: }
095:
096: /**
097: * Set the current session.
098: *
099: * @param session The current session.
100: */
101: public void setSession(ISession session) {
102: _session = session;
103: }
104: }
|