001: package net.sourceforge.squirrel_sql.client.session;
002:
003: /*
004: * Copyright (C) 2001-2004 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * Modifications Copyright (C) 2003-2004 Jason Height
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: import java.sql.SQLException;
024:
025: import javax.swing.Action;
026: import javax.swing.JComponent;
027:
028: import net.sourceforge.squirrel_sql.client.IApplication;
029: import net.sourceforge.squirrel_sql.client.gui.db.ISQLAliasExt;
030: import net.sourceforge.squirrel_sql.client.gui.session.BaseSessionInternalFrame;
031: import net.sourceforge.squirrel_sql.client.gui.session.MainPanel;
032: import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
033: import net.sourceforge.squirrel_sql.client.gui.session.SessionPanel;
034: import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
035: import net.sourceforge.squirrel_sql.client.session.mainpanel.IMainPanelTab;
036: import net.sourceforge.squirrel_sql.client.session.parser.IParserEventsProcessor;
037: import net.sourceforge.squirrel_sql.client.session.properties.SessionProperties;
038: import net.sourceforge.squirrel_sql.fw.id.IHasIdentifier;
039: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
040: import net.sourceforge.squirrel_sql.fw.sql.IQueryTokenizer;
041: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
042: import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
043: import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
044: import net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter;
045: import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
046:
047: /**
048: * The current session.
049: */
050: public interface ISession extends IHasIdentifier {
051:
052: public interface IMainPanelTabIndexes extends MainPanel.ITabIndexes {
053: // Empty body.
054: }
055:
056: /**
057: * Retrieve whether this session has been closed.
058: *
059: * @return <TT>true</TT> if session closed else <TT>false</TT>.
060: */
061: boolean isClosed();
062:
063: /**
064: * Return the Application API object.
065: *
066: * @return the Application API object.
067: */
068: IApplication getApplication();
069:
070: /**
071: * Return the current SQL connection object.
072: *
073: * @return the current SQL connection object.
074: */
075: ISQLConnection getSQLConnection();
076:
077: /**
078: * Return the current SQL connection database metadata.
079: *
080: * @return the current SQL connection database metadata.
081: */
082: ISQLDatabaseMetaData getMetaData();
083:
084: /**
085: * Return the driver used to connect to the database.
086: *
087: * @return the driver used to connect to the database.
088: */
089: ISQLDriver getDriver();
090:
091: /**
092: * Return the alias used to connect to the database.
093: *
094: * @return the alias used to connect to the database.
095: */
096: ISQLAliasExt getAlias();
097:
098: /**
099: * Return the properties for this session.
100: *
101: * @return the properties for this session.
102: */
103: SessionProperties getProperties();
104:
105: /**
106: * Commit the current SQL session.
107: */
108: void commit();
109:
110: /**
111: * Rollback the current SQL session.
112: */
113: void rollback();
114:
115: /**
116: * Close this session.
117: *
118: * @throws SQLException
119: * Thrown if an error closing the SQL connection. The session
120: * will still be closed even though the connection may not have
121: * been.
122: */
123: void close() throws SQLException;
124:
125: /**
126: * Close the current connection to the database.
127: *
128: * @throws SQLException if an SQL error occurs.
129: */
130: void closeSQLConnection() throws SQLException;
131:
132: void setSessionInternalFrame(SessionInternalFrame sif);
133:
134: /**
135: * Reconnect to the database.
136: */
137: void reconnect();
138:
139: Object getPluginObject(IPlugin plugin, String key);
140:
141: Object putPluginObject(IPlugin plugin, String key, Object obj);
142:
143: void removePluginObject(IPlugin plugin, String key);
144:
145: void setMessageHandler(IMessageHandler handler);
146:
147: SessionPanel getSessionSheet();
148:
149: SessionInternalFrame getSessionInternalFrame();
150:
151: // JASON:
152: // SQLFilterClauses getSQLFilterClauses();
153:
154: /**
155: * Retrieve the schema information object for this session.
156: */
157: net.sourceforge.squirrel_sql.client.session.schemainfo.SchemaInfo getSchemaInfo();
158:
159: /**
160: * Select a tab in the main tabbed pane.
161: *
162: * @param tabIndex The tab to select. @see #IMainTabIndexes
163: *
164: * @throws IllegalArgumentException
165: * Thrown if an invalid <TT>tabIndex</TT> passed.
166: */
167: void selectMainTab(int tabIndex) throws IllegalArgumentException;
168:
169: /**
170: * Add a tab to the main tabbed panel.
171: *
172: * @param tab The tab to be added.
173: *
174: * @return the index of the new tab that was added.
175: *
176: * @throws IllegalArgumentException
177: * Thrown if a <TT>null</TT> <TT>IMainPanelTab</TT> passed.
178: */
179: int addMainTab(IMainPanelTab tab);
180:
181: /**
182: * Add component to the session sheets status bar.
183: *
184: * @param comp Component to add.
185: */
186: void addToStatusBar(JComponent comp);
187:
188: /**
189: * Remove component to the session sheets status bar.
190: *
191: * @param comp Component to remove.
192: */
193: void removeFromStatusBar(JComponent comp);
194:
195: /**
196: * Add a listener to this session
197: *
198: * @param lis The listener to add.
199: *
200: * @throws IllegalArgumentException
201: * Thrown if a <TT>null</TT> listener passed.
202: */
203: // JASON: Removed as part of patch
204: // void addSessionListener(ISessionListener lis);
205: /**
206: * Remove a listener from this session
207: *
208: * @param lis The listener to remove.
209: *
210: * @throws IllegalArgumentException
211: * Thrown if a <TT>null</TT> listener passed.
212: */
213: // JASON: Removed as part of patch
214: // void removeSessionListener(ISessionListener lis);
215: /**
216: * Retrieve the descriptive title of this session.
217: *
218: * @return The descriptive title of this session.
219: */
220: String getTitle();
221:
222: /**
223: * Add the passed action to the toolbar of the sessions main window.
224: *
225: * @param action Action to be added.
226: */
227: void addToToolbar(Action action);
228:
229: public void addSeparatorToToolbar();
230:
231: /**
232: * The code in any SQLEditor is parsed in the background. You may attach a listener to the ParserEventsProcessor
233: * to get to know about the results of parsing. The events are passed synchron with the event queue
234: * (via SwingUtils.invokeLater()). At the moment events are produced for errors in the SQLScript
235: * which are highlighted in the syntax plugin and for aliases of table names which are used in the
236: * code completion plugin.
237: * <p>
238: * If you want the ParserEventsProcessor to produce further events feel free to contact gerdwagner@users.sourceforge.net.
239: */
240: IParserEventsProcessor getParserEventsProcessor(
241: IIdentifier sqlEntryPanelIdentifier);
242:
243: void setActiveSessionWindow(
244: BaseSessionInternalFrame activeActiveSessionWindow);
245:
246: /**
247: * Hint for plugins:
248: * When ISessionPlugin.sessionStarted is called the active session window is
249: * always the SessionInternalFrame which provides an SQLPanelAPI. This might help to simplyfy
250: * the code in the sessionStarted() method of a plugin.
251: */
252: BaseSessionInternalFrame getActiveSessionWindow();
253:
254: /**
255: * Hint for plugins:
256: * When ISessionPlugin.sessionStarted is called the active session window is
257: * always the SessionInternalFrame which provides an SQLPanelAPI. This might help to simplyfy
258: * the code in the sessionStarted() method of a plugin.
259: *
260: * @throws IllegalStateException if ActiveSessionWindow doesn't provide an SQLPanelAPI
261: * for example if it is an ObjectTreeInternalFrame
262: */
263: ISQLPanelAPI getSQLPanelAPIOfActiveSessionWindow();
264:
265: /**
266: *
267: * Hint for plugins:
268: * When ISessionPlugin.sessionStarted is called the active session window is
269: * always the SessionInternalFrame which provides an SQLPanelAPI. This might help to simplyfy
270: * the code in the sessionStarted() method of a plugin.
271: *
272: * @throws IllegalStateException if ActiveSessionWindow doesn't provide an IObjectTreeAPI
273: * for example if it is an SQLInternalFrame
274: */
275: IObjectTreeAPI getObjectTreeAPIOfActiveSessionWindow();
276:
277: /**
278: * @return Returns the _finishedLoading.
279: */
280: public boolean isfinishedLoading();
281:
282: /**
283: * @param _finishedLoading The _finishedLoading to set.
284: */
285: public void setPluginsfinishedLoading(boolean _finishedLoading);
286:
287: /**
288: * Determine from the session whether or not it is ok to close it. It might
289: * be the case that the session's SQLPanel has unsaved edits that require
290: * the user's approval to discard.
291: *
292: * @return true if it's ok to close the session; false otherwise.
293: */
294: public boolean confirmClose();
295:
296: /**
297: * Sets the IQueryTokenizer implementation to use for this session.
298: *
299: * @param tokenizer
300: */
301: public void setQueryTokenizer(IQueryTokenizer tokenizer);
302:
303: /**
304: * Returns the IQueryTokenizer implementation to use for tokenizing scripts
305: * statements that should be sent to the server.
306: *
307: * @return an implementation of IQueryTokenizer
308: */
309: IQueryTokenizer getQueryTokenizer();
310:
311: /**
312: * Sets the exception formatter to use when handling messages.
313: *
314: * @param formatter
315: * the ExceptionFormatter
316: * @param session TODO
317: */
318: void setExceptionFormatter(ExceptionFormatter formatter);
319:
320: /**
321: * Returns the exception formatter to use when handling messages.
322: *
323: * @return
324: */
325: ExceptionFormatter getExceptionFormatter();
326:
327: /**
328: * Facade method for ExceptionFormatter to allow callers to safely get a
329: * formatted exception without forcing them to wrap it in a try/catch block
330: *
331: * @param t the exception to format
332: *
333: * @return the context of the exception, in default or custom format,
334: * depending on whether or not a custom ExceptionFormatter was
335: * installed.
336: */
337: String formatException(Throwable t);
338:
339: // Facade methods for IMessageHandler. We don't want to allow code to
340: // directly access an internal IMessageHandler, now that the IMessageHandler
341: // interface requires an ExceptionFormatter to be injected for methods that
342: // accept Exceptions.
343:
344: /**
345: * Show a message describing the passed exception. This will apply
346: * any custom formatting if an ExceptionFormatter has been set.
347: *
348: * @param th the exception to be shown
349: */
350: void showMessage(Throwable th);
351:
352: /**
353: * Show a message.
354: *
355: * @param msg
356: * The message.
357: */
358: void showMessage(String msg);
359:
360: /**
361: * Show an error message describing the passed exception. This will apply
362: * any custom formatting if an ExceptionFormatter has been set.
363: *
364: * @param th the exception to be shown
365: */
366: void showErrorMessage(Throwable th);
367:
368: /**
369: * Show an error message. The implementation of <TT>IMessageHandler</TT>
370: * may or may not treat this differently to <TT>showMessage(String)</TT>.
371: * @param session the session that generated the exception.
372: * @param th
373: * Exception.
374: */
375: void showErrorMessage(String msg);
376:
377: void showWarningMessage(String msg);
378:
379: }
|