com.zfqjava.swing.model
Class ResultSetTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--com.zfqjava.swing.model.ResultSetTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
RowSetTableModel

public class ResultSetTableModel
extends javax.swing.table.AbstractTableModel

ResultSetTableModel provides a ResultSet table model.

The TableModel methods use the model row index, all other methods use the data row index of the ResultSet, but it is 0 based.
The page index also is 0 based.
All row index must be >= 0, and all first index must be <= last index.

See Also:
Serialized Form

Field Summary
static int CHANGE_CELL
          Identifies the update or insert policy.
static int CHANGE_PAGE
          Identifies the update or insert policy.
static int CHANGE_ROW
          Identifies the update or insert policy.
protected  javax.swing.event.SwingPropertyChangeSupport changeSupport
          If any PropertyChangeListeners have been registered, the changeSupport field describes them.
static int OFF
          Identifies the update or insert policy.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ResultSetTableModel(java.sql.ResultSet rs)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(java.sql.ResultSet rs, boolean sync)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(java.sql.ResultSet rs, boolean sync, int pageSize)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(java.sql.ResultSet rs, int pageSize)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(java.lang.String sql, java.lang.String url, java.lang.String username, java.lang.String password)
          Constructs a ResultSetTableModel with a SQL query command.
ResultSetTableModel(java.lang.String sql, java.lang.String url, java.lang.String username, java.lang.String password, boolean sync)
          Constructs a ResultSetTableModel with a SQL query command.
ResultSetTableModel(java.lang.String sql, java.lang.String url, java.lang.String username, java.lang.String password, boolean sync, int pageSize)
          Constructs a ResultSetTableModel with a SQL query command.
ResultSetTableModel(java.lang.String sql, java.lang.String url, java.lang.String username, java.lang.String password, int pageSize)
          Constructs a ResultSetTableModel with a SQL query command.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 int dataToModelRow(int dataRow)
          Converts the ResultSet row index to the model row index.
 void deleteRow()
          Deletes the data row at the specified current row index.
 void deleteRow(int rowIndex)
          Deletes the data row at the specified row index.
 void deleteRow(int firstRow, int lastRow)
          Deletes the data row from firstRow to lastRow
protected  void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
           
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Supports reporting bound property changes.
 void firstRow()
          Goto the fist row.
 int getAllRowCount()
          Returns all row count.
 java.lang.Class getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 int getFirstRowIndex()
          Returns the first row index in current page.
 int getPageCount()
          Returns the page count.
 int getPageIndex()
          Returns the current page index.
 int getPageSize()
          Returns the page size.
 int getRowCount()
           
 int getRowIndex()
          Returns the current row index.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 void lastRow()
          Goto the last row.
 int modelToDataRow(int modelRow)
          Converts the model row index to the ResultSet row index.
 void nextPage()
          Show the next page.
 void nextRow()
          Goto the next row.
 void previousPage()
          Show the previous page.
 void previousRow()
          Goto the previous row.
 void refreshCell(int rowIndex, int columnIndex)
          Refreshs the cell at the specified row and column index.
 void refreshCell(int firstRow, int lastRow, int firstColumn, int lastColumn)
          Refreshs the cell at the specified row and column index.
 void refreshRow()
          Refreshs the data row at the specified current row index.
 void refreshRow(int rowIndex)
          Refreshs the data row at the specified row index.
 void refreshRow(int firstRow, int lastRow)
          Refreshs the data row from firstRow to lastRow
 void reload()
          Reloads all record from database.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void setAutoInsertPolicy(int insertPolicy)
          Sets the auto insert policy.
 void setAutoUpdatePolicy(int updatePolicy)
          Sets the auto update policy.
 void setPageIndex(int pageIndex)
          Sets the page index.
 void setRowIndex(int rowIndex)
          Sets the row index.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 void updateCell(int rowIndex, int columnIndex)
          Updates the cell at the specified row and column index.
 void updateCell(int firstRow, int lastRow, int firstColumn, int lastColumn)
          Updates the cell at the specified row and column index.
 void updateRow()
          Updates the data row at the specified current row index.
 void updateRow(int rowIndex)
          Updates the data row at the specified row index.
 void updateRow(int firstRow, int lastRow)
          Updates the data row from firstRow to lastRow
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHANGE_CELL

