public class DefaultOutlineModel extends Object implements OutlineModel
createOutlineModel
.
A note on TableModelEvents produced by this model: There is a slight impedance mismatch between TableModelEvent and TreeModelEvent. When the tree changes, it is necessary to fire TableModelEvents to update the display. However, TreeModelEvents support changes to discontiguous segments of the model (i.e. "child nodes 3, 4 and 9 were deleted"). TableModelEvents have no such concept - they operate on contiguous ranges of rows. Therefore, one incoming TreeModelEvent may result in more than one TableModelEvent being fired. Discontiguous TreeModelEvents will be broken into their contiguous segments, which will be fired sequentially (in the case of removals, in reverse order). So, the example above would generate two TableModelEvents, the first indicating that row 9 was removed, and the second indicating that rows 3 and 4 were removed.
Clients which need to know whether the TableModelEvent they have just
received is one of a group (perhaps they update some data structure, and
should not do so until the table's state is fully synchronized with that
of the tree model) may call areMoreEventsPending()
.
In the case of TreeModelEvents which add items to an unexpanded tree node, a simple value change TableModelEvent will be fired for the row in question on the tree column index.
Note also that if the model is large-model, removal events may only indicate those indices which were visible at the time of removal, because less data is retained about the position of nodes which are not displayed. In this case, the only issue is the accuracy of the scrollbar in the model; in practice this is a non-issue, since it is based on the Outline's row count, which will be accurate.
A note to subclassers, if we even leave this class non-final: If you do not use ProxyTableModel and RowMapper (which probably means you are doing something wrong), do not fire structural changes from the TableModel. This class is designed such that the TreeModel is entirely in control of the count and contents of the rows of the table. It and only it may fire structural changes.
Note that this class enforces access only on the event dispatch thread with assertions. All events fired by the underlying table and tree model must be fired on the event dispatch thread.
Modifier | Constructor and Description |
---|---|
protected |
DefaultOutlineModel(TreeModel treeModel,
RowModel rowModel,
boolean largeModel,
String nodesColumnLabel)
Create a new instance of DefaultOutlineModel using the supplied tree model and row model,
specifying if it is a large-model tree
|
protected |
DefaultOutlineModel(TreeModel treeModel,
TableModel tableModel,
boolean largeModel,
String nodesColumnLabel)
Creates a new instance of DefaultOutlineModel.
|
Modifier and Type | Method and Description |
---|---|
void |
addTableModelListener(TableModelListener l) |
void |
addTreeModelListener(TreeModelListener l) |
boolean |
areMoreEventsPending()
Flag which is set to true while multiple TableModelEvents generated
from a single TreeModelEvent are being fired, so clients can avoid
any model queries until all pending changes have been fired.
|
static OutlineModel |
createOutlineModel(TreeModel treeModel,
RowModel rowModel)
Create a small model OutlineModel using the supplied tree model and row model
|
static OutlineModel |
createOutlineModel(TreeModel treeModel,
RowModel rowModel,
boolean isLargeModel)
Create an OutlineModel using the supplied tree model and row model,
specifying if it is a large-model tree
|
static OutlineModel |
createOutlineModel(TreeModel treeModel,
RowModel rowModel,
boolean isLargeModel,
String nodesColumnLabel)
Create an OutlineModel using the supplied tree model and row model,
specifying if it is a large-model tree
|
Object |
getChild(Object parent,
int index) |
int |
getChildCount(Object parent) |
Class |
getColumnClass(int columnIndex)
Delegates to the RowMapper for > 0 columns; column 0 always
returns Object.class
|
int |
getColumnCount() |
String |
getColumnName(int columnIndex) |
int |
getIndexOfChild(Object parent,
Object child) |
AbstractLayoutCache |
getLayout()
Get the layout cache which is used to track the visual state of nodes.
|
Object |
getRoot() |
int |
getRowCount() |
TreePathSupport |
getTreePathSupport()
Get the
TreePathSupport object this model uses to manage
information about expanded nodes. |
Object |
getValueAt(int rowIndex,
int columnIndex) |
boolean |
isCellEditable(int rowIndex,
int columnIndex) |
boolean |
isLargeModel()
Determine if the model is a large-model.
|
boolean |
isLeaf(Object node) |
void |
removeTableModelListener(TableModelListener l) |
void |
removeTreeModelListener(TreeModelListener l) |
void |
setNodesColumnLabel(String label)
Change the label of the 'tree' column.
|
protected void |
setTreeValueAt(Object aValue,
int rowIndex)
Sets the value of a 'tree' cell at given row number.
|
void |
setValueAt(Object aValue,
int rowIndex,
int columnIndex)
Delegates to the RowModel (or TableModel) for non-0 columns
|
void |
valueForPathChanged(TreePath path,
Object newValue) |
protected DefaultOutlineModel(TreeModel treeModel, RowModel rowModel, boolean largeModel, String nodesColumnLabel)
treeModel
- The tree modelrowModel
- The row modellargeModel
- true
if it's a large model tree, false
otherwise.nodesColumnLabel
- Label of the node's columnprotected DefaultOutlineModel(TreeModel treeModel, TableModel tableModel, boolean largeModel, String nodesColumnLabel)
treeModel
- The tree modeltableModel
- The table modellargeModel
- true
if it's a large model tree, false
otherwise.nodesColumnLabel
- Label of the node's columnpublic static OutlineModel createOutlineModel(TreeModel treeModel, RowModel rowModel)
treeModel
- The tree model that is the data model for the expandable
tree column of an OutlinerowModel
- The row model which will supply values for each row based
on the tree node in that row in the tree modelpublic static OutlineModel createOutlineModel(TreeModel treeModel, RowModel rowModel, boolean isLargeModel)
treeModel
- The tree modelrowModel
- The row modelisLargeModel
- true
if it's a large model tree, false
otherwise.public static OutlineModel createOutlineModel(TreeModel treeModel, RowModel rowModel, boolean isLargeModel, String nodesColumnLabel)
treeModel
- The tree modelrowModel
- The row modelisLargeModel
- true
if it's a large model tree, false
otherwise.nodesColumnLabel
- Label of the node's columnpublic final TreePathSupport getTreePathSupport()
OutlineModel
TreePathSupport
object this model uses to manage
information about expanded nodes. TreePathSupport
implements
logic for tracking expanded nodes, manages TreeWillExpandListener
s,
and is a repository for preserving expanded state information about nodes whose parents
are currently collapsed. JTree implements very similar logic internally
to itself.
(PENDING) It is not yet determined if TreePathSupport will remain a public class.
getTreePathSupport
in interface OutlineModel
public final AbstractLayoutCache getLayout()
OutlineModel
VariableHeightLayoutCache
or
FixedHeightLayoutCache
.getLayout
in interface OutlineModel
public boolean areMoreEventsPending()
This value is guaranteed to be true for the first group of related events, and false if tested in response to the final event.
true
if more events are pending, false
otherwise.public final int getChildCount(Object parent)
getChildCount
in interface TreeModel
public final Class getColumnClass(int columnIndex)
getColumnClass
in interface TableModel
public final int getColumnCount()
getColumnCount
in interface TableModel
public String getColumnName(int columnIndex)
getColumnName
in interface TableModel
public void setNodesColumnLabel(String label)
label
- New label for tree column.public final int getIndexOfChild(Object parent, Object child)
getIndexOfChild
in interface TreeModel
public final int getRowCount()
getRowCount
in interface TableModel
public final Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface TableModel
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface TableModel
public final void addTableModelListener(TableModelListener l)
addTableModelListener
in interface TableModel
public final void addTreeModelListener(TreeModelListener l)
addTreeModelListener
in interface TreeModel
public final void removeTableModelListener(TableModelListener l)
removeTableModelListener
in interface TableModel
public final void removeTreeModelListener(TreeModelListener l)
removeTreeModelListener
in interface TreeModel
public final void setValueAt(Object aValue, int rowIndex, int columnIndex)
setValueAt
in interface TableModel
protected void setTreeValueAt(Object aValue, int rowIndex)
aValue
- rowIndex
- public final void valueForPathChanged(TreePath path, Object newValue)
valueForPathChanged
in interface TreeModel
public boolean isLargeModel()
OutlineModel
isLargeModel
in interface OutlineModel