001: package net.sourceforge.squirrel_sql.client.mainframe.action;
002:
003: /*
004: * Copyright (C) 2001-2004 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: import java.beans.PropertyVetoException;
023: import java.io.IOException;
024: import java.net.URL;
025:
026: import net.sourceforge.squirrel_sql.client.IApplication;
027: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
028: import net.sourceforge.squirrel_sql.client.gui.db.DriversListInternalFrame;
029: import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
030: import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
031: import net.sourceforge.squirrel_sql.fw.util.StringManager;
032: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
033: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
034: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
035: import net.sourceforge.squirrel_sql.fw.xml.XMLException;
036:
037: /**
038: * This <CODE>Action</CODE> allows the user to create a new <TT>ISQLDriver</TT>.
039: *
040: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
041: */
042: public class CreateDriverAction extends SquirrelAction {
043: /** Logger for this class. */
044: private static ILogger s_log = LoggerController
045: .createLogger(CreateDriverAction.class);
046:
047: /** Internationalized strings for this class. */
048: private static final StringManager s_stringMgr = StringManagerFactory
049: .getStringManager(CreateDriverAction.class);
050:
051: /**
052: * Ctor.
053: *
054: * @param app Application API.
055: */
056: public CreateDriverAction(IApplication app) {
057: super (app);
058: }
059:
060: /**
061: * Perform this action. Execute the create driver command.
062: *
063: * @param evt The current event.
064: */
065: public void actionPerformed(ActionEvent evt) {
066: IApplication app = getApplication();
067: DriversListInternalFrame tw = app.getWindowManager()
068: .getDriversListInternalFrame();
069: tw.moveToFront();
070: try {
071: tw.setSelected(true);
072: } catch (PropertyVetoException ex) {
073: //i18n[CreateDriverAction.error.selectingwindow=Error selecting window]
074: s_log
075: .error(
076: s_stringMgr
077: .getString("CreateDriverAction.error.selectingwindow"),
078: ex);
079: }
080:
081: try {
082: final URL url = app.getResources().getDefaultDriversUrl();
083: net.sourceforge.squirrel_sql.client.gui.db.DataCache cache = _app
084: .getDataCache();
085: ISQLDriver[] missingDrivers = cache
086: .findMissingDefaultDrivers(url);
087: if (missingDrivers != null) {
088: String msg = s_stringMgr
089: .getString("CreateDriverAction.confirm");
090: if (Dialogs.showYesNo(_app.getMainFrame(), msg)) {
091: for (int i = 0; i < missingDrivers.length; i++) {
092: try {
093: cache.addDriver(missingDrivers[i], null);
094: } catch (Exception e) {
095: e.printStackTrace();
096: }
097: }
098:
099: }
100: }
101: } catch (XMLException e) {
102: // i18n[CreateDriverAction.error.loadDefaultDrivers]
103: String msg = s_stringMgr
104: .getString("CreateDriverAction.error.loadDefaultDrivers");
105: s_log.error(msg, e);
106: } catch (IOException e) {
107: // i18n[CreateDriverAction.error.loadDefaultDrivers]
108: String msg = s_stringMgr
109: .getString("CreateDriverAction.error.loadDefaultDrivers");
110: s_log.error(msg, e);
111: }
112:
113: new CreateDriverCommand(app).execute();
114: }
115: }
|