public final class TreeList<E> extends TransformedList<TreeList.Node<E>,E>
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.
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
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. |
source
publisher, readWriteLock, updates
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.Node s 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.
|
static <E> TreeList.ExpansionModel<E> |
nodesStartCollapsed() |
static <E> TreeList.ExpansionModel<E> |
nodesStartExpanded() |
E |
remove(int visibleIndex)
Removes the element at the specified position in this list (optional operation).
|
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.
|
add, addAll, clear, removeAll, retainAll, set
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
replaceAll, sort, spliterator
parallelStream, removeIf, stream
public static final TreeList.ExpansionModel NODES_START_EXPANDED
TreeList.ExpansionModel
with a simple policy: all nodes start expanded.public static final TreeList.ExpansionModel NODES_START_COLLAPSED
TreeList.ExpansionModel
with a simple policy: all nodes start collapsed.public TreeList(EventList<E> source, TreeList.Format<E> format, TreeList.ExpansionModel<E> expansionModel)
@Deprecated public TreeList(EventList<E> source, TreeList.Format<E> format)
TreeList.ExpansionModel
public static final <E> TreeList.ExpansionModel<E> nodesStartExpanded()
TreeList.ExpansionModel
with a simple policy: all nodes start expanded.public static final <E> TreeList.ExpansionModel<E> nodesStartCollapsed()
TreeList.ExpansionModel
with a simple policy: all nodes start collapsed.public EventList<TreeList.Node<E>> getNodesList()
EventList
of TreeList.Node
s which can be used to access this tree more
structurally.public int depth(int visibleIndex)
public int subtreeSize(int visibleIndex, boolean includeCollapsed)
public int size()
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.size
in interface Collection<E>
size
in interface List<E>
size
in class TransformedList<TreeList.Node<E>,E>
protected boolean isWritable()
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList<TreeList.Node<E>,E>
protected int getSourceIndex(int mutationIndex)
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
.getSourceIndex
in class TransformedList<TreeList.Node<E>,E>
public E get(int visibleIndex)
get
in interface List<E>
get
in class TransformedList<TreeList.Node<E>,E>
visibleIndex
- index of element to return.public E remove(int visibleIndex)
remove
in interface List<E>
remove
in class TransformedList<TreeList.Node<E>,E>
visibleIndex
- the index of the element to removed.public TreeList.Node<E> getTreeNode(int visibleIndex)
public boolean hasChildren(int visibleIndex)
true
if the node at the specified index has children, regardless of
whether such children are visible.public void setTreeFormat(TreeList.Format<E> treeFormat)
public List<TreeList.Node<E>> getRoots()
List
containing all TreeList.Node
s with no parents in the tree.public boolean getAllowsChildren(int visibleIndex)
true
if child nodes can be added to the
specified node.TreeList.Format.allowsChildren(E)
public boolean isExpanded(int visibleIndex)
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.public void setExpanded(int visibleIndex, boolean expanded)
expanded
- true
to expand the node, false
to collapse it.public void toggleExpanded(int visibleIndex)
public void listChanged(ListEvent<TreeList.Node<E>> listChanges)
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.
listChanged
in interface ListEventListener<TreeList.Node<E>>
listChanged
in class TransformedList<TreeList.Node<E>,E>
listChanges
- a ListEvent
describing the changes to the listpublic void dispose()
TransformedList
so that it may eventually be
garbage collected.
A TransformedList
will be garbage collected without a call to dispose()
, but
not before its source EventList
is garbage collected. By calling #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.
dispose
in interface EventList<E>
dispose
in class TransformedList<TreeList.Node<E>,E>
Copyright © 2024 levigo holding gmbh. All rights reserved.