001: package net.sourceforge.squirrel_sql.client.mainframe.action;
002:
003: /*
004: * Copyright (C) 2001-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.Frame;
022: import java.util.Iterator;
023:
024: import net.sourceforge.squirrel_sql.client.IApplication;
025: import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
026: import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
027: import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
028: import net.sourceforge.squirrel_sql.client.gui.db.SQLAlias;
029: import net.sourceforge.squirrel_sql.fw.util.ICommand;
030: import net.sourceforge.squirrel_sql.fw.util.StringManager;
031: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
032:
033: /**
034: * This <CODE>ICommand</CODE> allows the user to delete an existing
035: * <TT>ISQLDriver</TT>.
036: *
037: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
038: */
039: public class DeleteDriverCommand implements ICommand {
040: /** Internationalized strings for this class. */
041: private static final StringManager s_stringMgr = StringManagerFactory
042: .getStringManager(DeleteDriverCommand.class);
043:
044: /** Application API. */
045: private final IApplication _app;
046:
047: /** Owner of the maintenance dialog. */
048: private Frame _frame;
049:
050: /** <TT>ISQLDriver</TT> to be deleted. */
051: private ISQLDriver _sqlDriver;
052:
053: /**
054: * Ctor.
055: *
056: * @param app Application API.
057: * @param frame Owning <TT>Frame</TT>.
058: * @param sqlDriver <ISQLDriver</TT> to be deleted.
059: *
060: * @throws IllegalArgumentException
061: * Thrown if a <TT>null</TT> <TT>ISQLDriver</TT> or
062: * <TT>IApplication</TT> passed.
063: */
064: public DeleteDriverCommand(IApplication app, Frame frame,
065: ISQLDriver sqlDriver) {
066: super ();
067: if (sqlDriver == null) {
068: throw new IllegalArgumentException("Null ISQLDriver passed");
069: }
070: if (app == null) {
071: throw new IllegalArgumentException(
072: "Null IApplication passed");
073: }
074:
075: _app = app;
076: _frame = frame;
077: _sqlDriver = sqlDriver;
078: }
079:
080: /**
081: * Delete the current <TT>ISQLDriver</TT> after confirmation.
082: */
083: public void execute() {
084: final Object[] args = { _sqlDriver.getName() };
085: final net.sourceforge.squirrel_sql.client.gui.db.DataCache cache = _app
086: .getDataCache();
087: Iterator<ISQLAlias> it = cache.getAliasesForDriver(_sqlDriver);
088: if (it.hasNext()) {
089: StringBuffer aliasList = new StringBuffer();
090: while (it.hasNext()) {
091: net.sourceforge.squirrel_sql.client.gui.db.SQLAlias alias = (SQLAlias) it
092: .next();
093: aliasList.append("\n");
094: aliasList.append(alias.getName());
095: }
096: final Object[] args2 = { _sqlDriver.getName(), aliasList };
097: String msg = s_stringMgr.getString(
098: "DeleteDriverCommand.used", args2);
099: Dialogs.showOk(_frame, msg);
100: } else {
101: if (Dialogs.showYesNo(_frame, s_stringMgr.getString(
102: "DeleteDriverCommand.comfirm", args))) {
103: cache.removeDriver(_sqlDriver);
104: }
105: }
106: }
107: }
|