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 java.awt.Component;
022:
023: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetException;
024: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetScrollingPanel;
025: import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSet;
026: import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSetUpdateableModel;
027: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
028: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
029:
030: import net.sourceforge.squirrel_sql.client.session.ISession;
031:
032: public abstract class BaseDataSetTab extends BaseObjectTab {
033: /** Logger for this class. */
034: private static final ILogger s_log = LoggerController
035: .createLogger(BaseDataSetTab.class);
036:
037: /** Component to display in tab. */
038: private DataSetScrollingPanel _comp;
039:
040: public BaseDataSetTab() {
041: super ();
042: }
043:
044: /**
045: * Return the component to be displayed in the panel.
046: *
047: * @return The component to be displayed in the panel.
048: */
049: public synchronized Component getComponent() {
050: if (_comp == null) {
051: try {
052: /*
053: * If the object representing the actual data (i.e. this object)
054: * can be edited by the user, then the fw objects need to have
055: * a reference to it. Updateable objects must implement an
056: * interface derived from IDataSetUpdateableComponent in the
057: * net.sourceforge.squirrel_sql.fw.datasetviewer package.
058: * If the component does not implement that interface,
059: * then we just keep going, but if it does implement it,
060: * then we need to tell the DataSetScrollingPanel that the
061: * object that fw needs to call is this one.
062: */
063: IDataSetUpdateableModel modelReference = null; // default is no reference
064: try {
065: // we need the try/catch just to keep the compiler happy
066: if (Class
067: .forName(
068: "net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSetUpdateableModel")
069: .isAssignableFrom(this .getClass())) {
070: modelReference = ((IDataSetUpdateableModel) this );
071: }
072: } catch (Exception ignore) {
073: // any errors here result in an un-editable table, which
074: // should be no problem
075: }
076:
077: _comp = new DataSetScrollingPanel(
078: getDestinationClassName(), modelReference);
079: } catch (Exception ex) {
080: s_log.error("Error", ex);
081: }
082: }
083: return _comp;
084: }
085:
086: /**
087: * Rebuild the tab. This usually means that some kind of configuration
088: * data has changed (I.E. the output type has changed from text to table).
089: */
090: public void rebuild() {
091: super .rebuild();
092: _comp = null;
093: }
094:
095: /**
096: * @see BaseObjectPanelTab#clear()
097: */
098: public void clear() {
099: ((DataSetScrollingPanel) getComponent()).clear();
100: }
101:
102: /**
103: * Refresh the component displaying the database object.
104: */
105: public synchronized void refreshComponent() throws DataSetException {
106: ISession session = getSession();
107: if (session == null) {
108: throw new IllegalStateException("Null ISession");
109: }
110: super ._app.getThreadPool().addTask(new Runnable() {
111: public void run() {
112: try {
113: ((DataSetScrollingPanel) getComponent())
114: .load(createDataSet());
115: } catch (DataSetException e) {
116: s_log.error("", e);
117: }
118: }
119: });
120:
121: }
122:
123: protected abstract IDataSet createDataSet() throws DataSetException;
124:
125: protected String getDestinationClassName() {
126: return getSession().getProperties()
127: .getMetaDataOutputClassName();
128: }
129: }
|