001: package net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs;
002:
003: /*
004: * Copyright (C) 2001-2002 Colin Bell
005: * colbell@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: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetException;
022: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
023: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
024: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
025: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
026:
027: import net.sourceforge.squirrel_sql.client.IApplication;
028: import net.sourceforge.squirrel_sql.client.session.ISession;
029:
030: /**
031: * Base class for tabs to the added to one of the object panels.
032: *
033: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
034: */
035: public abstract class BaseObjectTab implements IObjectTab {
036: /** Logger for this class. */
037: private static final ILogger s_log = LoggerController
038: .createLogger(BaseObjectTab.class);
039:
040: /** Application API. */
041: protected IApplication _app;
042:
043: /** Current session. */
044: // private ISession _session;
045: /** ID of the session for this window. */
046: private IIdentifier _sessionId;
047:
048: /** Defines the object that info is to be displayed for. */
049: private IDatabaseObjectInfo _dbObjInfo;
050:
051: /**
052: * Set to <TT>true</TT> if the current <TT>IDatabaseObjectInfo</TT> object
053: * has been displayed.
054: */
055: private boolean _hasBeenDisplayed;
056:
057: /**
058: * Set the current session.
059: *
060: * @param session Current session.
061: *
062: * @throws IllegalArgumentException
063: * Thrown if a <TT>null</TT> ISession</TT> passed.
064: */
065: public void setSession(ISession session)
066: throws IllegalArgumentException {
067: if (session == null) {
068: throw new IllegalArgumentException("Null ISession passed");
069: }
070: _app = session.getApplication();
071: // _session = session;
072: _sessionId = session.getIdentifier();
073: }
074:
075: /**
076: * Retrieve the current session.
077: *
078: * @return Current session.
079: */
080: public final ISession getSession() {
081: // return _session;
082: return _app.getSessionManager().getSession(_sessionId);
083: }
084:
085: /**
086: * This tab has been selected. This will call <TT>refreshComponent()</TT>
087: * only if it hasn't been called for the current MTT>IDatabaseObjectInfo</TT> object.
088: *
089: * @throws IllegalStateException
090: * Thrown if a <TT>null</TT> <TT>ISession</TT> or
091: * <TT>IDatabaseObjectInfo</TT> object is stored here.
092: */
093: public synchronized void select() {
094: if (!_hasBeenDisplayed) {
095: s_log.debug("Refreshing " + getTitle() + " table tab.");
096: try {
097: clear();
098: refreshComponent();
099: } catch (Throwable th) {
100: getSession().showErrorMessage(th);
101: }
102: _hasBeenDisplayed = true;
103: }
104: }
105:
106: /**
107: * Rebuild the tab. This usually means that some kind of configuration
108: * data has changed (I.E. the output type has changed from text to table).
109: */
110: public void rebuild() {
111: _hasBeenDisplayed = false;
112: }
113:
114: /**
115: * Refresh the component displaying the <TT>IDatabaseObjectInfo</TT> object.
116: */
117: protected abstract void refreshComponent() throws DataSetException;
118:
119: /**
120: * Set the <TT>IDatabaseObjectInfo</TT> object that specifies the object that
121: * is to have its information displayed.
122: *
123: * @param value <TT>IDatabaseObjectInfo</TT> object that specifies the currently
124: * selected object. This can be <TT>null</TT>.
125: */
126: public void setDatabaseObjectInfo(IDatabaseObjectInfo value) {
127: _dbObjInfo = value;
128: _hasBeenDisplayed = false;
129: }
130:
131: /**
132: * Retrieve the current <TT>IDatabaseObjectInfo</TT> object.
133: *
134: * @return Current <TT>IDatabaseObjectInfo</TT> object.
135: */
136: protected final IDatabaseObjectInfo getDatabaseObjectInfo() {
137: return _dbObjInfo;
138: }
139: }
|