001: package net.sourceforge.squirrel_sql.client.plugin;
002:
003: /*
004: * Copyright (C) 2001-2002 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.io.File;
022: import java.io.IOException;
023:
024: import net.sourceforge.squirrel_sql.client.IApplication;
025: import net.sourceforge.squirrel_sql.client.Version;
026: import net.sourceforge.squirrel_sql.client.gui.db.aliasproperties.IAliasPropertiesPanelController;
027: import net.sourceforge.squirrel_sql.client.gui.db.SQLAlias;
028: import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
029: import net.sourceforge.squirrel_sql.client.preferences.INewSessionPropertiesPanel;
030: import net.sourceforge.squirrel_sql.client.util.ApplicationFiles;
031: import net.sourceforge.squirrel_sql.fw.util.StringManager;
032: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
033:
034: public abstract class DefaultPlugin implements IPlugin {
035: /** Internationalized strings for this class. */
036: private static final StringManager s_stringMgr = StringManagerFactory
037: .getStringManager(DefaultPlugin.class);
038:
039: /** Current application API. */
040: protected IApplication _app;
041:
042: /**
043: * Called on application startup before application started up.
044: *
045: * @param app Application API.
046: *
047: * @throws PluginException
048: * Thrown if an error occurs.
049: */
050: public void load(IApplication app) throws PluginException {
051: if (app == null) {
052: throw new IllegalArgumentException(
053: "Null IApplication passed");
054: }
055: _app = app;
056: }
057:
058: /**
059: * Called on application startup after application started.
060: *
061: * @throws PluginException
062: * Thrown if an error occurs.
063: */
064: public void initialize() throws PluginException {
065: // Empty method.
066: }
067:
068: /**
069: * Called when app shutdown.
070: *
071: * @throws PluginException
072: * Thrown if an error occurs.
073: */
074: public void unload() // throws PluginException
075: {
076: // TODO: Put throws clause back in
077: // Empty method.
078: }
079:
080: /**
081: * Returns a comma separated list of other contributors.
082: *
083: * @return Contributors names.
084: */
085: public String getContributors() {
086: return "";
087: }
088:
089: /**
090: * Returns the home page for this plugin.
091: *
092: * @return the home page for this plugin.
093: */
094: public String getWebSite() {
095: return Version.getWebSite();
096: }
097:
098: /**
099: * Returns the name of the Help file for the plugin. This should
100: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
101: * directory.
102: *
103: * @return the Help file name or <TT>null</TT> if plugin doesn't have
104: * a help file.
105: */
106: public String getHelpFileName() {
107: return null;
108: }
109:
110: /**
111: * Returns the name of the change log for the plugin. This should
112: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
113: * directory.
114: *
115: * @return the changelog file name or <TT>null</TT> if plugin doesn't have
116: * a change log.
117: */
118: public String getChangeLogFileName() {
119: return null;
120: }
121:
122: /**
123: * Returns the name of the licence file for the plugin. This should
124: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
125: * directory.
126: *
127: * @return the licence file name or <TT>null</TT> if plugin doesn't have
128: * a change log.
129: */
130: public String getLicenceFileName() {
131: return null;
132: }
133:
134: /**
135: * Return the current application API.
136: *
137: * @return The current application API.
138: */
139: public final IApplication getApplication() {
140: return _app;
141: }
142:
143: /**
144: * Return the folder with the Squirrel application folder
145: * that belongs to this plugin. If it doesn't exist then
146: * create it. This would normally be
147: * <PRE>
148: * <squirrel_app>/plugins/<plugin_internal_name>
149: * </PRE>
150: *
151: * @return Plugins application folder.
152: *
153: * @throws IllegalStateException
154: * if plugin doesn't have an internal name.
155: *
156: * @throws IOException
157: * An error occured retrieving/creating the folder.
158: */
159: public synchronized File getPluginAppSettingsFolder()
160: throws IllegalStateException, IOException {
161: final String internalName = getInternalName();
162: if (internalName == null || internalName.trim().length() == 0) {
163: throw new IllegalStateException(
164: "IPlugin doesn't have a valid internal name");
165: }
166: final File pluginDir = new ApplicationFiles()
167: .getPluginsDirectory();
168: final File file = new File(pluginDir, internalName);
169: if (!file.exists()) {
170: file.mkdirs();
171: }
172:
173: if (!file.isDirectory()) {
174: throw new IOException(s_stringMgr.getString(
175: "DefaultPlugin.error.cannotcreate", file
176: .getAbsolutePath()));
177: }
178:
179: return file;
180: }
181:
182: /**
183: * Return the folder with the users home directory
184: * that belongs to this plugin. If it doesn't exist then
185: * create it. This would normally be
186: * <PRE>
187: * <user_home>/.squirrel-sql/plugins/<plugin_internal_name>
188: * </PRE>
189: *
190: * @return Plugins user folder.
191: *
192: * @throws IllegalStateException
193: * if plugin doesn't have an internal name.
194: *
195: * @throws IOException
196: * An error occured retrieving/creating the folder.
197: */
198: public synchronized File getPluginUserSettingsFolder()
199: throws IllegalStateException, IOException {
200: final String internalName = getInternalName();
201: if (internalName == null || internalName.trim().length() == 0) {
202: throw new IllegalStateException(
203: "IPlugin doesn't have a valid internal name");
204: }
205: String name = new ApplicationFiles()
206: .getPluginsUserSettingsDirectory()
207: + File.separator + internalName + File.separator;
208: File file = new File(name);
209: if (!file.exists()) {
210: file.mkdirs();
211: }
212:
213: if (!file.isDirectory()) {
214: throw new IOException(s_stringMgr.getString(
215: "DefaultPlugin.error.cannotcreate", name));
216: }
217:
218: return file;
219: }
220:
221: /**
222: * Create panels for the Global Preferences dialog.
223: *
224: * @return <TT>null</TT> to indicate that this plugin doesn't require
225: * any panels in the Global Preferences Dialog.
226: */
227: public IGlobalPreferencesPanel[] getGlobalPreferencePanels() {
228: return null;
229: }
230:
231: public IAliasPropertiesPanelController[] getAliasPropertiesPanelControllers(
232: SQLAlias alias) {
233: return null;
234: }
235:
236: public void aliasCopied(SQLAlias source, SQLAlias target) {
237: }
238:
239: public void aliasRemoved(SQLAlias alias) {
240: }
241:
242: /**
243: * Create panels for the New Session Properties dialog.
244: *
245: * @return <TT>null</TT>to indicate that this plugin doesn't require
246: * any panels in the New Session Properties Dialog.
247: */
248: public INewSessionPropertiesPanel[] getNewSessionPropertiesPanels() {
249: return null;
250: }
251:
252: /**
253: * By default a plugin provieds no external services
254: * @return
255: */
256: public Object getExternalService() {
257: return null;
258: }
259:
260: }
|