001: package net.sourceforge.squirrel_sql.plugins.informix;
002:
003: /*
004: * Copyright (C) 2006 Rob Manning
005: * manningr@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:
022: import net.sourceforge.squirrel_sql.client.IApplication;
023: import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
024: import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
025: import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
026: import net.sourceforge.squirrel_sql.client.plugin.PluginException;
027: import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
028: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
029: import net.sourceforge.squirrel_sql.client.session.ISession;
030: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.TableWithChildNodesExpander;
031: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.DatabaseObjectInfoTab;
032: import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
033: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
034: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
035: import net.sourceforge.squirrel_sql.fw.util.StringManager;
036: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
037: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
038: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
039: import net.sourceforge.squirrel_sql.plugins.informix.exception.InformixExceptionFormatter;
040: import net.sourceforge.squirrel_sql.plugins.informix.exp.InformixTableIndexExtractorImpl;
041: import net.sourceforge.squirrel_sql.plugins.informix.exp.InformixTableTriggerExtractorImpl;
042: import net.sourceforge.squirrel_sql.plugins.informix.exp.SchemaExpander;
043: import net.sourceforge.squirrel_sql.plugins.informix.tab.IndexDetailsTab;
044: import net.sourceforge.squirrel_sql.plugins.informix.tab.ProcedureSourceTab;
045: import net.sourceforge.squirrel_sql.plugins.informix.tab.SequenceDetailsTab;
046: import net.sourceforge.squirrel_sql.plugins.informix.tab.TriggerDetailsTab;
047: import net.sourceforge.squirrel_sql.plugins.informix.tab.TriggerSourceTab;
048: import net.sourceforge.squirrel_sql.plugins.informix.tab.ViewSourceTab;
049:
050: /**
051: * The main controller class for the Informix plugin.
052: *
053: * @author manningr
054: */
055: public class InformixPlugin extends DefaultSessionPlugin {
056:
057: private static final StringManager s_stringMgr = StringManagerFactory
058: .getStringManager(InformixPlugin.class);
059:
060: /** Logger for this class. */
061: @SuppressWarnings("unused")
062: private final static ILogger s_log = LoggerController
063: .createLogger(InformixPlugin.class);
064:
065: /** API for the Obejct Tree. */
066: private IObjectTreeAPI _treeAPI;
067:
068: static interface i18n {
069: //i18n[InformixPlugin.showViewSource=Show view source]
070: String SHOW_VIEW_SOURCE = s_stringMgr
071: .getString("InformixPlugin.showViewSource");
072:
073: //i18n[InformixPlugin.showProcedureSource=Show procedure source]
074: String SHOW_PROCEDURE_SOURCE = s_stringMgr
075: .getString("InformixPlugin.showProcedureSource");
076: }
077:
078: /**
079: * Return the internal name of this plugin.
080: *
081: * @return the internal name of this plugin.
082: */
083: public String getInternalName() {
084: return "informix";
085: }
086:
087: /**
088: * Return the descriptive name of this plugin.
089: *
090: * @return the descriptive name of this plugin.
091: */
092: public String getDescriptiveName() {
093: return "Informix Plugin";
094: }
095:
096: /**
097: * Returns the current version of this plugin.
098: *
099: * @return the current version of this plugin.
100: */
101: public String getVersion() {
102: return "0.03";
103: }
104:
105: /**
106: * Returns the authors name.
107: *
108: * @return the authors name.
109: */
110: public String getAuthor() {
111: return "Rob Manning";
112: }
113:
114: /**
115: * Returns a comma separated list of other contributors.
116: *
117: * @return Contributors names.
118: */
119: public String getContributors() {
120: return "Doug Lawry";
121: }
122:
123: /**
124: * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getChangeLogFileName()
125: */
126: public String getChangeLogFileName() {
127: return "changes.txt";
128: }
129:
130: /**
131: * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getHelpFileName()
132: */
133: public String getHelpFileName() {
134: return "readme.html";
135: }
136:
137: /**
138: * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getLicenceFileName()
139: */
140: public String getLicenceFileName() {
141: return "licence.txt";
142: }
143:
144: /**
145: * Load this plugin.
146: *
147: * @param app Application API.
148: */
149: public synchronized void load(IApplication app)
150: throws PluginException {
151: super .load(app);
152: }
153:
154: /**
155: * Initialize this plugin.
156: */
157: public synchronized void initialize() throws PluginException {
158: super .initialize();
159: }
160:
161: /**
162: * Application is shutting down so save preferences.
163: */
164: public void unload() {
165: super .unload();
166: }
167:
168: public boolean allowsSessionStartedInBackground() {
169: return true;
170: }
171:
172: /**
173: * Session has been started. Update the tree api in using the event thread
174: *
175: * @param session Session that has started.
176: *
177: * @return <TT>true</TT> if session is Oracle in which case this plugin
178: * is interested in it.
179: */
180: public PluginSessionCallback sessionStarted(final ISession session) {
181: if (!isPluginSession(session)) {
182: return null;
183: }
184: GUIUtils.processOnSwingEventThread(new Runnable() {
185: public void run() {
186: updateTreeApi(session);
187: }
188: });
189: InformixExceptionFormatter formatter = new InformixExceptionFormatter(
190: session);
191: session.setExceptionFormatter(formatter);
192: return new PluginSessionCallback() {
193: public void sqlInternalFrameOpened(
194: SQLInternalFrame sqlInternalFrame, ISession sess) {
195: // Supports Session main window only
196: }
197:
198: public void objectTreeInternalFrameOpened(
199: ObjectTreeInternalFrame objectTreeInternalFrame,
200: ISession sess) {
201: // Supports Session main window only
202: }
203: };
204: }
205:
206: @Override
207: protected boolean isPluginSession(ISession session) {
208: return DialectFactory.isInformix(session.getMetaData());
209: }
210:
211: private void updateTreeApi(ISession session) {
212: //DatabaseObjectInfoTab dboit = new DatabaseObjectInfoTab();
213:
214: _treeAPI = session.getSessionInternalFrame().getObjectTreeAPI();
215:
216: _treeAPI.addDetailTab(DatabaseObjectType.PROCEDURE,
217: new ProcedureSourceTab(i18n.SHOW_PROCEDURE_SOURCE));
218:
219: _treeAPI.addDetailTab(DatabaseObjectType.VIEW,
220: new ViewSourceTab(i18n.SHOW_VIEW_SOURCE));
221:
222: _treeAPI.addDetailTab(DatabaseObjectType.INDEX,
223: new DatabaseObjectInfoTab());
224: _treeAPI.addDetailTab(DatabaseObjectType.INDEX,
225: new IndexDetailsTab());
226: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
227: new DatabaseObjectInfoTab());
228: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER_TYPE_DBO,
229: new DatabaseObjectInfoTab());
230: _treeAPI.addDetailTab(DatabaseObjectType.SEQUENCE,
231: new DatabaseObjectInfoTab());
232: _treeAPI.addDetailTab(DatabaseObjectType.SEQUENCE,
233: new SequenceDetailsTab());
234:
235: // Expanders - trigger and index expanders are added inside the table
236: // expander
237: _treeAPI.addExpander(DatabaseObjectType.SCHEMA,
238: new SchemaExpander());
239:
240: TableWithChildNodesExpander tableExp = new TableWithChildNodesExpander();
241: tableExp
242: .setTableIndexExtractor(new InformixTableIndexExtractorImpl());
243: tableExp
244: .setTableTriggerExtractor(new InformixTableTriggerExtractorImpl());
245: _treeAPI.addExpander(DatabaseObjectType.TABLE, tableExp);
246:
247: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
248: new TriggerDetailsTab());
249: _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
250: new TriggerSourceTab("The source of the trigger"));
251:
252: }
253:
254: }
|