JIDE 3.5.15

com.jidesoft.grid
Class TreeTableUtils

java.lang.Object
  extended by com.jidesoft.grid.TreeTableUtils

public class TreeTableUtils
extends Object


Constructor Summary
TreeTableUtils()
           
 
Method Summary
static Row getChildAt(TableModel model, Row parent, int index)
          Get the child of the parent row in the designated index inside the table model.
static int getChildIndex(TableModel model, Row parent, Row child)
          Get the index of the child within the parent's children inside the table model.
static List<Row> getChildren(TableModel model, Row parent)
          Get children list of the parent row inside the table model.
static int getChildrenCount(TableModel model, Row parent)
          Get the direct children count of a row inside the table model.
static int getDescendantCount(TableModel model, Row parent, boolean leafOnly, boolean includeCollapsedNodes)
          The method can only be used for any table model who has one inner model as TreeTableModel to find the current visible descendant count in that level.
static List<Row> getDescendants(TableModel model, Row parent, boolean directChildOnly, boolean leafOnly, boolean includeCollapsedNodes)
          Gets descendants list of the parent row inside the table model.
static Row getRow(TableModel model, int rowIndex)
          Gets the row in the row index of the table model.
static boolean hasDescendant(TableModel model, Row parent, boolean leafOnly, boolean includeCollapsedNodes)
          Gets if there is at least one descendant for the parent row in the model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeTableUtils

public TreeTableUtils()
Method Detail

getChildrenCount

public static int getChildrenCount(TableModel model,
                                   Row parent)
Get the direct children count of a row inside the table model.

It only returns the count of direct child while getDescendantCount(javax.swing.table.TableModel, Row, boolean, boolean) returns the count of its descendant.

Parameters:
model - the table model. In most case, it should be an instance of ITreeTableModel
parent - the parent row
Returns:
the count of direct children. 0 of the model is not an instance of ITreeTableModel.
See Also:
getChildren(javax.swing.table.TableModel, Row)

getChildIndex

public static int getChildIndex(TableModel model,
                                Row parent,
                                Row child)
Get the index of the child within the parent's children inside the table model.

Parameters:
model - the table model. In most case, it should be an instance of ITreeTableModel
parent - the parent row
child - the child row
Returns:
the index. -1 if the child is not a child of the parent inside the table model.
See Also:
getChildren(javax.swing.table.TableModel, Row)

getChildAt

public static Row getChildAt(TableModel model,
                             Row parent,
                             int index)
Get the child of the parent row in the designated index inside the table model.

Parameters:
model - the table model. In most case, it should be an instance of ITreeTableModel
parent - the parent row
index - the child index
Returns:
the child. null if index is not valid.
See Also:
getChildren(javax.swing.table.TableModel, Row)

getRow

public static Row getRow(TableModel model,
                         int rowIndex)
Gets the row in the row index of the table model.

Parameters:
model - the table model
rowIndex - the row index
Returns:
the Row instance.
Since:
3.2.3

getChildren

public static List<Row> getChildren(TableModel model,
                                    Row parent)
Get children list of the parent row inside the table model.

You could use this series of methods for FilterableTreeTableModel, SortableTreeTableModel or TreeTableModel directly. The children list will be the visible children from the designated table model point of view. For example, assume a parent row has 4 children in original tree table model while the FilterableTableModel contains only 3 children. If you use the original table model and the row to invoke this method, it will return a list with 4 children. If you use the filterable table model instead and the same row, it will return a 3-element list instead.

Parameters:
model - the table model. In most case, it should be an instance of ITreeTableModel
parent - the parent row
Returns:
the direct children list of the parent row inside the table model. Empty list if the model is not an instance of ITreeTableModel.

getDescendants

public static List<Row> getDescendants(TableModel model,
                                       Row parent,
                                       boolean directChildOnly,
                                       boolean leafOnly,
                                       boolean includeCollapsedNodes)
Gets descendants list of the parent row inside the table model.

Parameters:
model - the table model. In most case, it should be an instance of ITreeTableModel
parent - the parent row
directChildOnly - the flag if only direct child should be returned
leafOnly - the flag if only leaf descendants should be returned
includeCollapsedNodes - the flag if the collapsed nodes need to be included
Returns:
the descendant rows.

hasDescendant

public static boolean hasDescendant(TableModel model,
                                    Row parent,
                                    boolean leafOnly,
                                    boolean includeCollapsedNodes)
Gets if there is at least one descendant for the parent row in the model.

This method has higher performance than getDescendantCount(javax.swing.table.TableModel, Row, boolean, boolean) since it will simply return true without looping all child nodes as long as it gets one visible child row.

Parameters:
model - the outer table model
parent - the Row to be queried
leafOnly - the count will only include leaf children or not
includeCollapsedNodes - if the collapsed nodes need to be included
Returns:
true if there is a descendant for the parent row in the model. Otherwise false.
Since:
3.2.2

getDescendantCount

public static int getDescendantCount(TableModel model,
                                     Row parent,
                                     boolean leafOnly,
                                     boolean includeCollapsedNodes)
The method can only be used for any table model who has one inner model as TreeTableModel to find the current visible descendant count in that level. It has two options, leaf only or count collapsed nodes.

It could hit performance since we have to expand all to count the actual leaf nodes then set the original expansion state back.

Parameters:
model - the outer table model
parent - the Row to be queried
leafOnly - the count will only include leaf children or not
includeCollapsedNodes - if the collapsed nodes need to be included
Returns:
the visible children count in the outer table model

JIDE 3.5.15