ca.odell.glazedlists
Class TreeList<E>

java.lang.Object
  extended by ca.odell.glazedlists.AbstractEventList<E>
      extended by ca.odell.glazedlists.TransformedList<TreeList.Node<E>,E>
          extended by ca.odell.glazedlists.TreeList<E>
All Implemented Interfaces:
ListEventListener<TreeList.Node<E>>, EventList<E>, Iterable<E>, Collection<E>, EventListener, List<E>

public final class TreeList<E>
extends TransformedList<TreeList.Node<E>,E>

A hierarchial EventList that infers its structure from a flat list.

Warning: This class is thread ready but not thread safe. See EventList for an example of thread safe code.

Developer Preview this class is still under development and subject to API changes.

Author:
Jesse Wilson

Nested Class Summary
static interface TreeList.ExpansionModel<E>
          Provide the expand/collapse state of nodes.
static interface TreeList.Format<E>
          Define the tree structure of an node by expressing the path from the element itself to the tree's root.
static class TreeList.Node<E>
          A node in the display tree.
 
Field Summary
static TreeList.ExpansionModel NODES_START_COLLAPSED
          An TreeList.ExpansionModel with a simple policy: all nodes start collapsed.
static TreeList.ExpansionModel NODES_START_EXPANDED
          An TreeList.ExpansionModel with a simple policy: all nodes start expanded.
 
Fields inherited from class ca.odell.glazedlists.TransformedList
source
 
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
 
Constructor Summary
TreeList(EventList<E> source, TreeList.Format<E> format)
          Deprecated. use the constructor that takes an TreeList.ExpansionModel
TreeList(EventList<E> source, TreeList.Format<E> format, TreeList.ExpansionModel<E> expansionModel)
          Create a new TreeList that adds hierarchy to the specified source list.
 
Method Summary
 int depth(int visibleIndex)
           
 void dispose()
          Releases the resources consumed by this TransformedList so that it may eventually be garbage collected.
 E get(int visibleIndex)
          Returns the element at the specified position in this list.
 boolean getAllowsChildren(int visibleIndex)
          Whether the value at the specified index can have child nodes or not.
 EventList<TreeList.Node<E>> getNodesList()
           
 List<TreeList.Node<E>> getRoots()
          Get a List containing all TreeList.Nodes with no parents in the tree.
protected  int getSourceIndex(int mutationIndex)
          Gets the index in the source EventList that corresponds to the specified index.
 TreeList.Node<E> getTreeNode(int visibleIndex)
           
 boolean hasChildren(int visibleIndex)
           
 boolean isExpanded(int visibleIndex)
           
protected  boolean isWritable()
          Gets whether the source EventList is writable via this API.
 void listChanged(ListEvent<TreeList.Node<E>> listChanges)
          When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.
 void setExpanded(int visibleIndex, boolean expanded)
          Control whether the child elements of the specified node are visible.
 void setTreeFormat(TreeList.Format<E> treeFormat)
          Change how the structure of the tree is derived.
 int size()
          Returns the number of elements in this list.
 int subtreeSize(int visibleIndex, boolean includeCollapsed)
          The number of nodes including the node itself in its subtree.
 void toggleExpanded(int visibleIndex)
          A convenience method to expand the row if it is currently collapsed or vice versa.
 
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, remove, removeAll, retainAll, set
 
Methods inherited from class ca.odell.glazedlists.AbstractEventList
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NODES_START_EXPANDED

public static final TreeList.ExpansionModel NODES_START_EXPANDED
An TreeList.ExpansionModel with a simple policy: all nodes start expanded.


NODES_START_COLLAPSED

public static final TreeList.ExpansionModel NODES_START_COLLAPSED
An TreeList.ExpansionModel with a simple policy: all nodes start collapsed.

Constructor Detail

TreeList

public TreeList(EventList<E> source,
                TreeList.Format<E> format,
                TreeList.ExpansionModel<E> expansionModel)
Create a new TreeList that adds hierarchy to the specified source list. This constructor does not sort the elements.


