|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectca.odell.glazedlists.swing.TreeTableSupport
public final class TreeTableSupport
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:
TreeTableCellRenderer
will be installed on the hierarchical
TableColumn
. It wraps any TableCellRenderer
previously
installed on the TableColumn
, or if none was present, a
DefaultTableCellRenderer. The delegate renderer can be changed at any
time using setDelegateRenderer(javax.swing.table.TableCellRenderer)
.TreeTableCellEditor
will be installed on the hierarchical
TableColumn
. It wraps any TableCellEditor
previously
installed on the TableColumn
, or if none was present, a
DefaultCellEditor. The delegate editor can be changed at any
time using setDelegateEditor(javax.swing.table.TableCellEditor)
.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:
must
be displayed.
e.g.: A directory in a file system that contains files and/or subdirectories.
must not
be displayed.
e.g.: A file in a file system.
setShowExpanderForEmptyParent(boolean)
.
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 |
---|
public static TreeTableSupport install(JTable table, TreeList treeList, int modelColumnIndex)
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
:
hierarchyColumnModelIndex
must correspond to a valid
view column index
table
- the table to convert into a tree tabletreeList
- The TreeList capable of answering hierarchical questions
for the hierachical TableColumn's renderer and editormodelColumnIndex
- the model index of the hierarchical column
IllegalStateException
- if this method is called from any Thread
other than the Swing Event Dispatch Threadpublic void uninstall()
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.
IllegalStateException
- if this method is called from any Thread
other than the Swing Event Dispatch Threadpublic void setShowExpanderForEmptyParent(boolean showExpanderForEmptyParent)
TreeList.Format#allowsChildren(Object)
.
public boolean getShowExpanderForEmptyParent()
public void setArrowKeyExpansionEnabled(boolean arrowKeyExpansionEnabled)
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.
public boolean getArrowKeyExpansionEnabled()
public void setRenderer(TreeTableCellRenderer treeTableCellRenderer)
treeTableCellRenderer
when rendering the
hierarchy column of the tree table.
public TreeTableCellRenderer getRenderer()
treeTableCellRenderer
used to render the
hierarchy column of the tree table.
public void setDelegateRenderer(TableCellRenderer renderer)
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.
public TableCellRenderer getDelegateRenderer()
renderer
responsible for rendering the data
associated with each tree node in the hierarchy column.
public void setEditor(TreeTableCellEditor treeTableCellEditor)
treeTableCellEditor
when editing the
hierarchy column of the tree table.
public TreeTableCellEditor getEditor()
treeTableCellEditor
used to render the
hierarchy column of the tree table.
public void setDelegateEditor(TableCellEditor editor)
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.
public TableCellEditor getDelegateEditor()
editor
responsible for editing the data
associated with each tree node in the hierarchy column.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |