# Class HierarchyTreeModel<T>

java.lang.Object
com.macrofocus.hierarchy.swing.HierarchyTreeModel<T>

All Implemented Interfaces:
  `TreeModel`

public class HierarchyTreeModel<T> extends Object implements TreeModel

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HierarchyTreeModel(Hierarchy<T> hierarchy)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addTreeModelListener(TreeModelListener l)`
  `T`
  `getChild(Object parent, int index)`
  `int`
  `getChildCount(Object parent)`
  `int`
  `getIndexOfChild(Object parent, Object child)`
  `Object[]`
  `getPathToRoot(T aNode)`
  Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
  `protected Object[]`
  `getPathToRoot(T aNode, int depth)`
  Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
  `Object`
  `getRoot()`
  `boolean`
  `isLeaf(Object node)`
  `protected void`
  `notifyNodesAdded(T parent, int index, T child)`
  `protected void`
  `notifyNodesChanged(T child)`
  `protected void`
  `notifyNodesRemoved(T parent, int index, T child)`
  `void`
  `notifyStructureChanged()`
  `void`
  `removeTreeModelListener(TreeModelListener l)`
  `void`
  `valueForPathChanged(TreePath path, Object newValue)`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### HierarchyTreeModel

    public HierarchyTreeModel(Hierarchy<T> hierarchy)

- ## Method Details

  - ### getRoot

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

  - ### getChild

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

  - ### getChildCount

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

  - ### isLeaf

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

  - ### getIndexOfChild

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

  - ### valueForPathChanged

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

  - ### addTreeModelListener

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

  - ### removeTreeModelListener

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

  - ### notifyNodesAdded

    protected void notifyNodesAdded(T parent, int index, T child)

  - ### notifyNodesChanged

    protected void notifyNodesChanged(T child)

  - ### notifyNodesRemoved

    protected void notifyNodesRemoved(T parent, int index, T child)

  - ### notifyStructureChanged

    public void notifyStructureChanged()

  - ### getPathToRoot

    public Object[] getPathToRoot(T aNode)
    Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.
    Parameters:
      `aNode` - the TreeNode to get the path for

  - ### getPathToRoot

    protected Object[] getPathToRoot(T aNode, int depth)
    Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.
    Parameters:
      `aNode` - the TreeNode to get the path for
      `depth` - an int giving the number of steps already taken towards the root (on recursive calls), used to size the returned array
    Returns:
      an array of TreeNodes giving the path from the root to the specified node