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