com.sciapp.tree
Class TreeTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.sciapp.table.ListTableMap
          extended by com.sciapp.tree.TreeTableModel
All Implemented Interfaces:
ReorderListener, ListTableModel, ReorderModel, Serializable, EventListener, TableModelListener, TableModel

public class TreeTableModel
extends ListTableMap

TreeTableModel is the tablemodel that the TreeTable class uses. TreeTableModel wraps around a ListTableModel instance in order to provide a tree-like view of the table's data. Rows are grouped together if they are found to be equal by this class's row comparator. The default row comparator is a TreeTableModel.RowComparator, which compares rows by using a single column. However, more complex schemes can be employed, such as comparing using more than one columns. The current row comparator can be assigned with setRowComparator.


Nested Class Summary
 class TreeTableModel.RowComparator
          RowComparator compares row data based on a single column.
 
Field Summary
 
Fields inherited from class com.sciapp.table.ListTableMap
tableModel
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TreeTableModel(ListTableModel tableModel)
          Constructs a TreeTableModel with tableModel as the underlying tablemodel holding the data.
 
Method Summary
protected  Comparator createDefaultRowComparator()
          Creates the default row comparator that will be used to determine row similarity.
 void fireTableChanged(TableModelEvent e)
          Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
 Comparator getRowComparator()
          Returns the Comparator instance that will be used to determine row similarity.
 int getRowCount()
          Returns tableModel.getRowCount
 Object getValueAt(int rowIndex, int columnIndex)
          Returns tableModel.getValueAt
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false if the row at rowIndex is a grouping row, otherwise returns the value of its super method.
 void removeRow(int row)
          Removes a row from the data model
 void removeRows(int[] rows)
          Removes a few rows from the data model
 void rowsReordered(ReorderEvent e)
          Does nothing.
 void setRowComparator(Comparator rowComparator)
          Sets the row comparator that will be used to determine row similarity.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Assigns aValue to the object at columnIndex and rowIndex.
 
Methods inherited from class com.sciapp.table.ListTableMap
addReorderListener, addRow, addRows, clear, fireRowsReordered, getCellValue, getColumnClass, getColumnCount, getColumnName, getModel, getRows, removeReorderListener, setModel, tableChanged
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, 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, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

TreeTableModel

public TreeTableModel(ListTableModel tableModel)
Constructs a TreeTableModel with tableModel as the underlying tablemodel holding the data.

Method Detail

createDefaultRowComparator

protected Comparator createDefaultRowComparator()
Creates the default row comparator that will be used to determine row similarity. This method returns an instance of TreeTableModel.RowComparator that uses the first column of the table for the equality check.


fireTableChanged

public void fireTableChanged(TableModelEvent e)
Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.

Specified by:
fireTableChanged in interface ListTableModel
Overrides:
fireTableChanged in class AbstractTableModel
Parameters:
e - the event to be forwarded
See Also:
AbstractTableModel.addTableModelListener(javax.swing.event.TableModelListener), TableModelEvent, EventListenerList

getRowComparator

public Comparator getRowComparator()
Returns the Comparator instance that will be used to determine row similarity.

Returns:
the current row comparator instance

getRowCount

public int getRowCount()
Returns tableModel.getRowCount

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

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Returns tableModel.getValueAt

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class ListTableMap
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

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns false if the row at rowIndex is a grouping row, otherwise returns the value of its super method.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class ListTableMap
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
true if the cell is editable, false otherwise
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

removeRow

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

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

removeRows

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

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

rowsReordered

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

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

setRowComparator

public void setRowComparator(Comparator rowComparator)
Sets the row comparator that will be used to determine row similarity.

Parameters:
rowComparator - the row comparator that we want to use

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Assigns aValue to the object at columnIndex and rowIndex.

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