001: package de.ixdb.squirrel_sql.plugins.cache;
002:
003: import net.sourceforge.squirrel_sql.client.IApplication;
004: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
005: import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
006: import net.sourceforge.squirrel_sql.client.action.ActionCollection;
007: import net.sourceforge.squirrel_sql.client.plugin.*;
008: import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
009: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
010: import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
011: import net.sourceforge.squirrel_sql.client.session.ISession;
012: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
013: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
014: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
015:
016: import java.io.File;
017: import java.io.IOException;
018:
019: /**
020: * The SQL Script plugin class.
021: */
022: public class CachePlugin extends DefaultSessionPlugin {
023:
024: /** Logger for this class. */
025: private static ILogger s_log = LoggerController
026: .createLogger(CachePlugin.class);
027:
028: /** The app folder for this plugin. */
029: private File _pluginAppFolder;
030:
031: private PluginResources _resources;
032:
033: /** Folder to store user settings in. */
034: private File _userSettingsFolder;
035:
036: /**
037: * Return the internal name of this plugin.
038: *
039: * @return the internal name of this plugin.
040: */
041: public String getInternalName() {
042: return "cache";
043: }
044:
045: /**
046: * Return the descriptive name of this plugin.
047: *
048: * @return the descriptive name of this plugin.
049: */
050: public String getDescriptiveName() {
051: return "Plugin for the Intersystems Cache DB";
052: }
053:
054: /**
055: * Returns the current version of this plugin.
056: *
057: * @return the current version of this plugin.
058: */
059: public String getVersion() {
060: return "0.01";
061: }
062:
063: /**
064: * Returns the authors name.
065: *
066: * @return the authors name.
067: */
068: public String getAuthor() {
069: return "Gerd Wagner";
070: }
071:
072: /**
073: * Returns the name of the change log for the plugin. This should
074: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
075: * directory.
076: *
077: * @return the changelog file name or <TT>null</TT> if plugin doesn't have
078: * a change log.
079: */
080: public String getChangeLogFileName() {
081: return "changes.txt";
082: }
083:
084: /**
085: * Returns the name of the Help file for the plugin. This should
086: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
087: * directory.
088: *
089: * @return the Help file name or <TT>null</TT> if plugin doesn't have
090: * a help file.
091: */
092: public String getHelpFileName() {
093: return "readme.txt";
094: }
095:
096: /**
097: * Returns the name of the Licence file for the plugin. This should
098: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
099: * directory.
100: *
101: * @return the Licence file name or <TT>null</TT> if plugin doesn't have
102: * a licence file.
103: */
104: public String getLicenceFileName() {
105: return "licence.txt";
106: }
107:
108: /**
109: * @return Comma separated list of contributors.
110: */
111: public String getContributors() {
112: return "Andreas Schneider";
113: }
114:
115: /**
116: * Create preferences panel for the Global Preferences dialog.
117: *
118: * @return Preferences panel.
119: */
120: public IGlobalPreferencesPanel[] getGlobalPreferencePanels() {
121: return new IGlobalPreferencesPanel[0];
122: }
123:
124: /**
125: * Initialize this plugin.
126: */
127: public synchronized void initialize() throws PluginException {
128: super .initialize();
129: IApplication app = getApplication();
130:
131: PluginManager pmgr = app.getPluginManager();
132:
133: // Folder within plugins folder that belongs to this
134: // plugin.
135: try {
136: _pluginAppFolder = getPluginAppSettingsFolder();
137: } catch (IOException ex) {
138: throw new PluginException(ex);
139: }
140:
141: // Folder to store user settings.
142: try {
143: _userSettingsFolder = getPluginUserSettingsFolder();
144: } catch (IOException ex) {
145: throw new PluginException(ex);
146: }
147:
148: _resources = new CachePluginResources(
149: "de.ixdb.squirrel_sql.plugins.cache.cache", this );
150:
151: // Load plugin preferences.
152: ActionCollection coll = app.getActionCollection();
153: coll.add(new ScriptViewAction(app, _resources, this ));
154: coll.add(new ScriptFunctionAction(app, _resources, this ));
155: coll.add(new ScriptCdlAction(app, _resources, this ));
156: coll.add(new ShowNamespacesAction(app, _resources, this ));
157: coll.add(new ShowQueryPlanAction(app, _resources, this ));
158: coll.add(new ShowProcessesAction(app, _resources, this ));
159:
160: // coll.add(new ScriptProcedureAction(app, _resources, this, _userSettingsFolder));
161: // coll.add(new RefreshRepositoryAction(app, _resources, this, _userSettingsFolder));
162: }
163:
164: /**
165: * Application is shutting down so save data.
166: */
167: public void unload() {
168: super .unload();
169: }
170:
171: /**
172: * Called when a session started. Add commands to popup menu
173: * in object tree.
174: *
175: * @param session The session that is starting.
176: *
177: * @return <TT>true</TT> to indicate that this plugin is
178: * applicable to passed session.
179: */
180: public PluginSessionCallback sessionStarted(ISession session) {
181: try {
182: if (-1 != session.getSQLConnection().getConnection()
183: .getMetaData().getDriverName().toUpperCase()
184: .indexOf("CACHE")) {
185: ActionCollection coll = getApplication()
186: .getActionCollection();
187: IObjectTreeAPI otApi = session
188: .getSessionInternalFrame().getObjectTreeAPI();
189: otApi.addToPopup(DatabaseObjectType.VIEW, coll
190: .get(ScriptViewAction.class));
191: otApi.addToPopup(DatabaseObjectType.SESSION, coll
192: .get(ShowNamespacesAction.class));
193: otApi.addToPopup(DatabaseObjectType.SESSION, coll
194: .get(ShowProcessesAction.class));
195: otApi.addToPopup(DatabaseObjectType.PROCEDURE, coll
196: .get(ScriptFunctionAction.class));
197: otApi.addToPopup(DatabaseObjectType.PROCEDURE, coll
198: .get(ScriptCdlAction.class));
199: otApi.addToPopup(DatabaseObjectType.TABLE, coll
200: .get(ScriptCdlAction.class));
201: otApi.addToPopup(DatabaseObjectType.VIEW, coll
202: .get(ScriptCdlAction.class));
203:
204: ISQLPanelAPI sqlApi = session.getSessionInternalFrame()
205: .getSQLPanelAPI();
206: sqlApi.addToSQLEntryAreaMenu(coll
207: .get(ShowQueryPlanAction.class));
208:
209: session.addSeparatorToToolbar();
210: session.addToToolbar(coll
211: .get(ShowNamespacesAction.class));
212: session.addToToolbar(coll
213: .get(ShowProcessesAction.class));
214: session.addToToolbar(coll
215: .get(ShowQueryPlanAction.class));
216: session.getSessionInternalFrame().addToToolsPopUp(
217: "cachequeryplan",
218: coll.get(ShowQueryPlanAction.class));
219:
220: return new PluginSessionCallback() {
221: public void sqlInternalFrameOpened(
222: SQLInternalFrame sqlInternalFrame,
223: ISession sess) {
224: //plugin supports only Session main window
225: }
226:
227: public void objectTreeInternalFrameOpened(
228: ObjectTreeInternalFrame objectTreeInternalFrame,
229: ISession sess) {
230: //plugin supports only Session main window
231: }
232: };
233: } else {
234: return null;
235: }
236: } catch (Exception e) {
237: s_log.error("Could not get driver name", e);
238: return null;
239: }
240: }
241:
242: }
|