kiwi.ui.model
Class TreeModelTableAdapter

java.lang.Object
  |
  +--kiwi.ui.model.TreeModelTableAdapter

public class TreeModelTableAdapter
extends Object
implements TableModel, TreeModelListener

An adapter that allows a Swing JTable to be used with the StaticTreeModel and DynamicTreeModel data models. The adapter translates messages and events between the JTable and the ITreeModel implementation.

Version:
1.0 (11/98)
Author:
Mark Lindner, PING Software Group
See Also:
JTable, ITreeModel

Inner Class Summary
 class TreeModelTableAdapter.TableEntry
          Internal class for managing table items.
 
Constructor Summary
TreeModelTableAdapter(JTable jtable)
          Construct a new tree model table adapter.
 
Method Summary
 void addTableModelListener(TableModelListener listener)
          Add a table model listener.
 void dispose()
          Dispose of the adapter.
protected  void fireIntervalAdded(int first, int last)
          Fire an interval added event.
protected  void fireIntervalRemoved(int first, int last)
          Fire an interval removed event.
 Class getColumnClass(int col)
          Get the class type for the given column.
 int getColumnCount()
          Get the column count for this model.
 String getColumnName(int col)
          Get the name of a given column.
 int getRowCount()
          Get the row count for this table model.
 int getRowForNode(ITreeNode node)
          Get the table row number for a given node.
 ITreeModel getTreeModel()
          Get the tree model in use by this adapter.
 Object getValueAt(int row, int col)
          Get the value at the given row and column in the table model.
 boolean isCellEditable(int row, int col)
          Determine if a given cell is editable.
 void nodeAdded(TreeModelEvent evt)
          Invoked after a node has been added to the model.
 void nodeChanged(TreeModelEvent evt)
          Invoked after a node in the model has changed in some way.
 void nodeCollapsed(TreeModelEvent evt)
          Invoked after a node in the model has been collapsed.
 void nodeCollapsing(TreeModelEvent evt)
          Invoked when a node in the model is about to be collapsed.
 void nodeExpanded(TreeModelEvent evt)
          Invoked after a node in the model has been expanded.
 void nodeExpanding(TreeModelEvent evt)
          Invoked when a node in the model is about to be expanded.
 void nodeRemoved(TreeModelEvent evt)
          Invoked after a node has been removed from the model.
 void nodeStructureChanged(TreeModelEvent evt)
          Invoked after the subtree rooted at a node has changed its structure in some significant way.
 void removeTableModelListener(TableModelListener listener)
          Remove a table model listener.
 void setTreeModel(ITreeModel model)
          Set the tree model to be used by this adapter.
 void setValueAt(Object obj, int row, int col)
          Set the value at the given row and column in the table model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeModelTableAdapter

public TreeModelTableAdapter(JTable jtable)
Construct a new tree model table adapter. Creates a new adapter for the specified JFC table component.
Parameters:
jtable - The JFC table component to be associated with this adapter.
Method Detail

setTreeModel

public void setTreeModel(ITreeModel model)
Set the tree model to be used by this adapter. The adapter adds itself as a listener of the tree model. If a model was already set prior to this call, it is replaced, and the adapter removes itself as a listener from that model.
Parameters:
model - The model to set.
See Also:
getTreeModel()

getTreeModel

public ITreeModel getTreeModel()
Get the tree model in use by this adapter. Returns the tree model currently associated with this adapter (may be null if no model has been set).
See Also:
setTreeModel(kiwi.ui.model.ITreeModel)

addTableModelListener

public void addTableModelListener(TableModelListener listener)
Add a table model listener. Adds a TableModelListener to this adapter's list of table model listeners.
Specified by:
addTableModelListener in interface TableModel
Parameters:
listener - The listener to add.
See Also:
removeTableModelListener(javax.swing.event.TableModelListener)

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Remove a table model listener. Removes a TableModelListener from this adapter's list of table model listeners.
Specified by:
removeTableModelListener in interface TableModel
Parameters:
listener - The listener to remove.
See Also:
addTableModelListener(javax.swing.event.TableModelListener)

