Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.table
Class ListTableMap

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.sciapp.table.ListTableMap
All Implemented Interfaces:
ReorderListener, ListTableModel, ReorderModel, Serializable, EventListener, TableModelListener, TableModel
Direct Known Subclasses:
CachedListTableModel, FilterTableModel, SortTableModel, ThreadedListTableModel, TreeTableModel

public class ListTableMap
extends AbstractTableModel
implements ListTableModel, TableModelListener, ReorderModel, ReorderListener

This class defines a TableModel that wraps around a ListTableModel, which is passed in the constructor. The methods of ListTableModel that are implemented are nothing more than calls to the respective methods of the underlying ListTableModel.

Additionally, events generated from the underlying ListTableModel are intercepted and sent to this object's listeners.

See Also:
Serialized Form

Field Summary
protected  ListTableModel tableModel
          The underlying ListTableModel
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ListTableMap(ListTableModel tableModel)
          Constructs a ListTableMap having tableModel as the underlying ListTableModel
 
Method Summary
 void addReorderListener(ReorderListener l)
          Adds a ReorderListener that is notified each time a change to the data model occurs so that the table updates the selected rows accordingly.
 void addRow(Object row)
          Adds a row to the end of the model.
 void addRows(List addedRows)
          Adds a list of rows to the end of the model.
 void clear()
          Clears the model of any data.
 int convertRowIndexToModel(int viewRowIndex)
          Determines the index of the row in the underlying model in terms of the row index in this map.
 int convertRowIndexToView(int modelRowIndex)
          Determines the index of the row in this map in terms of the row index in the underlying model.
 void fireRowsMapped(int[] changedIndices)
          Notifies listeners that the rows of the table have been reordered according to the changedIndices map.
 void fireRowsReordered(ReorderEvent event)
          Notifies listeners that the rows of the table have been reordered in some way.
 Object getCellValue(Object o, int index)
          Returns tableModel.getCellValue
 Class getColumnClass(int c)
          Returns tableModel.getColumnClass
 int getColumnCount()
          Returns tableModel.getColumnCount
 String getColumnName(int columnIndex)
          Returns tableModel.getColumnName
 ListTableModel getInnerModel()
          In a chain of ListTableMaps, this method returns the inner most tablemodel that is not an instanceof ListTableMap.
 ListTableModel getModel()
          Returns the underlying ListTableModel model
 int getRowCount()
          Returns tableModel.getRowCount
 List getRows()
          Returns tableModel.getRows
 Object getValueAt(int row, int column)
          Returns tableModel.getValueAt
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns tableModel.isCellEditable
 void removeReorderListener(ReorderListener l)
          Removes a listener from the list that is notified each time a reorder event is generated.
 void removeRow(int row)
          Removes a row from the data model
 void removeRows(int[] deletedRows)
          Removes a few rows from the data model
 void rowsReordered(ReorderEvent e)
          Called whenever the rows of a JTable have been restructured.
 void setModel(ListTableModel newModel)
          Sets the underlying ListTableModel to newModel.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Returns tableModel.setValueAt
 void tableChanged(TableModelEvent e)
          This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.
 
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 com.sciapp.table.ListTableModel
fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

tableModel

protected ListTableModel tableModel
The underlying ListTableModel

Constructor Detail

ListTableMap

public ListTableMap(ListTableModel tableModel)
Constructs a ListTableMap having tableModel as the underlying ListTableModel

Method Detail

addReorderListener

public void addReorderListener(ReorderListener l)
Adds a ReorderListener that is notified each time a change to the data model occurs so that the table updates the selected rows accordingly.

Specified by:
addReorderListener in interface ReorderModel
Parameters:
l - the ReorderListener

addRow

public void addRow(Object row)
Adds a row to the end of the model.

Specified by:
addRow in interface ListTableModel
Parameters:
row - the row being added

addRows

public void addRows(List addedRows)
Adds a list of rows to the end of the model.

