org.tbee.swing.tree
Class AbstractTreeModel<T>

java.lang.Object
  extended by org.tbee.swing.tree.TreeModelSupport
      extended by org.tbee.swing.tree.AbstractTreeModel<T>
All Implemented Interfaces:
TreeModel

public abstract class AbstractTreeModel<T>
extends TreeModelSupport
implements TreeModel

A utility class to create custom TreeModels where the nodes themselves do not need to implement TreeNode or MutableTreeNode. The object representing a tree node should have "toString" return the text that will be shown in the tree. If an array, List, Set, or Map is used, only getRoot (because we need to start somewhere) and loadChilderen need to be extended.

Version:
$Revision: 1.16 $

Field Summary
static int LOADONDEMAND_MINIMAL
           
static int LOADONDEMAND_VISUAL
           
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
protected  Map<T,Collection<T>> treeNodes
           
 
Constructor Summary
AbstractTreeModel()
           
 
Method Summary
 void clear()
          Clear the cache
 void clear(T node)
          Remove one node and all its childeren from the cache
 Object getChild(Object parent, int index)
           
 int getChildCount(Object parent)
           
 Collection<T> getChilderen(T parent)
          Get all childeren of a node and load them if they are not in the cache
 int getIndexOfChild(Object parent, Object child)
           
 int getLoadOnDemandMode()
           
 T getParent(T child)
          Find the parent using a child.
abstract  T getRoot()
           
 TreePath getTreePathFor(T node)
          Get the treepath for a node
 boolean isLeaf(Object node)
           
 boolean isLoaded(T node)
          Detect if the node in question has been loaded or not (loading on demand)
protected  Collection<T> loadChilderen(T parent)
          loading-on-demand hook-in
static void main(String[] args)
          open a frame for quick testing
 void setLoadOnDemandMode(int mode)
          The load-on-demand mode sets how much data is loaded.
 void updateChilderen(T parent, Collection<T> childeren)
           
 void valueForPathChanged(TreePath path, Object newValue)
           
 
Methods inherited from class org.tbee.swing.tree.TreeModelSupport
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, removeTreeModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, removeTreeModelListener
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

treeNodes

protected Map<T,Collection<T>> treeNodes

LOADONDEMAND_MINIMAL

public static int LOADONDEMAND_MINIMAL

LOADONDEMAND_VISUAL

public static int LOADONDEMAND_VISUAL
Constructor Detail

AbstractTreeModel

public AbstractTreeModel()
Method Detail

getRoot

public abstract T getRoot()
Specified by:
getRoot in interface TreeModel

loadChilderen

protected Collection<T> loadChilderen(T parent)
loading-on-demand hook-in

Parameters:
parent -
Returns:

setLoadOnDemandMode

public void setLoadOnDemandMode(int mode)
The load-on-demand mode sets how much data is loaded. - Minimal means that only that is loaded what is required to display the tree, specifically it is unclear if a node if a leaf until it is attempted to open. Up until then the node is assumed to be a node (and not a leaf). - Correct means that all at-that-point end node are also loaded to determine if they are leaves.


getLoadOnDemandMode

public int getLoadOnDemandMode()

clear

public void clear()
Clear the cache

Parameters:
node -

clear

public void clear(T node)
Remove one node and all its childeren from the cache

Parameters:
node -

getTreePathFor

public TreePath getTreePathFor(T node)
Get the treepath for a node

Parameters:
node -
Returns:

isLoaded

public boolean isLoaded(T node)
Detect if the node in question has been loaded or not (loading on demand)


getChildCount

public int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel
See Also:
TreeModel.getChildCount(java.lang.Object)

getChilderen

public Collection<T> getChilderen(T parent)
Get all childeren of a node and load them if they are not in the cache


updateChilderen

public void updateChilderen(T parent,
                            Collection<T> childeren)
Parameters:
parent -
childeren -

getChild

public Object getChild(Object parent,
                       int index)
Specified by:
getChild in interface TreeModel
See Also:
TreeModel.getChild(java.lang.Object, int)

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Specified by:
getIndexOfChild in interface TreeModel
See Also:
TreeModel.getIndexOfChild(java.lang.Object, java.lang.Object)

isLeaf

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

valueForPathChanged

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

getParent

public T getParent(T child)
Find the parent using a child. BEWARE: if loading on demand has not loaded the parent, the child will not be found!


main

public static void main(String[] args)
open a frame for quick testing



Copyright © 2011 KnowledgePlaza. All Rights Reserved.