001: package net.sourceforge.squirrel_sql.plugins.SybaseASE;
002:
003: import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
004: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
005: import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
006: import net.sourceforge.squirrel_sql.client.plugin.PluginException;
007: import net.sourceforge.squirrel_sql.client.plugin.PluginQueryTokenizerPreferencesManager;
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.plugin.gui.PluginGlobalPreferencesTab;
011: import net.sourceforge.squirrel_sql.client.plugin.gui.PluginQueryTokenizerPreferencesPanel;
012: import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
013: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
014: import net.sourceforge.squirrel_sql.client.session.ISession;
015: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.TableWithChildNodesExpander;
016: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.DatabaseObjectInfoTab;
017: import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
018: import net.sourceforge.squirrel_sql.fw.preferences.IQueryTokenizerPreferenceBean;
019: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
020: import net.sourceforge.squirrel_sql.fw.util.StringManager;
021: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
022: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
023: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
024: import net.sourceforge.squirrel_sql.plugins.SybaseASE.exp.SybaseTableIndexExtractorImpl;
025: import net.sourceforge.squirrel_sql.plugins.SybaseASE.exp.SybaseTableTriggerExtractorImpl;
026: import net.sourceforge.squirrel_sql.plugins.SybaseASE.prefs.SybasePreferenceBean;
027: import net.sourceforge.squirrel_sql.plugins.SybaseASE.tab.TriggerSourceTab;
028: import net.sourceforge.squirrel_sql.plugins.SybaseASE.tab.ViewSourceTab;
029: import net.sourceforge.squirrel_sql.plugins.SybaseASE.tokenizer.SybaseQueryTokenizer;
030:
031: /**
032: * The Example plugin class.
033: */
034: public class SybaseASEPlugin extends DefaultSessionPlugin {
035: /**
036: * Internationalized strings for this class.
037: */
038: private static final StringManager s_stringMgr = StringManagerFactory
039: .getStringManager(SybaseASEPlugin.class);
040:
041: /** Logger for this class. */
042: @SuppressWarnings("unused")
043: private final static ILogger s_log = LoggerController
044: .createLogger(SybaseASEPlugin.class);
045:
046: private PluginResources _resources;
047:
048: /** manages our query tokenizing preferences */
049: private PluginQueryTokenizerPreferencesManager _prefsManager = null;
050:
051: /** The database name that appears in the border label of the pref panel */
052: private static final String SCRIPT_SETTINGS_BORDER_LABEL_DBNAME = "Sybase";
053:
054: static interface i18n {
055: // i18n[SybaseASEPlugin.title=SybaseASE]
056: String title = s_stringMgr.getString("SybaseASEPlugin.title");
057:
058: // i18n[SybaseASEPlugin.hint=Preferences for SybaseASE]
059: String hint = s_stringMgr.getString("SybaseASEPlugin.hint");
060:
061: //i18n[SybaseASEPlugin.showViewSource=Show view source]
062: String SHOW_VIEW_SOURCE = s_stringMgr
063: .getString("SybaseASEPlugin.showViewSource");
064:
065: // i18n[SybaseASEPlugin.triggerHint=Show trigger source]
066: String TRIGGER_HINT = s_stringMgr
067: .getString("SybaseASEPlugin.triggerHint");
068:
069: }
070:
071: /**
072: * Return the internal name of this plugin.
073: *
074: * @return the internal name of this plugin.
075: */
076: public String getInternalName() {
077: return "sybase";
078: }
079:
080: /**
081: * Return the descriptive name of this plugin.
082: *
083: * @return the descriptive name of this plugin.
084: */
085: public String getDescriptiveName() {
086: return "SybaseASE Plugin";
087: }
088:
089: /**
090: * Returns the current version of this plugin.
091: *
092: * @return the current version of this plugin.
093: */
094: public String getVersion() {
095: return "0.02";
096: }
097:
098: /**
099: * Returns the authors name.
100: *
101: * @return the authors name.
102: */
103: public String getAuthor() {
104: return "Ken McCullough";
105: }
106:
107: /**
108: * Returns the name of the change log for the plugin. This should
109: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
110: * directory.
111: *
112: * @return the changelog file name or <TT>null</TT> if plugin doesn't have
113: * a change log.
114: */
115: public String getChangeLogFileName() {
116: return "changes.txt";
117: }
118:
119: /**
120: * Returns the name of the Help file for the plugin. This should
121: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
122: * directory.
123: *
124: * @return the Help file name or <TT>null</TT> if plugin doesn't have
125: * a help file.
126: */
127: public String getHelpFileName() {
128: return "readme.txt";
129: }
130:
131: /**
132: * Returns the name of the Licence file for the plugin. This should
133: * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
134: * directory.
135: *
136: * @return the Licence file name or <TT>null</TT> if plugin doesn't have
137: * a licence file.
138: */
139: public String getLicenceFileName() {
140: return "licence.txt";
141: }
142:
143: /**
144: * @return Comma separated list of contributors.
145: */
146: public String getContributors() {
147: return "";
148: }
149:
150: /**
151: * Create preferences panel for the Global Preferences dialog.
152: *
153: * @return Preferences panel.
154: */
155: public IGlobalPreferencesPanel[] getGlobalPreferencePanels() {
156: boolean includeProcSepPref = false;
157:
158: PluginQueryTokenizerPreferencesPanel _prefsPanel = new PluginQueryTokenizerPreferencesPanel(
159: _prefsManager, SCRIPT_SETTINGS_BORDER_LABEL_DBNAME,
160: includeProcSepPref);
161:
162: PluginGlobalPreferencesTab tab = new PluginGlobalPreferencesTab(
163: _prefsPanel);
164:
165: tab.setHint(i18n.hint);
166: tab.setTitle(i18n.title);
167:
168: return new IGlobalPreferencesPanel[] { tab };
169: }
170:
171: /**
172: * Determines from the user's preference whether or not to install the
173: * custom query tokenizer, and if so configure installs it.
174: *
175: * @param session the session to install the custom query tokenizer in.
176: */
177: private void installSybaseQueryTokenizer(ISession session) {
178: IQueryTokenizerPreferenceBean _prefs = _prefsManager
179: .getPreferences();
180:
181: if (_prefs.isInstallCustomQueryTokenizer()) {
182: session.setQueryTokenizer(new SybaseQueryTokenizer(_prefs));
183: }
184: }
185:
186: /**
187: * Initialize this plugin.
188: */
189: public synchronized void initialize() throws PluginException {
190: _resources = new PluginResources(
191: "net.sourceforge.squirrel_sql.plugins.SybaseASE.SybaseASE",
192: this );
193: _prefsManager = new PluginQueryTokenizerPreferencesManager();
194: _prefsManager.initialize(this , new SybasePreferenceBean());
195:
196: }
197:
198: /**
199: * Called when a session started. Add commands to popup menu
200: * in object tree.
201: *
202: * @param session The session that is starting.
203: *
204: * @return An implementation of PluginSessionCallback or null to indicate
205: * the plugin does not work with this session
206: */
207: public PluginSessionCallback sessionStarted(ISession session) {
208: if (!isPluginSession(session)) {
209: return null;
210: }
211: installSybaseQueryTokenizer(session);
212: String stmtSep = session.getQueryTokenizer()
213: .getSQLStatementSeparator();
214:
215: // Add context menu items to the object tree's view and procedure nodes.
216: IObjectTreeAPI otApi = session.getSessionInternalFrame()
217: .getObjectTreeAPI();
218: otApi.addToPopup(DatabaseObjectType.VIEW,
219: new ScriptSybaseASEViewAction(getApplication(),
220: _resources, session));
221: otApi.addToPopup(DatabaseObjectType.PROCEDURE,
222: new ScriptSybaseASEProcedureAction(getApplication(),
223: _resources, session));
224:
225: otApi.addDetailTab(DatabaseObjectType.VIEW, new ViewSourceTab(
226: i18n.SHOW_VIEW_SOURCE, stmtSep));
227:
228: TableWithChildNodesExpander tableExp = new TableWithChildNodesExpander();
229: tableExp
230: .setTableIndexExtractor(new SybaseTableIndexExtractorImpl());
231: tableExp
232: .setTableTriggerExtractor(new SybaseTableTriggerExtractorImpl());
233: otApi.addExpander(DatabaseObjectType.TABLE, tableExp);
234:
235: otApi.addDetailTab(DatabaseObjectType.INDEX,
236: new DatabaseObjectInfoTab());
237: //otApi.addDetailTab(DatabaseObjectType.INDEX, new IndexDetailsTab());
238: otApi.addDetailTab(DatabaseObjectType.TRIGGER,
239: new DatabaseObjectInfoTab());
240: otApi.addDetailTab(DatabaseObjectType.TRIGGER_TYPE_DBO,
241: new DatabaseObjectInfoTab());
242:
243: otApi.addDetailTab(DatabaseObjectType.TRIGGER,
244: new TriggerSourceTab(i18n.TRIGGER_HINT, stmtSep));
245:
246: return new PluginSessionCallback() {
247: public void sqlInternalFrameOpened(
248: SQLInternalFrame sqlInternalFrame, ISession sess) {
249: //plugin supports Session main window only
250: }
251:
252: public void objectTreeInternalFrameOpened(
253: ObjectTreeInternalFrame objectTreeInternalFrame,
254: ISession sess) {
255: //plugin supports Session main window only
256: }
257: };
258: }
259:
260: @Override
261: protected boolean isPluginSession(ISession session) {
262: return DialectFactory.isSyBase(session.getMetaData());
263: }
264:
265: }
|