Class AbstractFilterTreeModelBuilder<T,B extends FilterTreeModel.Builder<T,B>>
- Type Parameters:
T- the item typeB- the builder type
- All Implemented Interfaces:
FilterTreeModel.Builder<T,B>
FilterTreeModel.Builder implementations. A toolkit builder extends this class, adding
its own options and overriding build() to wrap the FilterTreeModel built by
build(Function, NodesListener) in its own model.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceProvides what a toolkit'sTreeSelectionneeds from the model, seebuild(Function, NodesListener).Nested classes/interfaces inherited from interface is.codion.common.model.component.tree.FilterTreeModel.Builder
FilterTreeModel.Builder.ChildrenStep<T>, FilterTreeModel.Builder.RootsStep -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFilterTreeModelBuilder(Supplier<Collection<T>> roots, Function<NodePath<T>, Collection<T>> children) -
Method Summary
Modifier and TypeMethodDescriptionbuild()protected final FilterTreeModel<T> build(Function<AbstractFilterTreeModelBuilder.SelectionContext<T>, TreeSelection<T>> selection, FilterTreeModel.NodesListener<T> listener) Builds aFilterTreeModelwith the givenTreeSelectionandFilterTreeModel.NodesListener, for a toolkit builder to wrap in its own model.final Bcomparator(@Nullable Comparator<T> comparator) Specifies the comparator to use when sorting siblings, the same for all, seeFilterTreeModel.Builder.comparators(Function).final Bcomparators(Function<NodePath<T>, @Nullable Comparator<T>> comparators) Specifies the comparator to use when sorting the children of each parent, given the path of the parent, the root path for the top level, a null comparator leaving the children in the order the children function returned them in.final Bfinal BThe leaves function, node by node, for when a node can tell whether it is a leaf on its own, from its item for example, seeFilterTreeModel.Builder.leaves(Function).final BThe leaves function decides which nodes not yet loaded are leaves, a loaded node being a leaf when it has no included children.final BonLoadException(Consumer<Exception> onLoadException) By default, exceptions during loading are rethrown, use this method to handle async exceptions differentlyfinal BonSelectedIndex(Consumer<Integer> index) final BonSelectedIndexes(Consumer<List<Integer>> indexes) final BonSelectedItem(Consumer<T> item) final BonSelectedItems(Consumer<List<T>> items) final BonSelectedPath(Consumer<NodePath<T>> path) final BonSelectedPaths(Consumer<List<NodePath<T>>> paths) final BonSelectionChanged(Runnable listener) final BThe path function, the inverse of the children function, providing the path of the node holding an item, so that an item not yet in the model, its parent not loaded, can be selected viaTreeSelection.item()orTreeSelection.items(), which expand its ancestors, loading them, as for an item below a collapsed ancestor.protected final booleanrefresh()final Brefresh(boolean refresh) protected final Bself()
-
Constructor Details
-
AbstractFilterTreeModelBuilder
protected AbstractFilterTreeModelBuilder(Supplier<Collection<T>> roots, Function<NodePath<T>, Collection<T>> children) - Parameters:
roots- supplies the top level itemschildren- provides the children of a node
-
-
Method Details
-
leaves
Description copied from interface:FilterTreeModel.BuilderThe leaves function decides which nodes not yet loaded are leaves, a loaded node being a leaf when it has no included children. Without one, a node not yet loaded is not a leaf, so a view displays an expand handle until it is loaded.
It is given the nodes not yet loaded among the items the roots supplier or the children function return, all of a node's children at once, so it can find the leaves among them with a single query, and returns those which are leaves. It is called along with the children function, so on a background thread when loading asynchronously, its result kept until a refresh reaches the nodes. A view asking whether a node is a leaf does not call it, so it may be slow.
FilterTreeModel.Nodes.add(NodePath, Collection)calls it with the nodes added, andFilterTreeModel.Nodes.replace(NodePath, Object)with the node replaced, on the calling thread.A node not yet loaded, which the leaves function reports as a leaf, is not loaded when expanded, so the children function is not called for it, nor when refreshed, unless the leaves function, called for it again, no longer reports it as a leaf, see
FilterTreeModel.Nodes.refresh(NodePath).Replaces the function set via
FilterTreeModel.Builder.leaf(Predicate), the same option.- Specified by:
leavesin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
leaves- given the paths of nodes not yet loaded, returns those which are leaves, paths not given being ignored- Returns:
- this builder instance
- See Also:
-
leaf
Description copied from interface:FilterTreeModel.BuilderThe leaves function, node by node, for when a node can tell whether it is a leaf on its own, from its item for example, see
FilterTreeModel.Builder.leaves(Function).Replaces the function set via
FilterTreeModel.Builder.leaves(Function), the same option.- Specified by:
leafin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
leaf- returns true if the node identified by the given path is a leaf- Returns:
- this builder instance
- See Also:
-
path
Description copied from interface:FilterTreeModel.BuilderThe path function, the inverse of the children function, providing the path of the node holding an item, so that an item not yet in the model, its parent not loaded, can be selected via
TreeSelection.item()orTreeSelection.items(), which expand its ancestors, loading them, as for an item below a collapsed ancestor.Called on the UI thread, for the items not in the model only. The item is selected right away when loading synchronously, while loading asynchronously only its ancestors are expanded,
TreeSelection.Pending.set(NodePath)selecting a node once it is loaded.- Specified by:
pathin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
path- returns the path of the node holding the given item, null in case it is not in the tree- Returns:
- this builder instance
- See Also:
-
comparator
Description copied from interface:FilterTreeModel.BuilderSpecifies the comparator to use when sorting siblings, the same for all, seeFilterTreeModel.Builder.comparators(Function).- Specified by:
comparatorin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
comparator- the comparator to use when sorting siblings, null for none- Returns:
- this builder instance
-
comparators
Description copied from interface:FilterTreeModel.BuilderSpecifies the comparator to use when sorting the children of each parent, given the path of the parent, the root path for the top level, a null comparator leaving the children in the order the children function returned them in.
Called each time the children of a parent are sorted, when they are loaded, added, replaced, refreshed or excluded, or when the sort order changes. Sets the same option as
FilterTreeModel.Builder.comparator(Comparator), so the last one set wins.- Specified by:
comparatorsin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
comparators- provides the comparator for the children of a parent, given its path- Returns:
- this builder instance
- See Also:
-
included
- Specified by:
includedin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
included- the predicate controlling which nodes are included- Returns:
- this builder instance
- See Also:
-
onLoadException
Description copied from interface:FilterTreeModel.BuilderBy default, exceptions during loading are rethrown, use this method to handle async exceptions differently- Specified by:
onLoadExceptionin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
onLoadException- the exception handler to use during loading- Returns:
- this builder instance
-
refresh
- Specified by:
refreshin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
refresh- true if the model should be refreshed on initialization, false by default- Returns:
- this builder instance
-
onSelectionChanged
- Specified by:
onSelectionChangedin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
listener- the selection listener- Returns:
- this builder instance
-
onSelectedItem
- Specified by:
onSelectedItemin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
item- receives the item of the selected node- Returns:
- this builder instance
- See Also:
-
onSelectedItems
- Specified by:
onSelectedItemsin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
items- receives the items of the selected nodes- Returns:
- this builder instance
- See Also:
-
onSelectedPath
- Specified by:
onSelectedPathin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
path- receives the path of the selected node- Returns:
- this builder instance
- See Also:
-
onSelectedPaths
- Specified by:
onSelectedPathsin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
paths- receives the paths of the selected nodes- Returns:
- this builder instance
- See Also:
-
onSelectedIndex
- Specified by:
onSelectedIndexin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
index- receives the selected index- Returns:
- this builder instance
-
onSelectedIndexes
- Specified by:
onSelectedIndexesin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Parameters:
indexes- receives the selected indexes- Returns:
- this builder instance
-
build
- Specified by:
buildin interfaceFilterTreeModel.Builder<T,B extends FilterTreeModel.Builder<T, B>> - Returns:
- a new
FilterTreeModelinstance
-
build
protected final FilterTreeModel<T> build(Function<AbstractFilterTreeModelBuilder.SelectionContext<T>, TreeSelection<T>> selection, FilterTreeModel.NodesListener<T> listener) Builds aFilterTreeModelwith the givenTreeSelectionandFilterTreeModel.NodesListener, for a toolkit builder to wrap in its own model. The model is not refreshed, the toolkit model being the one to refresh once it is in place, seerefresh().- Parameters:
selection- provides theTreeSelection, given theAbstractFilterTreeModelBuilder.SelectionContextlistener- notified of changes to the included children of nodes, for bridging to the toolkit's own change notifications, such asjavax.swing.event.TreeModelEvents- Returns:
- a new
FilterTreeModelinstance, not refreshed
-
refresh
protected final boolean refresh()- Returns:
- true if the model should be refreshed once built
- See Also:
-
self
- Returns:
- this builder instance
-