001: package net.sourceforge.squirrel_sql.fw.sql;
002:
003: /*
004: * Copyright (C) 2001-2004 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.ColumnDisplayDefinition;
022: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetDefinition;
023: import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSet;
024: import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
025: import net.sourceforge.squirrel_sql.fw.util.StringManager;
026: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
027:
028: /**
029: * This implementation of <TT>IDataSet</TT> is used to display
030: * a <TT>ITableInfo</TT> object.
031: *
032: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
033: */
034: public class TableInfoDataSet implements IDataSet {
035: /** Internationalized strings for this class. */
036: private static final StringManager s_stringMgr = StringManagerFactory
037: .getStringManager(TableInfoDataSet.class);
038:
039: private final static String[] s_hdgs = new String[] {
040: s_stringMgr.getString("TableInfoDataSet.property"),
041: s_stringMgr.getString("TableInfoDataSet.value"), };
042:
043: private DataSetDefinition _dsDef;
044:
045: private int _curRow = -1;
046:
047: private String[][] _data = new String[][] {
048: {
049: s_stringMgr
050: .getString("TableInfoDataSet.rowheading.name"),
051: null },
052: {
053: s_stringMgr
054: .getString("TableInfoDataSet.rowheading.qualname"),
055: null },
056: {
057: s_stringMgr
058: .getString("TableInfoDataSet.rowheading.catalog"),
059: null },
060: {
061: s_stringMgr
062: .getString("TableInfoDataSet.rowheading.schema"),
063: null },
064: {
065: s_stringMgr
066: .getString("TableInfoDataSet.rowheading.type"),
067: null },
068: {
069: s_stringMgr
070: .getString("TableInfoDataSet.rowheading.remarks"),
071: null }, };
072:
073: /**
074: * Default ctor.
075: */
076: public TableInfoDataSet() {
077: this (null);
078: }
079:
080: /**
081: * Ctor specifying the <TT>ITableInfo</TT> to be displayed.
082: *
083: * @param ti The <TT>ITableInfo</TT> to be displayed.
084: */
085: public TableInfoDataSet(ITableInfo ti) {
086: super ();
087: _dsDef = new DataSetDefinition(createColumnDefinitions());
088: setTableInfo(ti);
089: }
090:
091: public final int getColumnCount() {
092: return s_hdgs.length;
093: }
094:
095: public DataSetDefinition getDataSetDefinition() {
096: return _dsDef;
097: }
098:
099: public synchronized void setTableInfo(ITableInfo ti) {
100: if (ti != null) {
101: load(ti);
102: } else {
103: for (int i = 0; i < _data.length; ++i) {
104: _data[i][1] = "";
105: }
106: }
107: }
108:
109: public synchronized boolean next(IMessageHandler msgHandler) {
110: if (_curRow >= _data.length - 1) {
111: return false;
112: }
113: ++_curRow;
114: return true;
115: }
116:
117: public synchronized Object get(int columnIndex) {
118: return _data[_curRow][columnIndex];
119: }
120:
121: private ColumnDisplayDefinition[] createColumnDefinitions() {
122: final int columnCount = getColumnCount();
123: ColumnDisplayDefinition[] columnDefs = new ColumnDisplayDefinition[columnCount];
124: for (int i = 0; i < columnCount; ++i) {
125: columnDefs[i] = new ColumnDisplayDefinition(100, s_hdgs[i]);
126: }
127: return columnDefs;
128: }
129:
130: private void load(ITableInfo ti) {
131: _data[0][1] = ti.getSimpleName();
132: _data[1][1] = ti.getQualifiedName();
133: _data[2][1] = ti.getCatalogName();
134: _data[3][1] = ti.getSchemaName();
135: _data[4][1] = ti.getType();
136: _data[5][1] = ti.getRemarks();
137:
138: _curRow = -1;
139: }
140: }
|