001: package net.sourceforge.squirrel_sql.client.mainframe.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 net.sourceforge.squirrel_sql.fw.util.ICommand;
022:
023: import net.sourceforge.squirrel_sql.client.IApplication;
024: import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
025:
026: /**
027: * This <CODE>ICommand</CODE> allows the user to show/hide drivers in the
028: * Drivers List that cannot be loaded.
029: *
030: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
031: */
032: public class ShowLoadedDriversOnlyCommand implements ICommand {
033: /** Application API. */
034: private final IApplication _app;
035:
036: /**
037: * If <TT>null</TT> then flip showing/hiding the drivers
038: * else if <TT>Boolean.TRUE</TT> then show the drivers
039: * else hide them.
040: */
041: private Boolean _show;
042:
043: /**
044: * Ctor. When created using this the command will flip
045: * whether loaded drivers are shown or hidden.
046: *
047: * @param app Application API.
048: *
049: * @throws IllegalArgumentException
050: * Thrown if null IApplication passed.
051: */
052: public ShowLoadedDriversOnlyCommand(IApplication app) {
053: this (app, null);
054: }
055:
056: /**
057: * Ctor specifying whether whether loaded drivers
058: * should be shown or hidden.
059: *
060: * @param app Application API.
061: * @param show If <TT>true</TT> show the drivers.
062: *
063: * @throws IllegalArgumentException
064: * Thrown if null IApplication passed.
065: */
066: public ShowLoadedDriversOnlyCommand(IApplication app, boolean show) {
067: this (app, Boolean.valueOf(show));
068: }
069:
070: /**
071: * Ctor specifying whether whether loaded drivers
072: * should be shown or hidden.
073: *
074: * @param app Application API.
075: * @param show If <TT>null</TT> then flip showing
076: * the drivers, <TT>Boolean.TRUE</TT> show the drivers
077: * else hide the drivers.
078: *
079: * @throws IllegalArgumentException
080: * Thrown if null IApplication passed.
081: */
082: private ShowLoadedDriversOnlyCommand(IApplication app, Boolean show) {
083: super ();
084: if (app == null) {
085: throw new IllegalArgumentException("IApplication == null");
086: }
087: _app = app;
088: _show = show;
089: }
090:
091: /**
092: * Execute this command.
093: */
094: public void execute() {
095: SquirrelPreferences prefs = _app.getSquirrelPreferences();
096: if (_show == null) {
097: prefs.setShowLoadedDriversOnly(!prefs
098: .getShowLoadedDriversOnly());
099: } else {
100: prefs.setShowLoadedDriversOnly(_show.booleanValue());
101: }
102: }
103: }
|