public static final int CHANGE_CELL
Identifies the update or insert policy. Update or insert the row when change the cell value.

CHANGE_ROW

public static final int CHANGE_ROW
Identifies the update or insert policy. Update or insert the row when change the row index.

CHANGE_PAGE

public static final int CHANGE_PAGE
Identifies the update or insert policy. Update or insert the row when change the page index.

OFF

public static final int OFF
Identifies the update or insert policy. The will disable the auto update or insert mode

changeSupport

protected javax.swing.event.SwingPropertyChangeSupport changeSupport
If any PropertyChangeListeners have been registered, the changeSupport field describes them.
Constructor Detail

ResultSetTableModel

public ResultSetTableModel(java.lang.String sql,
                           java.lang.String url,
                           java.lang.String username,
                           java.lang.String password)
Constructs a ResultSetTableModel with a SQL query command.
Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(java.lang.String sql,
                           java.lang.String url,
                           java.lang.String username,
                           java.lang.String password,
                           int pageSize)
Constructs a ResultSetTableModel with a SQL query command.
Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
pageSize - the page size for the record
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(java.lang.String sql,
                           java.lang.String url,
                           java.lang.String username,
                           java.lang.String password,
                           boolean sync)
Constructs a ResultSetTableModel with a SQL query command.
Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
sync - the synchronized flag
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(java.lang.String sql,
                           java.lang.String url,
                           java.lang.String username,
                           java.lang.String password,
                           boolean sync,
                           int pageSize)
Constructs a ResultSetTableModel with a SQL query command.
Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
sync - the synchronized flag
pageSize - the page size for the record
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(java.sql.ResultSet rs)
Constructs a ResultSetTableModel with a rs.
Parameters:
rs - the ResultSet

ResultSetTableModel

public ResultSetTableModel(java.sql.ResultSet rs,
                           boolean sync)
Constructs a ResultSetTableModel with a rs.
Parameters:
rs - the ResultSet
sync - the synchronized flag

ResultSetTableModel

public ResultSetTableModel(java.sql.ResultSet rs,
                           int pageSize)
Constructs a ResultSetTableModel with a rs.
Parameters:
rs - the ResultSet
pageSize - the page size for the record
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(java.sql.ResultSet rs,
                           boolean sync,
                           int pageSize)
Constructs a ResultSetTableModel with a rs.
Parameters:
rs - the ResultSet
sync - the synchronized flag
pageSize - the page size for the record
Since:
JDataGrid 1.3
Method Detail

reload

public void reload()
Reloads all record from database.

getPageSize

public int getPageSize()
Returns the page size.
Returns:
the page size
Since:
JDataGrid 1.3

getPageCount

public int getPageCount()
Returns the page count.
Returns:
the page count
Since:
JDataGrid 1.3

setPageIndex

public void setPageIndex(int pageIndex)
Sets the page index.
Parameters:
pageIndex - the page index
Since:
JDataGrid 1.3
See Also:
getPageIndex()

getPageIndex

public int getPageIndex()
Returns the current page index.
Returns:
the page index
Since:
JDataGrid 1.3
See Also:
setPageIndex(int)

nextPage

public void nextPage()
Show the next page.
Since:
JDataGrid 1.3

previousPage

public void previousPage()
Show the previous page.
Since:
JDataGrid 1.3

setRowIndex

public void setRowIndex(int rowIndex)
Sets the row index.
Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3
See Also:
getRowIndex()

getRowIndex

public int getRowIndex()
Returns the current row index.
Returns:
the row index
Since:
JDataGrid 1.3
See Also:
setRowIndex(int)

getFirstRowIndex

public int getFirstRowIndex()
Returns the first row index in current page.
Returns:
the first row index
Since:
JDataGrid 1.3

getAllRowCount

public int getAllRowCount()
Returns all row count.

Note:This is different with getRowCount when use page mode.

Returns:
all row count in the result set
Since:
JDataGrid 1.3

nextRow

public void nextRow()
Goto the next row.
Since:
JDataGrid 1.3

lastRow

public void lastRow()
Goto the last row.
Since:
JDataGrid 1.3

