com.nqadmin.swingSet
Class SSTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.nqadmin.swingSet.SSTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class SSTableModel
extends javax.swing.table.AbstractTableModel

SSTableModel.java

SwingSet - Open Toolkit For Making Swing Controls Database-Aware

 SSTableModel provides an implementation of the TableModel interface.
 The SSDataGrid uses this class for providing a grid view for a SSRowSet.
 SSTableModel can be used without the SSDataGrid (e.g. in conjunction with a
 JTable), but the cell renderers and hidden columns features of the SSDataGrid
 will not be available.

 SSTableModel can be used with a JTable to get a Grid view of the data.

Version:
$Revision: 1.20 $
See Also:
Serialized Form

Constructor Summary
SSTableModel()
          Constructs a SSTableModel object.
SSTableModel(SSRowSet _rowset)
          Constructs a SSTableModel object with the given SSRowSet.
 
Method Summary
 boolean deleteRow(int _row)
          Deletes the specified row from the database.
 java.lang.Class getColumnClass(int _column)
          Returns the type for the column specified for the current view.
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int _columnNumber)
          Returns the name of the column appearing in the view at column position column.
 java.lang.Object getDefaultValue(int _columnNumber)
          Returns the default value inforce for the requested column.
 int getRowCount()
          Returns the number of rows in the model.
 java.lang.Object getValueAt(int _row, int _column)
          Returns the value for the cell at the specified row & column.
 boolean isCellEditable(int _row, int _column)
          Returns true if the cell at rowIndex and columnIndex is editable.
 void setDefaultValues(int[] _columnNumbers, java.lang.Object[] _values)
          Sets the default values for different columns.
 void setHeaders(java.lang.String[] _headers)
          Sets the headers for the JTable.
 void setHiddenColumns(int[] _columnNumbers)
          Sets the column numbers that should be hidden.
 void setInsertion(boolean _insert)
          Sets row insertion indicator.
 void setJTable(javax.swing.JTable _table)
          This sets the JTable to which the table model is bound to.
 void setMessageWindow(java.awt.Component _component)
          Sets the message window.
 void setPrimaryColumn(int _columnNumber)
          Sets the column number which is the primary column for the table.
 void setRowSet(SSRowSet _rowset)
          Deprecated.  
 void setSSCellEditing(SSCellEditing _cellEditing)
          Used to set an implementation of SSCellEditing interface which can be used to determine dynamically if a given cell can be edited and to determine if a given value is valid.
 void setSSDataValue(SSDataValue _dataValue)
          Sets the SSDataValue interface implemention.
 void setSSRowSet(SSRowSet _rowset)
          Sets the SSRowSet for SSTableModel to the given SSRowSet.
 void setUneditableColumns(int[] _columnNumbers)
          Sets the uneditable columns.
 void setValueAt(java.lang.Object _value, int _row, int _column)
          Sets the value in the cell at _row and _column to _value.
 
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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSTableModel

public SSTableModel()
Constructs a SSTableModel object. If this contructor is used the setSSRowSet() method has to be used to set the SSRowSet before constructing the JTable.


SSTableModel

public SSTableModel(SSRowSet _rowset)
             throws java.sql.SQLException
Constructs a SSTableModel object with the given SSRowSet. This will call the execute method on the given SSRowSet.

Parameters:
_rowset - SSRowSet object whose records has to be displayed in JTable.
Throws:
java.sql.SQLException
Method Detail

setSSRowSet

public void setSSRowSet(SSRowSet _rowset)
                 throws java.sql.SQLException
Sets the SSRowSet for SSTableModel to the given SSRowSet. This SSRowSet will be used to get the data for JTable.

Parameters:
_rowset - SSRowSet object whose records has to be displayed in JTable.
Throws:
java.sql.SQLException

setSSCellEditing

public void setSSCellEditing(SSCellEditing _cellEditing)
Used to set an implementation of SSCellEditing interface which can be used to determine dynamically if a given cell can be edited and to determine if a given value is valid.

Parameters:
_cellEditing - implementation of SSCellEditing interface.

setInsertion

public void setInsertion(boolean _insert)
Sets row insertion indicator.

Parameters:
_insert - true if user can insert new rows, else false.

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.

Returns:
the number of columns in the SSTableModel

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.

Returns:
the number of rows in the SSTableModel

isCellEditable

public boolean isCellEditable(int _row,
                              int _column)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, a call to setValueAt() on the cell will not change the value of that cell.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
_row - the row whose value to be queried
_column - the column whose value to be queried
Returns:
editable indicator for cell at row and column specified

getValueAt

public java.lang.Object getValueAt(int _row,
                                   int _column)
Returns the value for the cell at the specified row & column.

Parameters:
_row - the row whose value to be queried.
_column - the column whose value to be queried.
Returns:
value at the requested cell.

setValueAt

public void setValueAt(java.lang.Object _value,
                       int _row,
                       int _column)
Sets the value in the cell at _row and _column to _value.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
_value - the new value
_row - the row whose value is to be changed
_column - the column whose value is to be changed

getColumnClass

public java.lang.Class getColumnClass(int _column)
Returns the type for the column specified for the current view.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
_column - the column in the view being queried
Returns:
type for the specified column (first column is 0)

deleteRow

public boolean deleteRow(int _row)
Deletes the specified row from the database. The rows are numbered as: 0, 1, ..., n-1

Parameters:
_row - the row number that has to be deleted.
Returns:
returns true on succesful deletion else false.

setDefaultValues

public void setDefaultValues(int[] _columnNumbers,
                             java.lang.Object[] _values)
Sets the default values for different columns. These values will be used while inserting a new row.

Parameters:
_columnNumbers - the column numbers for which defaults are required
_values - the values for all the columns specified in first argument

getDefaultValue

public java.lang.Object getDefaultValue(int _columnNumber)
Returns the default value inforce for the requested column. The type of object is same as returned by getColumnClass in JTable.

Parameters:
_columnNumber - the column number for which default value is needed.
Returns:
returns a object representing the default value.

setMessageWindow

public void setMessageWindow(java.awt.Component _component)
Sets the message window. This is used as parent component for pop up message dialogs.

Parameters:
_component - the component that should be used for message dialogs.

setJTable

public void setJTable(javax.swing.JTable _table)
This sets the JTable to which the table model is bound to. When an insert row has taken place TableModel tries to update the UI.

Parameters:
_table - JTable to which SSTableModel is bound to.

setPrimaryColumn

public void setPrimaryColumn(int _columnNumber)
Sets the column number which is the primary column for the table. This is required if new rows have to be added to the JTable. For this to properly work the SSDataValue object should also be provided SSDataValue is used to get the value for the primary column.

Parameters:
_columnNumber - the column which is the primary column.

setSSDataValue

public void setSSDataValue(SSDataValue _dataValue)
Sets the SSDataValue interface implemention. This interface specifies function to retrieve primary column values for a new row to be added.

Parameters:
_dataValue - implementation of SSDataValue for determining PK

setHeaders

public void setHeaders(java.lang.String[] _headers)
Sets the headers for the JTable. This function has to be called before setting the SSRowSet for SSDataGrid.

Parameters:
_headers - array of string objects representing the header for each column.

getColumnName

public java.lang.String getColumnName(int _columnNumber)
Returns the name of the column appearing in the view at column position column.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
_columnNumber - the column in the view being queried
Returns:
the name of the column at the position specified for the current vew where column numbering begins at 0

setUneditableColumns

public void setUneditableColumns(int[] _columnNumbers)
Sets the uneditable columns. The columns specified as uneditable will not be available for user to edit. This overrides the isCellEditable function in SSCellEditing.

Parameters:
_columnNumbers - array specifying the column numbers which should be uneditable.

setHiddenColumns

public void setHiddenColumns(int[] _columnNumbers)
Sets the column numbers that should be hidden. The SSDataGrid sets the column width of these columns to 0. The columns are set to zero width rather than removing the column from the table. Thus preserving the column numbering. If a column is removed then the column numbers for columns after the removed column will change. Even if the column is specified as hidden user will be seeing a tiny strip. Make sure that you specify the hidden column numbers in the uneditable column list.

Parameters:
_columnNumbers - array specifying the column numbers which should be hidden.

setRowSet

public void setRowSet(SSRowSet _rowset)
               throws java.sql.SQLException
Deprecated. 

Sets the SSRowSet for SSTableModel to the given SSRowSet. This SSRowSet will be used to get the data for JTable.

Parameters:
_rowset - SSRowSet object whose records has to be displayed in JTable.
Throws:
java.sql.SQLException
See Also:
setSSRowSet(com.nqadmin.swingSet.datasources.SSRowSet)