Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.treetable
Class TreeTableModelAdapter

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.sciapp.treetable.TreeTableModelAdapter
All Implemented Interfaces:
TreeTableModelAdapterIF, Serializable, TableModel

public class TreeTableModelAdapter
extends AbstractTableModel
implements TreeTableModelAdapterIF

TreeTableModelAdapter sits between a TreeTable and a TreeTableModel. Methods inherited from the TableModel interface are passed to the inner treetable model.

See Also:
Serialized Form

Field Summary
protected  boolean delayed
          flag that controls whether the adapter will fire table change events immediatelly or add them to the swing event queue for later processing.
protected  JTree tree
          the tree
protected  TreeTableModel treeTableModel
          the treetable model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.sciapp.treetable.TreeTableModelAdapterIF
TREE_PROPERTY, TREE_TABLE_MODEL_PROPERTY
 
Constructor Summary
TreeTableModelAdapter()
          Constructs a TreeTableModelAdapter.
TreeTableModelAdapter(TreeTableModel treeTableModel)
          Constructs a TreeTableModelAdapter.
TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree)
          Constructs a TreeTableModelAdapter.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list to be notified when the TreeTableModel or the JTree changes.
 void collapseAll()
          Convenience method to collapse all rows.
protected  JTree createDefaultTree()
          Returns a new instance of the JTree that will be associated with this TreeTableModelAdapter.
protected  TreeTableModel createDefaultTreeTableModel()
          Creates and returns a new instance of the treetable model associated with this TreeTableModelAdapter.
 void expandAll()
          Convenience method to expand all rows.
 void fireTableChanged(TableModelEvent e)
          Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
 Class getColumnClass(int column)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int column)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 boolean getDelayed()
          Returns true if events received from the treemodel are to be added to the swing event queue.
protected  int getPreviousRowCount()
          Called from subclasses during events to find what was the row count before the event.
 int getRowCount()
          Returns the number of rows in the model.
 JTree getTree()
          Returns the associated tree.
 TreeTableModel getTreeTableModel()
          Returns the associated treetable model.
 Object getValueAt(int row, int column)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isAggregate(int rowIndex)
          Determines if the row at rowIndex is an aggregate row.
 boolean isCellEditable(int row, int column)
          Returns false.
 boolean isFooter(int rowIndex)
          Determines if the row at rowIndex is a footer.
 boolean isHeader(int rowIndex)
          Determines if the row at rowIndex is a header.
protected  void nodeCollapsed(TreePath path)
          Notification that the specified path was collapsed.
protected  void nodeExpanded(TreePath path)
          Notification that the specified path was expanded.
 Object nodeForRow(int rowIndex)
          Returns the node at row rowIndex.
protected  void nodesChanged(TreeModelEvent e)
          Notification that children nodes at the specified path have changed.
protected  void nodesInserted(TreeModelEvent e)
          Notification that children nodes at the specified path have been added.
protected  void nodesRemoved(TreeModelEvent e)
          Notification that children nodes at the specified path have been removed.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list that is notified when the TreeTableColumnModel or the JTree changes.
 void setDelayed(boolean delayed)
          Sets the delay property, which if true, events received from the treemodel are to be added to the swing event queue.
 void setTree(JTree newTree)
          Sets a new tree.
 void setTreeTableModel(TreeTableModel newTreeModel)
          Sets a new treetable model.
 void setValueAt(Object value, int row, int column)
          This empty implementation is provided so users don't have to implement this method if their data model is not editable.
protected  void structureChanged(TreeModelEvent e)
          Notification that the structure of the nodes at the specified path has changed.
 
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 javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

tree

protected JTree tree
the tree


treeTableModel

protected TreeTableModel treeTableModel
the treetable model


delayed

protected boolean delayed
flag that controls whether the adapter will fire table change events immediatelly or add them to the swing event queue for later processing.

Constructor Detail

TreeTableModelAdapter

public TreeTableModelAdapter()
Constructs a TreeTableModelAdapter.


TreeTableModelAdapter

public TreeTableModelAdapter(TreeTableModel treeTableModel)
Constructs a TreeTableModelAdapter.


TreeTableModelAdapter

public TreeTableModelAdapter(TreeTableModel treeTableModel,
                             JTree tree)
Constructs a TreeTableModelAdapter.

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list to be notified when the TreeTableModel or the JTree changes. The listener should check for TREE_TABLE_MODEL_PROPERTY and TREE_PROPERTY property events respectively.

Specified by:
addPropertyChangeListener in interface TreeTableModelAdapterIF
Parameters:
listener - the listener to add.

