org.netbeans.swing.outline 1.20

org.netbeans.swing.outline
Class DefaultOutlineModel

java.lang.Object
  extended by org.netbeans.swing.outline.DefaultOutlineModel
All Implemented Interfaces:
TableModel, TreeModel, OutlineModel

public class DefaultOutlineModel
extends Object
implements OutlineModel

Proxies a standard TreeModel and TableModel, translating events between the two. Note that the constructor is not public; the TableModel that is proxied is the OutlineModel's own. To make use of this class, implement RowModel - that is a mini-table model in which the TreeModel is responsible for defining the set of rows; it is passed an object from the tree, which it may use to generate values for the other columns. Pass that and the TreeModel you want to use to 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.


Constructor Summary
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.
 
Method Summary
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultOutlineModel

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

Parameters:
treeModel - The tree model
rowModel - The row model
largeModel - true if it's a large model tree, false otherwise.
nodesColumnLabel - Label of the node's column

DefaultOutlineModel

protected DefaultOutlineModel(TreeModel treeModel,
                              TableModel tableModel,
                              boolean largeModel,
                              String nodesColumnLabel)
Creates a new instance of DefaultOutlineModel. Note Do not fire table structure changes from the wrapped TableModel (value changes are okay). Changes that affect the number of rows must come from the TreeModel.

Parameters:
treeModel - The tree model
tableModel - The table model
largeModel - true if it's a large model tree, false otherwise.
nodesColumnLabel - Label of the node's column
Method Detail

createOutlineModel

public static OutlineModel createOutlineModel(TreeModel treeModel,
                                              RowModel rowModel)
Create a small model OutlineModel using the supplied tree model and row model

Parameters:
treeModel - The tree model that is the data model for the expandable tree column of an Outline
rowModel - The row model which will supply values for each row based on the tree node in that row in the tree model

createOutlineModel

public 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

Parameters:
treeModel - The tree model
rowModel - The row model
isLargeModel - true if it's a large model tree, false otherwise.

createOutlineModel

public 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

Parameters:
treeModel - The tree model
rowModel - The row model
isLargeModel - true if it's a large model tree, false otherwise.
nodesColumnLabel - Label of the node's column

getTreePathSupport

public final TreePathSupport getTreePathSupport()
Description copied from interface: OutlineModel
Get the TreePathSupport object this model uses to manage information about expanded nodes. TreePathSupport implements logic for tracking expanded nodes, manages TreeWillExpandListeners, 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.

Specified by:
getTreePathSupport in interface OutlineModel

getLayout

public final AbstractLayoutCache getLayout()
Description copied from interface: OutlineModel
Get the layout cache which is used to track the visual state of nodes. This is typically one of the standard JDK layout cache classes, such as VariableHeightLayoutCache or FixedHeightLayoutCache.

Specified by:
getLayout in interface OutlineModel

areMoreEventsPending

public 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. The main thing to avoid is any mid-process repaints, which can only happen if the response to an event will be to call paintImmediately().

This value is guaranteed to be true for the first group of related events, and false if tested in response to the final event.

Returns:
true if more events are pending, false otherwise.

getChild

public final Object getChild(Object parent,
                             int index)
Specified by:
getChild in interface TreeModel

getChildCount

public final int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel

getColumnClass

public final Class getColumnClass(int columnIndex)
Delegates to the RowMapper for > 0 columns; column 0 always returns Object.class

Specified by:
getColumnClass in interface TableModel

getColumnCount

public final int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getColumnName

public String getColumnName(int columnIndex)
Specified by:
getColumnName in interface TableModel

setNodesColumnLabel

public void setNodesColumnLabel(String label)
Change the label of the 'tree' column.

Parameters:
label - New label for tree column.

getIndexOfChild

public final int getIndexOfChild(Object parent,
                                 Object child)
Specified by:
getIndexOfChild in interface TreeModel

getRoot

public final Object getRoot()
Specified by:
getRoot in interface TreeModel

getRowCount

public final int getRowCount()
Specified by:
getRowCount in interface TableModel

getValueAt

public final Object getValueAt(int rowIndex,
                               int columnIndex)
Specified by:
getValueAt in interface TableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface TableModel

isLeaf

public final boolean isLeaf(Object node)
Specified by:
isLeaf in interface TreeModel

addTableModelListener

public final void addTableModelListener(TableModelListener l)
Specified by:
addTableModelListener in interface TableModel

addTreeModelListener

public final void addTreeModelListener(TreeModelListener l)
Specified by:
addTreeModelListener in interface TreeModel

removeTableModelListener

public final void removeTableModelListener(TableModelListener l)
Specified by:
removeTableModelListener in interface TableModel

removeTreeModelListener

public final void removeTreeModelListener(TreeModelListener l)
Specified by:
removeTreeModelListener in interface TreeModel

setValueAt

public final void setValueAt(Object aValue,
                             int rowIndex,
                             int columnIndex)
Delegates to the RowModel (or TableModel) for non-0 columns

Specified by:
setValueAt in interface TableModel

setTreeValueAt

protected void setTreeValueAt(Object aValue,
                              int rowIndex)
Sets the value of a 'tree' cell at given row number. The default implementation does nothing.

Parameters:
aValue -
rowIndex -

valueForPathChanged

public final void valueForPathChanged(TreePath path,
                                      Object newValue)
Specified by:
valueForPathChanged in interface TreeModel

isLargeModel

public boolean isLargeModel()
Description copied from interface: OutlineModel
Determine if the model is a large-model. Large model trees keep less internal state information, relying on the TreeModel more. Essentially they trade performance for scalability. An OutlineModel may be large model or small model; primarily this affects the type of layout cache used, just as it does with JTree.

Specified by:
isLargeModel in interface OutlineModel

org.netbeans.swing.outline 1.20

Built on May 25 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.