getColumnCount

public int getColumnCount()
Get the column count for this model. (Implementation of TableModel.)
Specified by:
getColumnCount in interface TableModel

setValueAt

public void setValueAt(Object obj,
                       int row,
                       int col)
Set the value at the given row and column in the table model. (Implementation of TableModel.) In this implementation, this method does nothing, since TreeTables are currently not editable.
Specified by:
setValueAt in interface TableModel

getValueAt

public Object getValueAt(int row,
                         int col)
Get the value at the given row and column in the table model. (Implementation of TableModel.)
Specified by:
getValueAt in interface TableModel
Parameters:
row - The row.
col - The column.

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Determine if a given cell is editable. In this implementation, the method always returns false because TreeTables are currently not editable.
Specified by:
isCellEditable in interface TableModel

getRowCount

public int getRowCount()
Get the row count for this table model. (Implementation of TableModel.)
Specified by:
getRowCount in interface TableModel

getColumnClass

public Class getColumnClass(int col)
Get the class type for the given column. In this implementation, this method always returns Object.class. This may change in a future implementation to reflect the actual data type.
Specified by:
getColumnClass in interface TableModel

getColumnName

public String getColumnName(int col)
Get the name of a given column. (Implementation of TableModel.)
Specified by:
getColumnName in interface TableModel
Parameters:
col - The index of the column.
Returns:
The name of the column.

fireIntervalAdded

protected void fireIntervalAdded(int first,
                                 int last)
Fire an interval added event. Notifies the TreeTable to insert new rows when a given node is expanded.
Parameters:
first - The index of the first row added.
last - The index of the last row added.

fireIntervalRemoved

protected void fireIntervalRemoved(int first,
                                   int last)
Fire an interval removed event. Notifies the TreeTable to remove rows when a given node is collapsed.
Parameters:
first - The index of the first row removed.
last - The index of the last row removed.

nodeExpanding

public void nodeExpanding(TreeModelEvent evt)
Invoked when a node in the model is about to be expanded.
Specified by:
nodeExpanding in interface TreeModelListener

nodeExpanded

public void nodeExpanded(TreeModelEvent evt)
Invoked after a node in the model has been expanded.
Specified by:
nodeExpanded in interface TreeModelListener

nodeCollapsing

public void nodeCollapsing(TreeModelEvent evt)
Invoked when a node in the model is about to be collapsed.
Specified by:
nodeCollapsing in interface TreeModelListener

nodeCollapsed

public void nodeCollapsed(TreeModelEvent evt)
Invoked after a node in the model has been collapsed.
Specified by:
nodeCollapsed in interface TreeModelListener

nodeAdded

public void nodeAdded(TreeModelEvent evt)
Invoked after a node has been added to the model.
Specified by:
nodeAdded in interface TreeModelListener

nodeRemoved

public void nodeRemoved(TreeModelEvent evt)
Invoked after a node has been removed from the model.
Specified by:
nodeRemoved in interface TreeModelListener

nodeChanged

public void nodeChanged(TreeModelEvent evt)
Invoked after a node in the model has changed in some way.
Specified by:
nodeChanged in interface TreeModelListener

nodeStructureChanged

public void nodeStructureChanged(TreeModelEvent evt)
Invoked after the subtree rooted at a node has changed its structure in some significant way.
Specified by:
nodeStructureChanged in interface TreeModelListener

getRowForNode

public final int getRowForNode(ITreeNode node)
Get the table row number for a given node.
Parameters:
node - The node.
row - The row in the table at which this node is currently displayed. Note that this value will become invalid when any node in the table is expanded or collapsed, as this could potentially change the position of node in the table.
Returns:
The row at which the node currently resides in the table, or -1 if the node was not found in the table.

dispose

public void dispose()
Dispose of the adapter. Causes the adapter to detach its listeners from its associated JTable component, and then null out its references to the JTable and to the associated ITreeModel.