001: package net.sourceforge.squirrel_sql.plugins.example;
002:
003: import net.sourceforge.squirrel_sql.client.action.ActionCollection;
004: import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
005: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
006: import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
007: import net.sourceforge.squirrel_sql.client.plugin.PluginException;
008: import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
009: import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
010: import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
011: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
012: import net.sourceforge.squirrel_sql.client.session.ISession;
013: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
014:
015: /**
016: * The Example plugin class.
017: */
018: public class ExamplePlugin extends DefaultSessionPlugin {
019: private PluginResources _resources;
020:
021: /**
022: * Return the internal name of this plugin.
023: *
024: * @return the internal name of this plugin.
025: */
026: public String getInternalName() {
027: return "example";
028: }
029:
030: /**
031: * Return the descriptive name of this plugin.
032: *
033: * @return the descriptive name of this plugin.
034: */
035: public String getDescriptiveName() {
036: return "Example Plugin";
037: }
038:
039: /**
040: * Returns the current version of this plugin.
041: *
042: * @return the current version of this plugin.
043: */
044: public String getVersion() {
045: return "0.01";
046: }
047:
048: /**
049: * Returns the authors name.
050: *
051: * @return the authors name.
052: */
053: public String getAuthor() {
054: return "Gerd Wagner";
055: }
056:
057: /**
058: * Returns the name of the change log for the plugin. This should
059: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
060: * directory.
061: *
062: * @return the changelog file name or <TT>null</TT> if plugin doesn't have
063: * a change log.
064: */
065: public String getChangeLogFileName() {
066: return "changes.txt";
067: }
068:
069: /**
070: * Returns the name of the Help file for the plugin. This should
071: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
072: * directory.
073: *
074: * @return the Help file name or <TT>null</TT> if plugin doesn't have
075: * a help file.
076: */
077: public String getHelpFileName() {
078: return "readme.txt";
079: }
080:
081: /**
082: * Returns the name of the Licence file for the plugin. This should
083: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
084: * directory.
085: *
086: * @return the Licence file name or <TT>null</TT> if plugin doesn't have
087: * a licence file.
088: */
089: public String getLicenceFileName() {
090: return "licence.txt";
091: }
092:
093: /**
094: * @return Comma separated list of contributors.
095: */
096: public String getContributors() {
097: return "";
098: }
099:
100: /**
101: * Create preferences panel for the Global Preferences dialog.
102: *
103: * @return Preferences panel.
104: */
105: public IGlobalPreferencesPanel[] getGlobalPreferencePanels() {
106: return new IGlobalPreferencesPanel[0];
107: }
108:
109: /**
110: * Initialize this plugin.
111: */
112: public synchronized void initialize() throws PluginException {
113: _resources = new PluginResources(
114: "net.sourceforge.squirrel_sql.plugins.example.example",
115: this );
116: }
117:
118: /**
119: * Called when a session started. Add commands to popup menu
120: * in object tree.
121: *
122: * @param session The session that is starting.
123: *
124: * @return An implementation of PluginSessionCallback or null to indicate
125: * the plugin does not work with this session
126: */
127: public PluginSessionCallback sessionStarted(ISession session) {
128: try {
129: String driverName = session.getSQLConnection()
130: .getConnection().getMetaData().getDriverName();
131: if (false == driverName.toUpperCase().startsWith(
132: "IBM DB2 JDBC")) {
133: // Plugin knows only how to script Views and Stored Procedures on DB2.
134: // So if it's not a DB2 Session we tell SQuirreL the Plugin should not be used.
135: return null;
136: }
137:
138: // Add context menu items to the object tree's view and procedure nodes.
139: IObjectTreeAPI otApi = session.getSessionInternalFrame()
140: .getObjectTreeAPI();
141: otApi.addToPopup(DatabaseObjectType.VIEW,
142: new ScriptDB2ViewAction(getApplication(),
143: _resources, session));
144: otApi.addToPopup(DatabaseObjectType.PROCEDURE,
145: new ScriptDB2ProcedureAction(getApplication(),
146: _resources, session));
147:
148: return new PluginSessionCallback() {
149: public void sqlInternalFrameOpened(
150: SQLInternalFrame sqlInternalFrame, ISession sess) {
151: //plugin supports Session main window only
152: }
153:
154: public void objectTreeInternalFrameOpened(
155: ObjectTreeInternalFrame objectTreeInternalFrame,
156: ISession sess) {
157: //plugin supports Session main window only
158: }
159: };
160: } catch (Exception e) {
161: throw new RuntimeException(e);
162: }
163: }
164:
165: }
|