addedRows contains objects representing the actual rows being added. e.g. java.util.Vector, for DefaultTableModel.

Specified by:
addRows in interface ListTableModel
Parameters:
addedRows - the rows being added.

clear

public void clear()
Clears the model of any data.

Specified by:
clear in interface ListTableModel

fireRowsMapped

public void fireRowsMapped(int[] changedIndices)
Notifies listeners that the rows of the table have been reordered according to the changedIndices map.

Specified by:
fireRowsMapped in interface ReorderModel
Parameters:
changedIndices - int array indicating how the rows have been reordered.
See Also:
ReorderEvent

fireRowsReordered

public void fireRowsReordered(ReorderEvent event)
Notifies listeners that the rows of the table have been reordered in some way.

Specified by:
fireRowsReordered in interface ReorderModel
Parameters:
event - the reorder event.
See Also:
ReorderEvent

getCellValue

public Object getCellValue(Object o,
                           int index)
Returns tableModel.getCellValue

Specified by:
getCellValue in interface ListTableModel
Parameters:
o - the row data
index - an index
Returns:
the object found at column index of the row data row

getColumnClass

public Class getColumnClass(int c)
Returns tableModel.getColumnClass

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

getColumnCount

public int getColumnCount()
Returns tableModel.getColumnCount

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

getColumnName

public String getColumnName(int columnIndex)
Returns tableModel.getColumnName

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

getInnerModel

public ListTableModel getInnerModel()
In a chain of ListTableMaps, this method returns the inner most tablemodel that is not an instanceof ListTableMap.

Returns:
the innermost list tablemodel instance that is not an instance of ListTableMap.

getModel

public ListTableModel getModel()
Returns the underlying ListTableModel model

Returns:
the underlying ListTableModel model

getRowCount

public int getRowCount()
Returns tableModel.getRowCount

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

getRows

public List getRows()
Returns tableModel.getRows

Specified by:
getRows in interface ListTableModel
Returns:
the rows of the datamodel as a java.util.List

getValueAt

public Object getValueAt(int row,
                         int column)
Returns tableModel.getValueAt

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

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns tableModel.isCellEditable

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)

removeReorderListener

public void removeReorderListener(ReorderListener l)
Removes a listener from the list that is notified each time a reorder event is generated.

Specified by:
removeReorderListener in interface ReorderModel
Parameters:
l - the RearrangeListener

removeRow

public void removeRow(int row)
Removes a row from the data model

Specified by:
removeRow in interface ListTableModel
Parameters:
row - the index of the row being removed

removeRows

public void removeRows(int[] deletedRows)
Removes a few rows from the data model

Specified by:
removeRows in interface ListTableModel
Parameters:
deletedRows - an integer array that contains indexes of the rows being deleted

rowsReordered

public void rowsReordered(ReorderEvent e)
Called whenever the rows of a JTable have been restructured.

Specified by:
rowsReordered in interface ReorderListener
Parameters:
e - the ReorderEvent object

setModel

public void setModel(ListTableModel newModel)
Sets the underlying ListTableModel to newModel.

Parameters:
newModel - the new ListTableModel to set

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Returns tableModel.setValueAt

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)

tableChanged

public void tableChanged(TableModelEvent e)
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.

Specified by:
tableChanged in interface TableModelListener

convertRowIndexToModel

public int convertRowIndexToModel(int viewRowIndex)
Determines the index of the row in the underlying model in terms of the row index in this map.

Parameters:
viewRowIndex - the index of the row in this map
Returns:
the index of the corresponding row in the underlying model

convertRowIndexToView

public int convertRowIndexToView(int modelRowIndex)
Determines the index of the row in this map in terms of the row index in the underlying model. If the row is not viewable in the map (such as filtered out), -1 is returned.

Parameters:
modelRowIndex - the index of the row in the underlying model
Returns:
the index of the corresponding row in this map

Copyright © 2005 Scientific Applications. All Rights Reserved.