001: package net.sourceforge.squirrel_sql.fw.sql;
002:
003: /*
004: * Copyright (C) 2002 David MacLean
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: import java.util.ArrayList;
021: import java.util.Collections;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.StringTokenizer;
025:
026: import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
027: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetDefinition;
028: import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSet;
029: import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
030: import net.sourceforge.squirrel_sql.fw.util.StringManager;
031: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
032:
033: /**
034: * Represents the list of functions and SQL keywords as a one-column data set.
035: */
036: public class MetaDataListDataSet implements IDataSet {
037: /** Internationalized strings for this class. */
038: private static final StringManager s_stringMgr = StringManagerFactory
039: .getStringManager(MetaDataListDataSet.class);
040:
041: private static interface IStrings {
042: String NAME_COLUMN = s_stringMgr
043: .getString("MetaDataListDataSet.propname");
044: }
045:
046: private final static String[] s_hdgs = new String[] { IStrings.NAME_COLUMN };
047: private DataSetDefinition _dsDef;
048: private Iterator<String> _rowIter;
049: private List<String> _row = new ArrayList<String>();
050: private String _rowElem;
051:
052: public MetaDataListDataSet(String functionList) {
053: super ();
054: _dsDef = new DataSetDefinition(createColumnDefinitions());
055: load(functionList);
056: }
057:
058: public int getColumnCount() {
059: return s_hdgs.length;
060: }
061:
062: public DataSetDefinition getDataSetDefinition() {
063: return _dsDef;
064: }
065:
066: public synchronized boolean next(IMessageHandler msgHandler) {
067: if (_rowIter.hasNext()) {
068: _rowElem = _rowIter.next();
069: return true;
070: }
071: return false;
072: }
073:
074: public synchronized Object get(int columnIndex) {
075: if (columnIndex == 0) {
076: return _rowElem;
077: }
078: return null;
079: }
080:
081: private ColumnDisplayDefinition[] createColumnDefinitions() {
082: final int columnCount = getColumnCount();
083: ColumnDisplayDefinition[] columnDefs = new ColumnDisplayDefinition[columnCount];
084: for (int i = 0; i < columnCount; ++i) {
085: columnDefs[i] = new ColumnDisplayDefinition(200, s_hdgs[i]);
086: }
087: return columnDefs;
088: }
089:
090: private void load(String functionList) {
091: if (functionList != null) {
092: StringTokenizer st = new StringTokenizer(functionList, ",");
093: while (st.hasMoreTokens()) {
094: _row.add(st.nextToken());
095: }
096: Collections.sort(_row);
097: }
098: _rowIter = _row.iterator();
099: }
100: }
|