Key responsibilities:
Typical usage involves subclassing to implement a specific kind of tree node (e.g., see TreeItem ).
V
the data type associated with each node
N
the type of the node itself (for fluent API use)
S
the selection type or structure, commonly the node type or a list of nodes
Provides methods for:
Each node added to the tree is a CheckTreeItem , which can be checked or unchecked. Selecting an item doesn't automatically uncheck the previously selected items, which provides a multi-checkable behavior.
Example Usage:
CheckTree tree = CheckTree.create("Root node", "root_value");
CheckTreeItem child1 = CheckTreeItem.create("Child 1", "child1_value");
CheckTreeItem child2 = CheckTreeItem.create("Child 2", "child2_value");
tree.appendChild(child1).appendChild(child2);
tree.selectAll(); // Checks all items
List
> selection = tree.getFlatSelection(); // returns all checked items throughout the tree
V
the type of data/value associated with each tree item
Key behaviors:
Example Usage:
CheckTreeItem item = CheckTreeItem.create("My Item", "dataValue");
// mark as selected:
item.select();
V
the type of value or data object associated with this node
public void TreeNode(Icon<?> icon, String title)
TreeNode with an icon and a title.
icon
the icon to display
title
the text label for this node
public void TreeNode(String title)
TreeNode with a title only (no icon).
title
the text label for this node
public void TreeNode(Icon<?> icon)
TreeNode with an icon only (no title).
icon
the icon to display
public void TreeNode(String title, V value)
TreeNode with a title and a data value.
title
the text label for this node
value
the data value associated with the node
public void TreeNode(Icon<?> icon, String title, V value)
TreeNode with an icon, title, and a data value.
icon
the icon to display
title
the text label
value
the data value
public void TreeNode(Icon<?> icon, V value)
TreeNode with an icon and a data value (no title).
icon
the icon to display
value
the data value
public N setTitle(String title)
title
the title text
this node (for fluent API)
public String getTitle()
the title string
public void deactivate()
dui_active CSS class. If this node has child nodes, they are also deactivated, and if the tree is configured for auto collapse, the node collapses. Updates the icon accordingly.
public N appendChild(N node)
node
the child node to add
this node (for fluent API)
public N appendChild(N[] treeItems)
treeItems
the child nodes to add
this node (for fluent API)
public void removeNode(N item)
item
the child node to remove
public N clear()
this node (for fluent API)
public N remove()
this node (for fluent API)
public PrefixElement getPrefixElement()
Returns a PrefixElement that wraps the node's content area, allowing insertion of custom elements (e.g., icons) before the text.
public PostfixElement getPostfixElement()
Returns a PostfixElement that wraps the node's content area, allowing insertion of custom elements (e.g., badges) after the text.
public N appendChild(Separator separator)
separator
a Separator object
this node (for fluent API)
public RootNode<V, N, S> getRootNode()
Returns the root of the entire tree structure. Typically used for configuration or top-level behaviors.
public Optional<IsParentNode<V, N, S>> getParent()
public void setActiveNode(N activeNode)
activeNode
The TreeItem to set as the active item.
public List<N> getPath()
an ordered list of nodes from the tree root to this node
public List<V> getPathValues()
an ordered list of values from the tree root to this node
public List<N> getSubNodes()
a list of child nodes
public void doActivate()
public N activate()
this node (for fluent API)
public N getActiveNode()
null if none is active.
the active node, or null
public TreeNode<V, N, S> setToggleTarget(ToggleTarget toggleTarget)
toggleTarget
the new toggle target
this node (for fluent API)
public boolean isLeaf()
true if no children, false otherwise
public N setIcon(Icon<?> icon)
icon
the new icon to display
this node (for fluent API)
public HTMLAnchorElement getClickableElement()
Returns the anchor element for the node, which is used for wave effects (unless toggle target is icon-only).
public void collapseAll()
public void expandAll()
public N expandNode()
this node (for fluent API)
public N collapseNode()
this node (for fluent API)
public N expandNode(boolean expandParent)
expandParent is true , also expands all ancestors.
expandParent
whether to expand parent nodes too
this node (for fluent API)
public N collapseNode(boolean collapseParent)
collapseParent is true , also collapse all ancestors.
collapseParent
whether to collapse parent nodes too
this node (for fluent API)
public N show(boolean expandParent)
expandParent
if true, parent nodes are also expanded
this node (for fluent API)
public N hide(boolean collapseParent)
collapseParent
if true, parent nodes are also expanded
this node (for fluent API)
public void clearFilter()
public boolean filter(String searchToken)
searchToken
the token to search for
true if this node or any child matches the search token, false otherwise
public boolean filterChildren(String searchToken)
true if any child node matches.
searchToken
the token to filter by
true if any child matches, false otherwise
public boolean isAutoExpandFound()
true if auto-expand is enabled for found nodes
public TreeItemFilter<N> getFilter()
a TreeItemFilter used to evaluate matches
public V getValue()
the node's value
public void setValue(V value)
value
the new value
public Element getWavesElement()
By default, wave effects apply to the anchor, unless ICON is selected.
public SpanElement getTextElement()
public UListElement getSubTree()
the sub-tree element
public N pauseSelectionListeners()
this node
public N resumeSelectionListeners()
this node
public N togglePauseSelectionListeners(boolean toggle)
toggle
if true, listeners are paused; if false, they are resumed
this node
public Set<SelectionListener<? super N, ? super S>> getSelectionListeners()
Returns the set of selection listeners associated with this node.
public Set<SelectionListener<? super N, ? super S>> getDeselectionListeners()
Returns the set of deselection listeners associated with this node.
public boolean isSelectionListenersPaused()
Indicates whether selection listeners are currently paused.
public N triggerSelectionListeners(N source, S selection)
Notifies all registered selection listeners of a selection event, unless listeners are paused.
public N triggerDeselectionListeners(N source, S selection)
Notifies all registered deselection listeners of a deselection event, unless listeners are paused.
public boolean isActive()
true if the object is active, false otherwise.
public HTMLLIElement element()
Returns the underlying
public void CheckTree()
CheckTree with no title or associated value.
public void CheckTree(String treeTitle)
CheckTree with the given title.
treeTitle
the title of the tree
public void CheckTree(String treeTitle, V value)
CheckTree with the given title and associated data value.
treeTitle
the title of the tree
value
the data value associated with the root item
public static CheckTree<V> create(String title, V value)
CheckTree with the specified title and associated data value.
title
the title of the root item
value
the data value associated with the root item
V
the type of data
a new CheckTree instance
public static CheckTree<V> create(String title)
CheckTree with the specified title and no associated data value.
title
the title of the root item
V
the type of data
a new CheckTree instance
public static CheckTree<V> create()
CheckTree (no title or value).
V
the type of data
a new CheckTree instance
public List<CheckTreeItem<V>> getSelection()
a list of checked root-level items
public List<CheckTreeItem<V>> getFlatSelection()
a list of all checked items in this tree
public void onSelectionChanged(CheckTreeItem<V> source, List<CheckTreeItem<V>> selection, boolean silent)
When the selection changes (an item is checked or unchecked), notifies any registered listeners.
source
the item that triggered the selection change
selection
the new selection
silent
true to suppress event notifications
public void setActiveNode(CheckTreeItem<V> node, boolean silent)
The previously active node (if any) will be deactivated.
node
the node to activate
silent
true to suppress event notifications
public CheckTree<V> selectAll()
this CheckTree (for method chaining)
public CheckTree<V> selectAll(boolean silent)
silent
if true , no selection listeners are triggered
this CheckTree (for method chaining)
public CheckTree<V> deselectAll()
this CheckTree (for method chaining)
public CheckTree<V> deselectAll(boolean silent)
silent
if true , no selection listeners are triggered
this CheckTree (for method chaining)
public CheckTree<V> addNodeActivationListener(ChildHandler<CheckTree<V>, CheckTreeItem<V>> handler)
handler
a functional interface that receives this tree and the newly activated item
this CheckTree (for method chaining)
public CheckTree<V> addNodeActivationListener(RegistryRecord<ChildHandler<CheckTree<V>, CheckTreeItem<V>>> record)
record
the registry record containing the handler
this CheckTree (for method chaining)
public CheckTree<V> removeNodeActivationListener(ChildHandler<CheckTree<V>, CheckTreeItem<V>> handler)
handler
the ChildHandler to remove
this CheckTree (for method chaining)
public void onActiveNodeChanged(CheckTreeItem<V> source, List<CheckTreeItem<V>> selection, boolean silent)
Notifies all registered activation handlers when the active node changes.
source
the newly active node
selection
the current selection (checked items)
silent
true to suppress notifications
public void CheckTreeItem(Icon<?> icon, String title)
public void CheckTreeItem(String title)
CheckTreeItem with only a title (no icon).
title
the text label
public void CheckTreeItem(Icon<?> icon)
CheckTreeItem with only an icon (no text label).
icon
the Icon to display
public void CheckTreeItem(String title, V value)
CheckTreeItem with a title and a data value.
title
the text label
value
the data value
public void CheckTreeItem(Icon<?> icon, String title, V value)
CheckTreeItem with an icon, a title, and a data value.
icon
the Icon to display
title
the text label
value
the data value
public void CheckTreeItem(Icon<?> icon, V value)
CheckTreeItem with an icon and a data value (no text label).
icon
the Icon to display
value
the data value
public static CheckTreeItem<String> create(String title)
CheckTreeItem with the specified title, using the title string as both the label and the data value.
title
the text label and value for the node
a new CheckTreeItem
public static CheckTreeItem<String> create(Icon<?> icon, String title)
CheckTreeItem with an icon and a title string, using the title as both label and data value.
icon
the Icon to display beside the title
title
the text label and value for the node
a new CheckTreeItem
public static CheckTreeItem<String> create(Icon<?> icon)
CheckTreeItem with only an icon. The data value is set to an empty string.
icon
the Icon to display
a new CheckTreeItem with an empty string value
public static CheckTreeItem<T> create(String title, T value)
CheckTreeItem with the specified title and value.
title
the text label for this node
value
the data value
T
the value type
a new CheckTreeItem
public static CheckTreeItem<T> create(Icon<?> icon, String title, T value)
CheckTreeItem with the specified icon, title, and value.
icon
the Icon to display
title
the text label
value
the data value
T
the value type
a new CheckTreeItem
public static CheckTreeItem<T> create(Icon<?> icon, T value)
CheckTreeItem with an icon and a data value (no text label).
icon
the Icon to display
value
the data value
T
the value type
a new CheckTreeItem
public List<CheckTreeItem<V>> getRootSelection()
CheckTree , otherwise returns an empty list. This is used to know which items are selected at the top level.
a list of selected items at the root level
public List<CheckTreeItem<V>> getSelection()
Returns a list of this node's immediate children that are currently selected (checked).
public List<CheckTreeItem<V>> getFlatSelection()
a list of selected items in the entire subtree
public void setActiveNode(CheckTreeItem<V> activeItem, boolean silent)
Sets the active node for this item's subtree, optionally silent. Deactivates the previously active node and then notifies the root node's onActiveNodeChanged method if silent is false .
public CheckTreeItem<V> deselect()
public CheckTreeItem<V> select()
public CheckTreeItem<V> select(boolean silent)
public CheckTreeItem<V> deselect(boolean silent)
public boolean isSelected()
public boolean isSelectable()
public CheckTreeItem<V> setSelectable(boolean selectable)
public CheckTreeItem<V> setSelected(boolean selected)
public CheckTreeItem<V> setSelected(boolean selected, boolean silent)
public void onSelectionChanged(CheckTreeItem<V> source, List<CheckTreeItem<V>> selection, boolean silent)
Called when selection changes in a child node. Adjusts this node's own checkbox state to reflect partial (indeterminate) or uniform (checked/unchecked) selection among its children, and propagates selection change up to the parent if applicable.