collapseAll

public void collapseAll()
Convenience method to collapse all rows.


createDefaultTree

protected JTree createDefaultTree()
Returns a new instance of the JTree that will be associated with this TreeTableModelAdapter.

Returns:
a new JTree instance

createDefaultTreeTableModel

protected TreeTableModel createDefaultTreeTableModel()
Creates and returns a new instance of the treetable model associated with this TreeTableModelAdapter.

By default, this method returns a DefaultMutableTreeTableModel.


expandAll

public void expandAll()
Convenience method to expand all rows.


fireTableChanged

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

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

getColumnClass

public Class getColumnClass(int column)
Returns Object.class regardless of columnIndex.

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

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.

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

getColumnName

public String getColumnName(int column)
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. If column cannot be found, returns an empty string.

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

getDelayed

public boolean getDelayed()
Returns true if events received from the treemodel are to be added to the swing event queue.

Returns:
true if events received from the treemodel are to be added to the swing event queue.

getPreviousRowCount

protected int getPreviousRowCount()
Called from subclasses during events to find what was the row count before the event.

Returns:
the previous row count

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. This method should be quick, as it is called frequently during rendering.

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

getTree

public JTree getTree()
Returns the associated tree.

Specified by:
getTree in interface TreeTableModelAdapterIF
Returns:
the tree.

getTreeTableModel

public TreeTableModel getTreeTableModel()
Returns the associated treetable model.

Specified by:
getTreeTableModel in interface TreeTableModelAdapterIF
Returns:
the treetable model.

getValueAt

public Object getValueAt(int row,
                         int column)
Returns the value for the cell at columnIndex and rowIndex.

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

isAggregate

public boolean isAggregate(int rowIndex)
Determines if the row at rowIndex is an aggregate row.

Parameters:
rowIndex - the row to query
Returns:
true if the row is an aggregate row, false otherwise

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns false. This is the default implementation for all cells.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - the row being queried
column - the column being queried
Returns:
false
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

isFooter

public boolean isFooter(int rowIndex)
Determines if the row at rowIndex is a footer.

Parameters:
rowIndex - the row to query
Returns:
true if the row is a footer, false otherwise

isHeader

public boolean isHeader(int rowIndex)
Determines if the row at rowIndex is a header.

Parameters:
rowIndex - the row to query
Returns:
true if the row is a header, false otherwise

nodeCollapsed

protected void nodeCollapsed(TreePath path)
Notification that the specified path was collapsed.

Parameters:
path - the path that was collapsed

nodeExpanded

protected void nodeExpanded(TreePath path)
Notification that the specified path was expanded.

Parameters:
path - the path that was expanded

nodeForRow

public Object nodeForRow(int rowIndex)
Returns the node at row rowIndex.

Parameters:
rowIndex - the index of the row
Returns:
the node at rowIndex

nodesChanged

protected void nodesChanged(TreeModelEvent e)
Notification that children nodes at the specified path have changed.

Parameters:
e - the event identifying the change

nodesInserted

protected void nodesInserted(TreeModelEvent e)
Notification that children nodes at the specified path have been added.

Parameters:
e - the event identifying the insertion

nodesRemoved

protected void nodesRemoved(TreeModelEvent e)
Notification that children nodes at the specified path have been removed.

Parameters:
e - the event identifying the removal

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list that is notified when the TreeTableColumnModel or the JTree changes. The listener should check for TREE_TABLE_COLUMN_MODEL_PROPERTY and TREE_PROPERTY property events respectively.

Specified by:
removePropertyChangeListener in interface TreeTableModelAdapterIF
Parameters:
listener - the listener to remove.

setDelayed

public void setDelayed(boolean delayed)
Sets the delay property, which if true, events received from the treemodel are to be added to the swing event queue.

Parameters:
delayed - set to true if events received from the treemodel are to be added to the swing event queue.

setTree

public void setTree(JTree newTree)
Sets a new tree. A property change event is fired with the TREE_PROPERTY.

Parameters:
newTree - the new tree to assign.

setTreeTableModel

public void setTreeTableModel(TreeTableModel newTreeModel)
Sets a new treetable model. A property change event is fired with the TREE_TABLE_MODEL_PROPERTY.

Parameters:
newTreeModel - the new treetable model to assign.

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
This empty implementation is provided so users don't have to implement this method if their data model is not editable.

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

structureChanged

protected void structureChanged(TreeModelEvent e)
Notification that the structure of the nodes at the specified path has changed.

Parameters:
e - the event identifying the structure change

Copyright © 2005 Scientific Applications. All Rights Reserved.