ca.odell.glazedlists.swing
Class TreeTableSupport

java.lang.Object
  extended by ca.odell.glazedlists.swing.TreeTableSupport

public final class TreeTableSupport
extends Object

This class install(javax.swing.JTable, ca.odell.glazedlists.TreeList, int)s support for a single hierarchical column within a standard JTable that is backed by an EventTableModel. The EventTableModel, in turn must be backed by the same TreeList which is given as a parameter to install(javax.swing.JTable, ca.odell.glazedlists.TreeList, int).

Typical usage of TreeTableSupport resembles this:


 // create an EventList of data
 EventList myEventList = ...

 // create a TreeList which uses a TreeFormat object to infer a hierarchy for each element in myEventList
 TreeList treeList = new TreeList(myEventList, new MyTreeFormat());

 // create a JTable that displays the contents of treeList in a tabular format
 EventTableModel myTableModel = new EventTableModel(treeList, new MyTableFormat());
 JTable myTable = new JTable(myTableModel);

 // make the 3rd table column a hierarchical column to create a TreeTable
 TreeTableSupport.install(myTable, treeList, 2);
 
In order to achieve all of the treetable behaviours, the following occurs when install(javax.swing.JTable, ca.odell.glazedlists.TreeList, int) is called: Customizing TreeTableSupport

After installing the basic TreeTableSupport, its specific behaviour can be refined by setting properties on the instance of TreeTableSupport returned by the install(javax.swing.JTable, ca.odell.glazedlists.TreeList, int) method. Below are descriptions of some of the available customizations.

Left & Right Arrow Keys

Within a treetable there is ambiguity about the functions performed by the left and right arrow keys. Tables normally use them to advance cell focus to the left or right while trees commonly use them to expand or collapse hierarchies. What behaviour is desirable for any given treetable? By default, TreeTableSupport assumes the table-style behaviour but that can be adjusted to the tree-style behaviour calling setArrowKeyExpansionEnabled(boolean) with an argument of true. Generally speaking, tree-style behaviour is preferrable when the treetable is readonly.

Displaying Expander Buttons

TreeList draws a distinction between three unique situations regarding the display of the expander button for a given tree node, N:

Author:
James Lemieux

Method Summary
 boolean getArrowKeyExpansionEnabled()
          Returns true if the left and right arrow keys are currently used to control the tree hierarchy expansion; false if they are used to control the table's cell focus.
 TableCellEditor getDelegateEditor()
          Returns the editor responsible for editing the data associated with each tree node in the hierarchy column.
 TableCellRenderer getDelegateRenderer()
          Returns the renderer responsible for rendering the data associated with each tree node in the hierarchy column.
 TreeTableCellEditor getEditor()
          Returns the treeTableCellEditor used to render the hierarchy column of the tree table.
 TreeTableCellRenderer getRenderer()
          Returns the treeTableCellRenderer used to render the hierarchy column of the tree table.
 boolean getShowExpanderForEmptyParent()
          Returns true if empty tree nodes that are allowed to have children are displayed with visible expanders while they are empty; false otherwise.
static TreeTableSupport install(JTable table, TreeList treeList, int modelColumnIndex)
          Installs support for a hierarchical table column into the table on the column with the given hierarchyColumnModelIndex.
 void setArrowKeyExpansionEnabled(boolean arrowKeyExpansionEnabled)
          If arrowKeyExpansionEnabled is true then two things are changed in tandem: The left and right arrow keys will toggle the expansion state of hierarchy nodes in the tree rather than adjust cell focus in the table. The table column model's selection model is replaced with a no-op implementation so that column selection and column lead/anchor indexes are NOT tracked.
 void setDelegateEditor(TableCellEditor editor)
          Use the given editor as the new delegate editor of the TreeTableCellEditor which is responsible for editing the data associated with each tree node in the hierarchy column.
 void setDelegateRenderer(TableCellRenderer renderer)
          Use the given renderer as the new delegate renderer of the TreeTableCellRenderer which is responsible for rendering the data associated with each tree node in the hierarchy column.
 void setEditor(TreeTableCellEditor treeTableCellEditor)
          Use the given treeTableCellEditor when editing the hierarchy column of the tree table.
 void setRenderer(TreeTableCellRenderer treeTableCellRenderer)
          Use the given treeTableCellRenderer when rendering the hierarchy column of the tree table.
 void setShowExpanderForEmptyParent(boolean showExpanderForEmptyParent)
          Sets whether the expander is displayed for nodes that do not contain children but are allowed to contain children, and thus may accumulate children in the future.
 void uninstall()
          Removes treetable support from the JTable it was installed on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