previousRow

public void previousRow()
Goto the previous row.
Since:
JDataGrid 1.3

firstRow

public void firstRow()
Goto the fist row.
Since:
JDataGrid 1.3

setAutoUpdatePolicy

public void setAutoUpdatePolicy(int updatePolicy)
Sets the auto update policy.
One of 2 legal values:
Parameters:
updatePolicy - the update policy
Since:
JDataGrid 1.3

setAutoInsertPolicy

public void setAutoInsertPolicy(int insertPolicy)
Sets the auto insert policy.
One of 2 legal values:
Parameters:
insertPolicy - the insert policy
Since:
JDataGrid 1.3

updateCell

public void updateCell(int rowIndex,
                       int columnIndex)
Updates the cell at the specified row and column index.
Parameters:
rowIndex - the data row index
columnIndex - the data column index
Since:
JDataGrid 1.3

refreshCell

public void refreshCell(int rowIndex,
                        int columnIndex)
Refreshs the cell at the specified row and column index.
Parameters:
rowIndex - the data row index
columnIndex - the data column index
Since:
JDataGrid 1.3

updateCell

public void updateCell(int firstRow,
                       int lastRow,
                       int firstColumn,
                       int lastColumn)
Updates the cell at the specified row and column index.
Parameters:
firstRow - the first row index of the specified cell area
lastRow - the last row index of the specified cell area
firstColumn - the first column index of the specified cell area
lastColumn - the last column index of the specified cell area
Since:
JDataGrid 1.3

refreshCell

public void refreshCell(int firstRow,
                        int lastRow,
                        int firstColumn,
                        int lastColumn)
Refreshs the cell at the specified row and column index.
Parameters:
firstRow - the first row index of the specified cell area
lastRow - the last row index of the specified cell area
firstColumn - the first column index of the specified cell area
lastColumn - the last column index of the specified cell area
Since:
JDataGrid 1.3

updateRow

public void updateRow()
Updates the data row at the specified current row index.
Since:
JDataGrid 1.3

updateRow

public void updateRow(int rowIndex)
Updates the data row at the specified row index.
Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3

updateRow

public void updateRow(int firstRow,
                      int lastRow)
Updates the data row from firstRow to lastRow
Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.3

deleteRow

public void deleteRow()
Deletes the data row at the specified current row index.
Since:
JDataGrid 1.3

deleteRow

public void deleteRow(int rowIndex)
Deletes the data row at the specified row index.
Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3

deleteRow

public void deleteRow(int firstRow,
                      int lastRow)
Deletes the data row from firstRow to lastRow
Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.3

refreshRow

public void refreshRow()
Refreshs the data row at the specified current row index.
Since:
JDataGrid 1.3

refreshRow

public void refreshRow(int rowIndex)
Refreshs the data row at the specified row index.
Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3

refreshRow

public void refreshRow(int firstRow,
                       int lastRow)
Refreshs the data row from firstRow to lastRow
Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.3

modelToDataRow

public int modelToDataRow(int modelRow)
Converts the model row index to the ResultSet row index.
Parameters:
modelRow - the mode row index
Returns:
the ResultSet row index for the specified model row index
Since:
JDataGrid 1.3

dataToModelRow

public int dataToModelRow(int dataRow)
Converts the ResultSet row index to the model row index.
Parameters:
dataRow - the data row index
Returns:
the model index for the specified ResultSet row index
Since:
JDataGrid 1.3

getRowCount

public int getRowCount()
Overrides:
getRowCount in class javax.swing.table.AbstractTableModel

getColumnCount

public int getColumnCount()
Overrides:
getColumnCount in class javax.swing.table.AbstractTableModel

getColumnName

public java.lang.String getColumnName(int columnIndex)
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Overrides:
getValueAt in class javax.swing.table.AbstractTableModel

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  int oldValue,
                                  int newValue)

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to setting a bound property, e.g. setFont, setBackground, or setForeground. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

Parameters:
listener - The PropertyChangeListener to be added
See Also:
Action#addPropertyChangeListener

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
Parameters:
listener - the PropertyChangeListener to be removed
See Also:
Action#removePropertyChangeListener


Copyright © 2001-2003 Extreme Component, Inc. All rights reserved.