JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.sql
Class ScrollResultSetTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by net.sf.japi.sql.ScrollResultSetTableModel
All Implemented Interfaces:
Serializable, EventListener, RowSetListener, TableModel, ResultSetTableModel

public class ScrollResultSetTableModel
extends AbstractTableModel
implements ResultSetTableModel, RowSetListener

An implementation of javax.swing.TableModel for an SQL ResultSet. It is required that the ResultSet is absolutely navigatable. That feature heavily depends on the JDBC Driver implementation. Please note that though this class does NOT store the ResultSet data except some meta data, the JTable probably will in its own private shadow copy table model.

Author:
Christian Hujer
See Also:
ResultSet, TableModel, Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ScrollResultSetTableModel()
          Create a ResultSetTableModel.
ScrollResultSetTableModel(ResultSet rs)
          Create a ResultSetTableModel.
 
Method Summary
 void addThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
          Adds a ThrowableHandler to this model.
 void cursorMoved(RowSetEvent event)
          Notifies registered listeners that a RowSet object's cursor has moved.
 void deleteRow(int n)
          Delete a row.
 Class<?> getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int column)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 ResultSetMetaData getMetaData()
          Get the meta data.
 ResultSet getResultSet()
          Get the ResultSet.
 int getRowCount()
          Returns the number of rows in the model.
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 void insert(String[] rowData)
          Insert a row.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false.
 void removeThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
          Removes a ThrowableHandler from this model.
 void rowChanged(RowSetEvent event)
          Notifies registered listeners that a RowSet object has had a change in one of its rows.
 void rowSetChanged(RowSetEvent event)
          Notifies registered listeners that a RowSet object in the given RowSetEvent object has changed its entire contents.
 void setResultSet(ResultSet resultSet)
          Set the ResultSet.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          This empty implementation is provided so users don't have to implement this method if their data model is not editable.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

ScrollResultSetTableModel

public ScrollResultSetTableModel()
Create a ResultSetTableModel.


ScrollResultSetTableModel

public ScrollResultSetTableModel(ResultSet rs)
Create a ResultSetTableModel.

Parameters:
rs - Initial ResultSet
Method Detail

setResultSet

public void setResultSet(ResultSet resultSet)
Set the ResultSet.

Specified by:
setResultSet in interface ResultSetTableModel
Parameters:
resultSet - ResultSet, maybe null

getResultSet

public ResultSet getResultSet()
Get the ResultSet.

Specified by:
getResultSet in interface ResultSetTableModel
Returns:
ResultSet or null if there is no current result set

addThrowableHandler

public void addThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
Adds a ThrowableHandler to this model.

Specified by:
addThrowableHandler in interface ResultSetTableModel
Parameters:
throwableHandler - ThrowableHandler to add

removeThrowableHandler

public void removeThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
Removes a ThrowableHandler from this model.

Specified by:
removeThrowableHandler in interface ResultSetTableModel
Parameters:
throwableHandler - ThrowableHandler to add

rowSetChanged

public void rowSetChanged(RowSetEvent event)
Notifies registered listeners that a RowSet object in the given RowSetEvent object has changed its entire contents.

The source of the event can be retrieved with the method event.getSource.

Specified by:
rowSetChanged in interface RowSetListener
Parameters:
event - a RowSetEvent object that contains the RowSet object that is the source of the event

rowChanged

public void rowChanged(RowSetEvent event)
Notifies registered listeners that a RowSet object has had a change in one of its rows.

The source of the event can be retrieved with the method event.getSource.

Specified by:
rowChanged in interface RowSetListener
Parameters:
event - a RowSetEvent object that contains the RowSet object that is the source of the event

cursorMoved

public void cursorMoved(RowSetEvent event)
Notifies registered listeners that a RowSet object's cursor has moved.

The source of the event can be retrieved with the method event.getSource.

Specified by:
cursorMoved in interface RowSetListener
Parameters:
event - a RowSetEvent object that contains the RowSet object that is the source of the event

getRowCount

public int getRowCount()
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface TableModel
Returns:
the number of rows in the model
See Also:
TableModel.getColumnCount()

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

Specified by:
getColumnCount in interface TableModel
Returns:
the number of columns in the model
See Also:
TableModel.getRowCount()

getValueAt

@Nullable
public Object getValueAt(int rowIndex,
                                  int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface TableModel
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Returns Object.class regardless of columnIndex.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - the column being queried
Returns:
the Object.class

getColumnName

@Nullable
public String getColumnName(int column)
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. If column cannot be found, returns an empty string.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - the column being queried
Returns:
a string containing the default name of column

insert

public void insert(String[] rowData)
            throws SQLException
Insert a row. This is a proxy method to the underlying result set.

Parameters:
rowData - data for new row
Throws:
SQLException - in case of SQL problems

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns false. This is the default implementation for all cells.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
false
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
This empty implementation is provided so users don't have to implement this method if their data model is not editable.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
aValue - value to assign to cell
rowIndex - row of cell
columnIndex - column of cell
See Also:
TableModel.getValueAt(int, int), TableModel.isCellEditable(int, int)

deleteRow

public void deleteRow(int n)
               throws SQLException
Delete a row. This is a proxy method to the underlying result set.

Parameters:
n - row number to delete (Java row number, 0 .. (number of rows - 1))
Throws:
SQLException - in case of SQL problems

getMetaData

public ResultSetMetaData getMetaData()
Get the meta data.

Returns:
meta data

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright