SalesPoint v3.3 API

util.swing
Class AbstractTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by util.swing.AbstractTableModel
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
CatalogTableModel, CountingStockTableModel, DataBasketTableModel, LogTableModel, StoringStockTableModel, TableMap, UserTableModel

public abstract class AbstractTableModel
extends AbstractTableModel

A TableModel that models a list of records rather than a matrix of cells.

Usage of this TableModel is always recommendable when the data that is to be displayed consists of a list of uniformly structured records and you want to display a selection of attributes for each record. As the data management classes (Catalog, Stock, DataBasket) of the "SalesPoint" framework match this scheme, there are concrete subclasses of this model for each of those classes.

util.swing.AbstractTableModel will give one row in the table to each record of the model. The record that is to be displayed in a certain row is determined by the getRecord(int) method which is abstract and must be overridden in subclasses. Thus, subclasses have the opportunity to define what type (class) of records they use and how they are derived from the actual data source in the background. There's only one more method that subclasses will have to override: TableModel.getRowCount().

A TableEntryDescriptor will be used to determine how individual records are represented in one row of the table model, i.e. how many columns there are and what is displayed in the cells as well as formatting and editing issues.

Since:
v2.0
Author:
Steffen Zschaler
See Also:
JAbstractTable, Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
AbstractTableModel(TableEntryDescriptor ted)
          Create a new AbstractTableModel.
 
Method Summary
 Class<?> getColumnClass(int nIdx)
          Get the class of the given column in this TableModel.
 int getColumnCount()
          Get the number of columns in this TableModel.
 String getColumnName(int nIdx)
          Get the name of the given column in this TableModel.
 TableEntryDescriptor getEntryDescriptor()
          Get the TableEntryDescriptor that is used to split records into columns.
abstract  Object getRecord(int row)
          Get the record associated to the given row.
 Object getValueAt(int row, int col)
          Get the value of the given cell in this TableModel.
 boolean isCellEditable(int row, int col)
          Check whether the given cell is editable in this TableModel.
 void orderByColumn(int nIdx, boolean fAscending)
          Reorders the table by the specified column if that's possible.
protected  void reOrderBy(Comparator cmp)
          Reorder the records displayed according to the specified comparator.
abstract  void setData(Object data)
          Set the table's data.
 void setValueAt(Object oValue, int row, int col)
          Set the value of the given cell in this TableModel.
 
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
getRowCount
 

Constructor Detail

AbstractTableModel

public AbstractTableModel(TableEntryDescriptor ted)
Create a new AbstractTableModel.

Parameters:
ted - the TableEntryDescriptor that is to be used to split records into columns.
Method Detail

setData

public abstract void setData(Object data)
Set the table's data.

Parameters:
data - the new data
Throws:
Exception

getEntryDescriptor

public TableEntryDescriptor getEntryDescriptor()
Get the TableEntryDescriptor that is used to split records into columns.

Override:
Never

getColumnCount

public int getColumnCount()
Get the number of columns in this TableModel.

Returns:
the number of columns in the associated TableEntryDescriptor.
See Also:
TableEntryDescriptor.getColumnCount()
Override:
Never

getColumnName

public String getColumnName(int nIdx)
Get the name of the given column in this TableModel.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
nIdx - the column's index. Columns indices run from 0 to getColumnCount() - 1.
Returns:
the name of the column in the associated TableEntryDescriptor.
See Also:
TableEntryDescriptor.getColumnName(int)
Override:
Never

getColumnClass

public Class<?> getColumnClass(int nIdx)
Get the class of the given column in this TableModel.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
nIdx - the column's index. Columns indices run from 0 to getColumnCount() - 1.
Returns:
the class of the column in the associated TableEntryDescriptor.
See Also:
TableEntryDescriptor.getColumnClass(int)
Override:
Never

getValueAt

public Object getValueAt(int row,
                         int col)
Get the value of the given cell in this TableModel.

First determines the record associated to the row by calling getRecord(int), then calls getValueAt() in the associated TableEntryDescriptor.

Parameters:
row - the row index for which to determine the value. This will be passed on to getRecord(int). Row indices run from 0 to getRowCount() - 1.
col - the column's index. Columns indices run from 0 to getColumnCount() - 1.
Returns:
the value returned by TableEntryDescriptor.getValueAt(java.lang.Object, int).
Override:
Never

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Check whether the given cell is editable in this TableModel.

First determines the record associated to the row by calling getRecord(int), then calls isElementEditable() in the associated TableEntryDescriptor.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - the row index for which to determine editability. This will be passed on to getRecord(int). Row indices run from 0 to getRowCount() - 1.
col - the column's index. Columns indices run from 0 to getColumnCount() - 1.
Returns:
the value returned by TableEntryDescriptor.isElementEditable(java.lang.Object, int).
Override:
Never

setValueAt

public void setValueAt(Object oValue,
                       int row,
                       int col)
Set the value of the given cell in this TableModel.

First determines the record associated to the row by calling getRecord(int), then calls setValueAt() in the associated TableEntryDescriptor.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
oValue - the new value for the cell. This will be passed on to TableEntryDescriptor.setValueAt(java.lang.Object, int, java.lang.Object) as the oValue parameter.
row - the row index for which to set the value. This will be passed on to getRecord(int). Row indices run from 0 to getRowCount() - 1.
col - the column's index. Columns indices run from 0 to getColumnCount() - 1.
Override:
Never

orderByColumn

public void orderByColumn(int nIdx,
                          boolean fAscending)
Reorders the table by the specified column if that's possible.

Parameters:
nIdx - the index of the column by which to sort
fAscending - if false orders the records in descending order
Since:
v3.0 12/14/2000
See Also:
reOrderBy(java.util.Comparator)
Override:
Never

getRecord

public abstract Object getRecord(int row)
Get the record associated to the given row.

Subclasses must indicate the class of the record in their documentation.

Parameters:
row - the row index for which to return the record. Row indices run from 0 to getRowCount() - 1.
Returns:
the record associated to the given row. May return null, instead of throwing an exception, if the given index is without its bounds.
Override:
Always You must override this method to define and incorporate your own type of record. Subclasses should specify what class of record is returned.

reOrderBy

protected void reOrderBy(Comparator cmp)
Reorder the records displayed according to the specified comparator.

Parameters:
cmp - the comparator by which to order.
Since:
v3.0 12/14/2000
Override:
Sometimes Override this method if you want sorting by column for your derived models. The default implementation does nothing. Subclasses should specify what class of record is maintained and whether the comparators must compare whole records or just specific attributes.

SalesPoint v3.3 API