install

public static TreeTableSupport install(JTable table,
                                       TreeList treeList,
                                       int modelColumnIndex)
Installs support for a hierarchical table column into the table on the column with the given hierarchyColumnModelIndex. The data returned by the TableModel for the hierarchical column will remain unchanged. But, the renderer and editor will be wrapped with instances of TreeTableCellRenderer and TreeTableCellEditor which take care of displaying the hierarchical information (namely the whitespace indenting and expand/collapse button).

The following must be true in order to successfully install TreeTableSupport on a JTable:

Parameters:
table - the table to convert into a tree table
treeList - The TreeList capable of answering hierarchical questions for the hierachical TableColumn's renderer and editor
modelColumnIndex - the model index of the hierarchical column
Returns:
an instance of the support class providing treetable behaviour
Throws:
IllegalStateException - if this method is called from any Thread other than the Swing Event Dispatch Thread

uninstall

public void uninstall()
Removes treetable support from the JTable it was installed on. This method is useful when the TreeList of items that backs the JTable must outlive the JTable itself. Calling this method will return the hierarchical column to its original state before treetable support was installed, and it will be available for garbage collection independently of the TreeList of items.

Throws:
IllegalStateException - if this method is called from any Thread other than the Swing Event Dispatch Thread

setShowExpanderForEmptyParent

public void setShowExpanderForEmptyParent(boolean showExpanderForEmptyParent)
Sets whether the expander is displayed for nodes that do not contain children but are allowed to contain children, and thus may accumulate children in the future. If this property is true then empty nodes that may contain children in the future are displayed with a visible expander; otherwise they are displayed without the expander. A node signals that it may contain children in the future by returning true from TreeList.Format#allowsChildren(Object).


getShowExpanderForEmptyParent

public boolean getShowExpanderForEmptyParent()
Returns true if empty tree nodes that are allowed to have children are displayed with visible expanders while they are empty; false otherwise.


setArrowKeyExpansionEnabled

public void setArrowKeyExpansionEnabled(boolean arrowKeyExpansionEnabled)
If arrowKeyExpansionEnabled is true then two things are changed in tandem:

If arrowKeyExpansionEnabled is false then the behaviour is reverted to default. That is, left and right arrow keys adjust cell focus in the table and not expansion, and the original column selection model is reinstalled.


getArrowKeyExpansionEnabled

public boolean getArrowKeyExpansionEnabled()
Returns true if the left and right arrow keys are currently used to control the tree hierarchy expansion; false if they are used to control the table's cell focus.


setRenderer

public void setRenderer(TreeTableCellRenderer treeTableCellRenderer)
Use the given treeTableCellRenderer when rendering the hierarchy column of the tree table.


getRenderer

public TreeTableCellRenderer getRenderer()
Returns the treeTableCellRenderer used to render the hierarchy column of the tree table.


setDelegateRenderer

public void setDelegateRenderer(TableCellRenderer renderer)
Use the given renderer as the new delegate renderer of the TreeTableCellRenderer which is responsible for rendering the data associated with each tree node in the hierarchy column.


getDelegateRenderer

public TableCellRenderer getDelegateRenderer()
Returns the renderer responsible for rendering the data associated with each tree node in the hierarchy column.


setEditor

public void setEditor(TreeTableCellEditor treeTableCellEditor)
Use the given treeTableCellEditor when editing the hierarchy column of the tree table.


getEditor

public TreeTableCellEditor getEditor()
Returns the treeTableCellEditor used to render the hierarchy column of the tree table.


setDelegateEditor

public void setDelegateEditor(TableCellEditor editor)
Use the given editor as the new delegate editor of the TreeTableCellEditor which is responsible for editing the data associated with each tree node in the hierarchy column.


getDelegateEditor

public TableCellEditor getDelegateEditor()
Returns the editor responsible for editing the data associated with each tree node in the hierarchy column.



Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by James Lemieux at 2009-01-25 18:40