001: package net.sourceforge.squirrel_sql.fw.datasetviewer;
002:
003: /*
004: * Copyright (C) 2002-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 javax.swing.BorderFactory;
022: import javax.swing.JScrollPane;
023: import javax.swing.SwingUtilities;
024:
025: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
026: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
027:
028: public class DataSetScrollingPanel extends JScrollPane {
029: /** Logger for this class. */
030: private static final ILogger s_log = LoggerController
031: .createLogger(DataSetScrollingPanel.class);
032:
033: private boolean _fullyCreated = false;
034: private IDataSetViewer _viewer;
035:
036: /**
037: * @deprecated
038: */
039: public DataSetScrollingPanel() {
040: super ();
041: }
042:
043: public DataSetScrollingPanel(String destClassName,
044: IDataSetUpdateableModel updateableModel)
045: throws DataSetException {
046: super ();
047: createUserInterface(destClassName, updateableModel);
048: _fullyCreated = true;
049: }
050:
051: public void load(IDataSet ds) {
052: load(ds, null);
053: }
054:
055: /**
056: * @deprecated
057: */
058: public void load(IDataSet ds, String destClassName) {
059: try {
060: if (!_fullyCreated) {
061: createUserInterface(destClassName, null);
062: _fullyCreated = true;
063: }
064: Runnable run = new UIUpdater(_viewer, ds);
065: SwingUtilities.invokeLater(run);
066: } catch (Exception ex) {
067: s_log.error("Error", ex);
068: }
069: }
070:
071: public void clear() {
072: if (_viewer != null) {
073: _viewer.clear();
074: }
075: }
076:
077: private void createUserInterface(String destClassName,
078: IDataSetUpdateableModel updateableModel)
079: throws DataSetException {
080: setBorder(BorderFactory.createEmptyBorder());
081: _viewer = BaseDataSetViewerDestination.getInstance(
082: destClassName, updateableModel);
083: Runnable run = new Runnable() {
084: public void run() {
085: setViewportView(_viewer.getComponent());
086: }
087: };
088: SwingUtilities.invokeLater(run);
089: }
090:
091: private final static class UIUpdater implements Runnable {
092: /** Logger for this class. */
093: private static final ILogger s_log = LoggerController
094: .createLogger(UIUpdater.class);
095:
096: private final IDataSetViewer _viewer;
097: private final IDataSet _ds;
098:
099: UIUpdater(IDataSetViewer viewer, IDataSet ds) {
100: super ();
101: _viewer = viewer;
102: _ds = ds;
103: }
104:
105: public void run() {
106: try {
107: _viewer.show(_ds);
108: } catch (Throwable th) {
109: s_log.error("Error processing a DataSet", th);
110: }
111: }
112: }
113:
114: /**
115: * Get the viewer being used in this panel.
116: */
117: public IDataSetViewer getViewer() {
118: return _viewer;
119: }
120: }
|