TreeList

public TreeList(EventList<E> source,
                TreeList.Format<E> format)
Deprecated. use the constructor that takes an TreeList.ExpansionModel

Method Detail

getNodesList

public EventList<TreeList.Node<E>> getNodesList()
Returns:
an EventList of TreeList.Nodes which can be used to access this tree more structurally.

depth

public int depth(int visibleIndex)
Returns:
the number of ancestors of the node at the specified index. Root nodes have depth 0, other nodes depth is one greater than the depth of their parent node.

subtreeSize

public int subtreeSize(int visibleIndex,
                       boolean includeCollapsed)
The number of nodes including the node itself in its subtree.


size

public int size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Overrides:
size in class TransformedList<TreeList.Node<E>,E>
Returns:
the number of elements in this list.

isWritable

protected boolean isWritable()
Gets whether the source EventList is writable via this API.

Extending classes must override this method in order to make themselves writable.

Specified by:
isWritable in class TransformedList<TreeList.Node<E>,E>

getSourceIndex

protected int getSourceIndex(int mutationIndex)
Gets the index in the source EventList that corresponds to the specified index. More formally, returns the index such that
this.get(i) == source.get(getSourceIndex(i)) for all legal values of i.

Overrides:
getSourceIndex in class TransformedList<TreeList.Node<E>,E>

get

public E get(int visibleIndex)
Returns the element at the specified position in this list.

Specified by:
get in interface List<E>
Overrides:
get in class TransformedList<TreeList.Node<E>,E>
Parameters:
visibleIndex - index of element to return.
Returns:
the element at the specified position in this list.

getTreeNode

public TreeList.Node<E> getTreeNode(int visibleIndex)
Returns:
the tree node at the specified index

hasChildren

public boolean hasChildren(int visibleIndex)
Returns:
true if the node at the specified index has children, regardless of whether such children are visible.

setTreeFormat

public void setTreeFormat(TreeList.Format<E> treeFormat)
Change how the structure of the tree is derived.

Parameters:
treeFormat -

getRoots

public List<TreeList.Node<E>> getRoots()
Get a List containing all TreeList.Nodes with no parents in the tree.


getAllowsChildren

public boolean getAllowsChildren(int visibleIndex)
Whether the value at the specified index can have child nodes or not.

Returns:
true if child nodes can be added to the specified node.
See Also:
TreeList.Format.allowsChildren(E)

isExpanded

public boolean isExpanded(int visibleIndex)
Returns:
true if the children of the node at the specified index are visible. Nodes with no children may be expanded or not, this is used to determine whether to show children should any be added.

setExpanded

public void setExpanded(int visibleIndex,
                        boolean expanded)
Control whether the child elements of the specified node are visible.

Parameters:
expanded - true to expand the node, false to collapse it.

toggleExpanded

public void toggleExpanded(int visibleIndex)
A convenience method to expand the row if it is currently collapsed or vice versa.


listChanged

public void listChanged(ListEvent<TreeList.Node<E>> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.

It is mandatory that the calling thread has obtained the write lock on the source list. This is because the calling thread will have written to the source list to cause this event. This condition guarantees that no writes can occur while the listener is handling this event. It is an error to write to the source list while processing an event.

Specified by:
listChanged in interface ListEventListener<TreeList.Node<E>>
Specified by:
listChanged in class TransformedList<TreeList.Node<E>,E>

dispose

public void dispose()
Releases the resources consumed by this TransformedList so that it may eventually be garbage collected.

A TransformedList will be garbage collected without a call to TransformedList.dispose(), but not before its source EventList is garbage collected. By calling TransformedList.dispose(), you allow the TransformedList to be garbage collected before its source EventList. This is necessary for situations where a TransformedList is short-lived but its source EventList is long-lived.

Warning: It is an error to call any method on a TransformedList after it has been disposed.

Specified by:
dispose in interface EventList<E>
Overrides:
dispose in class TransformedList<TreeList.Node<E>,E>


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by James Lemieux at 2009-01-25 18:40