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:
javax.swing.tree.TreeModel

public abstract class AbstractTreeModel<T>
extends TreeModelSupport
implements javax.swing.tree.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 java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
protected  java.util.Map<T,java.util.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
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 int getChildCount(java.lang.Object parent)
           
 java.util.Collection<T> getChilderen(T parent)
          Get all childeren of a node and load them if they are not in the cache
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 int getLoadOnDemandMode()
           
 T getParent(T child)
          Find the parent using a child.
abstract  T getRoot()
           
 javax.swing.tree.TreePath getTreePathFor(T node)
          Get the treepath for a node
 boolean isLeaf(java.lang.Object node)
           
 boolean isLoaded(T node)
          Detect if the node in question has been loaded or not (loading on demand)
protected  java.util.Collection<T> loadChilderen(T parent)
          loading-on-demand hook-in
static void main(java.lang.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, java.util.Collection<T> childeren)
           
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.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 java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

treeNodes

protected java.util.Map<T,java.util.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 javax.swing.tree.TreeModel

loadChilderen

protected java.util.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 javax.swing.tree.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(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel
See Also:
TreeModel.getChildCount(java.lang.Object)

getChilderen

public java.util.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,
                            java.util.Collection<T> childeren)
Parameters:
parent -
childeren -

getChild

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

getIndexOfChild

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

isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Specified by:
valueForPathChanged in interface javax.swing.tree.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(java.lang.String[] args)
open a frame for quick testing



Copyright © 2010 KnowledgePlaza. All Rights Reserved.