001: package org.firebirdsql.squirrel;
002:
003: import javax.swing.JMenu;
004:
005: import net.sourceforge.squirrel_sql.client.IApplication;
006: import net.sourceforge.squirrel_sql.client.action.ActionCollection;
007: import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
008: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
009: import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
010: import net.sourceforge.squirrel_sql.client.plugin.PluginException;
011: import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
012: import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
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.gui.GUIUtils;
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:
023: import org.firebirdsql.squirrel.act.ActivateIndexAction;
024: import org.firebirdsql.squirrel.act.DeactivateIndexAction;
025: import org.firebirdsql.squirrel.exp.DatabaseExpander;
026: import org.firebirdsql.squirrel.exp.FirebirdTableIndexExtractorImpl;
027: import org.firebirdsql.squirrel.exp.FirebirdTableTriggerExtractorImpl;
028: import org.firebirdsql.squirrel.exp.AllIndexesParentExpander;
029: import org.firebirdsql.squirrel.tab.DomainDetailsTab;
030: import org.firebirdsql.squirrel.tab.GeneratorDetailsTab;
031: import org.firebirdsql.squirrel.tab.IndexInfoTab;
032: import org.firebirdsql.squirrel.tab.ProcedureSourceTab;
033: import org.firebirdsql.squirrel.tab.TriggerDetailsTab;
034: import org.firebirdsql.squirrel.tab.TriggerSourceTab;
035: import org.firebirdsql.squirrel.tab.ViewSourceTab;
036:
037: public class FirebirdPlugin extends DefaultSessionPlugin {
038:
039: private static final StringManager s_stringMgr = StringManagerFactory
040: .getStringManager(FirebirdPlugin.class);
041:
042: /** API for the Obejct Tree. */
043: private IObjectTreeAPI _treeAPI;
044:
045: /** Plugin resources. */
046: private PluginResources _resources;
047:
048: /** Firebird menu. */
049: private JMenu _firebirdMenu;
050:
051: /**
052: * Return the internal name of this plugin.
053: *
054: * @return the internal name of this plugin.
055: */
056: public String getInternalName() {
057: return "firebird";
058: }
059:
060: /**
061: * Return the descriptive name of this plugin.
062: *
063: * @return the descriptive name of this plugin.
064: */
065: public String getDescriptiveName() {
066: return "Firebird Plugin";
067: }
068:
069: /**
070: * Returns the current version of this plugin.
071: *
072: * @return the current version of this plugin.
073: */
074: public String getVersion() {
075: return "0.02";
076: }
077:
078: /**
079: * Returns the authors name.
080: *
081: * @return the authors name.
082: */
083: public String getAuthor() {
084: return "Roman Rokytskyy";
085: }
086:
087: /**
088: * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getChangeLogFileName()
089: */
090: public String getChangeLogFileName() {
091: return "changes.txt";
092: }
093:
094: /**
095: * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getHelpFileName()
096: */
097: public String getHelpFileName() {
098: return "readme.html";
099: }
100:
101: /**
102: * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getLicenceFileName()
103: */
104: public String getLicenceFileName() {
105: return "licence.txt";
106: }
107:
108: /**
109: * Load this plugin.
110: *
111: * @param app Application API.
112: */
113: public synchronized void load(IApplication app)
114: throws PluginException {
115: super .load(app);
116: _resources = new FirebirdResources(getClass().getName(), this );
117: }
118:
119: /**
120: * Initialize this plugin.
121: */
122: public synchronized void initialize() throws PluginException {
123: super .initialize();
124: final IApplication app = getApplication();
125: final ActionCollection coll = app.getActionCollection();
126:
127: coll.add(new ActivateIndexAction(app, _resources, this ));
128: coll.add(new DeactivateIndexAction(app, _resources, this ));
129:
130: _firebirdMenu = createFirebirdMenu();
131: app
132: .addToMenu(IApplication.IMenuIDs.SESSION_MENU,
133: _firebirdMenu);
134: super .registerSessionMenu(_firebirdMenu);
135: }
136:
137: /**
138: * Application is shutting down so save preferences.
139: */
140: public void unload() {
141: super .unload();
142: }
143:
144: public boolean allowsSessionStartedInBackground() {
145: return true;
146: }
147:
148: /**
149: * Session has been started. If this is an Oracle session then
150: * register an extra expander for the Schema nodes to show
151: * Oracle Packages.
152: *
153: * @param session Session that has started.
154: *
155: * @return <TT>true</TT> if session is Oracle in which case this plugin
156: * is interested in it.
157: */
158: public PluginSessionCallback sessionStarted(final ISession session) {
159: if (!isPluginSession(session)) {
160: return null;
161: }
162: GUIUtils.processOnSwingEventThread(new Runnable() {
163: public void run() {
164: updateTreeApi(session);
165: }
166: });
167: return new PluginSessionCallback() {
168: public void sqlInternalFrameOpened(
169: SQLInternalFrame sqlInternalFrame, ISession sess) {
170: // Supports Session main window only
171: }
172:
173: public void objectTreeInternalFrameOpened(
174: ObjectTreeInternalFrame objectTreeInternalFrame,
175: ISession sess) {
176: // Supports Session main window only
177: }
178: };
179: }
180:
181: @Override
182: protected boolean isPluginSession(ISession session) {
183: return DialectFactory.isFirebird(session.getMetaData());
184: }
185:
186: private void updateTreeApi(ISession session) {
187: _treeAPI = session.getSessionInternalFrame().getObjectTreeAPI();
188:
189: // Tabs to add to the database node.
190: _treeAPI.addDetailTab(DatabaseObjectType.SEQUENCE,
191: new DatabaseObjectInfoTab());
192: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
193: new DatabaseObjectInfoTab());
194: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER_TYPE_DBO,
195: new DatabaseObjectInfoTab());
196: _treeAPI.addDetailTab(DatabaseObjectType.INDEX,
197: new DatabaseObjectInfoTab());
198: _treeAPI.addDetailTab(DatabaseObjectType.INDEX,
199: new IndexInfoTab());
200:
201: // Expanders.
202: _treeAPI.addExpander(IObjectTypes.INDEX_PARENT,
203: new AllIndexesParentExpander());
204:
205: _treeAPI.addExpander(DatabaseObjectType.SESSION,
206: new DatabaseExpander(this ));
207:
208: TableWithChildNodesExpander tableExp = new TableWithChildNodesExpander();
209: tableExp
210: .setTableTriggerExtractor(new FirebirdTableTriggerExtractorImpl());
211: tableExp
212: .setTableIndexExtractor(new FirebirdTableIndexExtractorImpl());
213: _treeAPI.addExpander(DatabaseObjectType.TABLE, tableExp);
214:
215: _treeAPI.addDetailTab(DatabaseObjectType.SEQUENCE,
216: new GeneratorDetailsTab());
217: _treeAPI.addDetailTab(DatabaseObjectType.DATATYPE,
218: new DomainDetailsTab());
219: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
220: new TriggerDetailsTab());
221: // i18n[firebird.showTrigger=Show trigger source]
222: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
223: new TriggerSourceTab(s_stringMgr
224: .getString("firebird.showTrigger")));
225: // i18n[firebird.showProcedureSource=Show procedure source]
226: _treeAPI.addDetailTab(DatabaseObjectType.PROCEDURE,
227: new ProcedureSourceTab(s_stringMgr
228: .getString("firebird.showProcedureSource")));
229: // i18n[firebird.showView=Show view source]
230: _treeAPI.addDetailTab(DatabaseObjectType.VIEW,
231: new ViewSourceTab(s_stringMgr
232: .getString("firebird.showView")));
233:
234: final ActionCollection coll = getApplication()
235: .getActionCollection();
236: _treeAPI.addToPopup(DatabaseObjectType.INDEX, coll
237: .get(ActivateIndexAction.class));
238: _treeAPI.addToPopup(DatabaseObjectType.INDEX, coll
239: .get(DeactivateIndexAction.class));
240: }
241:
242: /**
243: * Create menu containing all Firebird actions.
244: *
245: * @return The menu object.
246: */
247: private JMenu createFirebirdMenu() {
248: final IApplication app = getApplication();
249: final ActionCollection coll = app.getActionCollection();
250:
251: final JMenu firebirdMenu = _resources
252: .createMenu(FirebirdResources.IMenuResourceKeys.FIREBIRD);
253:
254: _resources.addToMenu(coll.get(ActivateIndexAction.class),
255: firebirdMenu);
256: _resources.addToMenu(coll.get(DeactivateIndexAction.class),
257: firebirdMenu);
258:
259: return firebirdMenu;
260: }
261:
262: }
|