Package adams.gui.core
Class ResultSetTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- adams.gui.core.AbstractBaseTableModel
-
- adams.gui.core.ResultSetTableModel
-
- All Implemented Interfaces:
LoggingLevelHandler
,LoggingSupporter
,SpreadSheetSupporter
,Serializable
,TableModel
public class ResultSetTableModel extends AbstractBaseTableModel
Table model for displaying an SQL ResultSet.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
ResultSet
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<String,Integer>
m_ColumnIndex
for fast access to the column names (name - index).protected String[]
m_Columns
the column titles.protected List<Object[]>
m_Data
-
Fields inherited from class adams.gui.core.AbstractBaseTableModel
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description ResultSetTableModel(String[] columns)
Initializes an empty model.ResultSetTableModel(ResultSet rs)
Initializes the model with the given result set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getColumnCount()
Returns the number of columns in the model.int
getColumnIndex(String columnName)
Returns the column index associated with the column name.String
getColumnName(int columnIndex)
Returns the name of the column atcolumnIndex
.int
getRowCount()
Returns the number of rows in the model.Object
getValueAt(int rowIndex, int columnIndex)
Returns the value for the cell atcolumnIndex
androwIndex
.Object
getValueAt(int rowIndex, String columnName)
Returns the value for the cell rowrowIndex
and from the column namedcolumnName
.protected void
initialize()
Initializes the members.-
Methods inherited from class adams.gui.core.AbstractBaseTableModel
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, setLoggingLevel, toSpreadSheet, toString
-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
-
-
-
-
Constructor Detail
-
ResultSetTableModel
public ResultSetTableModel(String[] columns)
Initializes an empty model.- Parameters:
columns
- the column titles
-
ResultSetTableModel
public ResultSetTableModel(ResultSet rs) throws SQLException
Initializes the model with the given result set.- Parameters:
rs
- the data to use- Throws:
SQLException
- in case of an SQL error
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.
-
getRowCount
public int getRowCount()
Returns the number of rows in the model.- Returns:
- the number of rows in the model
-
getColumnName
public String getColumnName(int columnIndex)
Returns the name of the column atcolumnIndex
. This is used to initialize the table's column header name.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
columnIndex
- the index of the column- Returns:
- the name of the column
-
getColumnCount
public int getColumnCount()
Returns the number of columns in the model.- Returns:
- the number of columns in the model
-
getValueAt
public Object getValueAt(int rowIndex, int columnIndex)
Returns the value for the cell atcolumnIndex
androwIndex
.- Parameters:
rowIndex
- the row whose value is to be queriedcolumnIndex
- the column whose value is to be queried- Returns:
- the value Object at the specified cell
-
getColumnIndex
public int getColumnIndex(String columnName)
Returns the column index associated with the column name.- Parameters:
columnName
- the name to look up- Returns:
- the index, -1 if not found
-
getValueAt
public Object getValueAt(int rowIndex, String columnName)
Returns the value for the cell rowrowIndex
and from the column namedcolumnName
.- Parameters:
rowIndex
- the row whose value is to be queriedcolumnName
- the name of the column whose value is to be queried- Returns:
- the value Object at the specified cell, null if not found or no value available
-
-