001: package net.sourceforge.squirrel_sql.client.session.mainpanel;
002:
003: /*
004: * Copyright (C) 2001-2003 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.util.log.ILogger;
022: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
023:
024: import net.sourceforge.squirrel_sql.client.session.ISession;
025:
026: /**
027: * Base class for tabs to the added to the main tabbed panel.
028: *
029: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
030: */
031: public abstract class BaseMainPanelTab implements IMainPanelTab {
032: /** Logger for this class. */
033: private static ILogger s_log = LoggerController
034: .createLogger(BaseMainPanelTab.class);
035:
036: /** Current session. */
037: private ISession _session;
038:
039: /** Set to <TT>true</TT> once this tab has been displayed. */
040: private boolean _hasBeenDisplayed;
041:
042: /**
043: * Set the current session.
044: *
045: * @param session Current session.
046: *
047: * @throws IllegalArgumentException
048: * Thrown if a <TT>null</TT> ISession</TT> passed.
049: */
050: public void setSession(ISession session) {
051: if (session == null) {
052: throw new IllegalArgumentException("Null ISession passed");
053: }
054: _session = session;
055: }
056:
057: /**
058: * The current session is closing.
059: *
060: * @param session Current session.
061: */
062: public void sessionClosing(ISession session) {
063: // Empty method.
064: }
065:
066: /**
067: * Retrieve the current session.
068: *
069: * @return Current session.
070: */
071: public final ISession getSession() {
072: return _session;
073: }
074:
075: /**
076: * This tab has been selected. This will call <TT>refreshComponent()</TT>
077: * only if it hasn't been called.
078: */
079: public synchronized void select() {
080: if (!_hasBeenDisplayed) {
081: s_log.debug("Refreshing " + getTitle() + " main tab.");
082: refreshComponent();
083: _hasBeenDisplayed = true;
084: }
085: }
086:
087: /**
088: * Refresh the component.
089: */
090: protected abstract void refreshComponent();
091:
092: /**
093: * When a session is ending, if it happens to be the one this class is using,
094: * then set our reference to null to allow it to be GC'd.
095: *
096: * @param session the session that is ending.
097: */
098: public void sessionEnding(ISession session) {
099: if (_session == session) {
100: _session = null;
101: }
102: }
103: }
|