lazyj.widgets
Class Tree<K,V>

java.lang.Object
  extended by lazyj.widgets.Tree<K,V>
Type Parameters:
K - key type (usually Integer).
V - value type (usually String).
All Implemented Interfaces:
OptionProvider<K,V>

public class Tree<K,V>
extends java.lang.Object
implements OptionProvider<K,V>

Generic tree object. It will take the entries through a TreeProvider object and will keep the children in the same order they are returned by the provider. The only restriction is to have one of the roots as first entry. Any orphan node will be put on the same level with the first entry (root).

Since:
Nov 26, 2007 (1.0.4)
Author:
costing

Constructor Summary
Tree(TreeProvider<K,V> provider)
          Build a tree based on the information returned by the provider.
 
Method Summary
 java.util.List<Tree<K,V>> getChildren()
          List of children.
static Tree<java.lang.Integer,java.lang.String> getDefaultTree(DBFunctions db)
          Build a tree upon a simple query that has ID on the first column, parent ID on the second, and value to be displayed on the third.
 K getKey()
          Key of this node.
 java.util.Collection<Option<K,V>> getOptions()
          Convert the tree to a collection of Option objects that are good to be used in a Select.
 java.util.Collection<Option<K,java.lang.String>> getOptionsFullPath(java.lang.String sSeparator)
          Get the options having as value the concatenated values of the parents and their own, separated by the specified separator.
 V getValue()
          Value for this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tree

public Tree(TreeProvider<K,V> provider)
Build a tree based on the information returned by the provider.

Parameters:
provider -
Method Detail

getKey

public K getKey()
Key of this node.

Returns:
key

getValue

public V getValue()
Value for this node.

Returns:
value

getChildren

public java.util.List<Tree<K,V>> getChildren()
List of children. They retain the order from the query result.

Returns:
children

getOptions

public java.util.Collection<Option<K,V>> getOptions()
Convert the tree to a collection of Option objects that are good to be used in a Select.

Specified by:
getOptions in interface OptionProvider<K,V>
Returns:
tree as options

getOptionsFullPath

public java.util.Collection<Option<K,java.lang.String>> getOptionsFullPath(java.lang.String sSeparator)
Get the options having as value the concatenated values of the parents and their own, separated by the specified separator.

Parameters:
sSeparator - some separator, for example " &raquo; "
Returns:
tree as options with full path to them

getDefaultTree

public static Tree<java.lang.Integer,java.lang.String> getDefaultTree(DBFunctions db)
Build a tree upon a simple query that has ID on the first column, parent ID on the second, and value to be displayed on the third. It's just shortcut that relies on BasicDBTreeProvider to do the actual work.

Parameters:
db -
Returns:
the tree
See Also:
BasicDBTreeProvider