Class AbstractEntityTreeModelBuilder<B extends EntityTreeModel.Builder<B>>
- Type Parameters:
B- the builder type
- All Implemented Interfaces:
FilterTreeModel.Builder<Entity,,B> EntityTreeModel.Builder<B>
EntityTreeModel.Builder implementations. A toolkit builder extends this class, overriding
build() to build its own model, based on AbstractEntityTreeModel.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.framework.model.EntityTreeModel.Builder
EntityTreeModel.Builder.Children, EntityTreeModel.Builder.ConnectionStep, EntityTreeModel.Builder.Roots, EntityTreeModel.Builder.RootsStepNested classes/interfaces inherited from interface is.codion.common.model.component.tree.FilterTreeModel.Builder
FilterTreeModel.Builder.ChildrenStep<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractEntityTreeModelBuilder(EntityType rootType, Consumer<EntityTreeModel.Builder.Roots> roots, EntityConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionbuild()final Bchildren(ForeignKey foreignKey) Adds the entities referencing a node via the given foreign key as its children, for the nodes of the referenced entity type.final Bchildren(ForeignKey foreignKey, Consumer<EntityTreeModel.Builder.Children> children) Adds the entities referencing a node via the given foreign key as its children, seeEntityTreeModel.Builder.children(ForeignKey), configuring the query selecting them.final Bcomparator(@Nullable Comparator<Entity> comparator) Specifies the comparator for the roots, and the children via each foreign key, which specify neither a comparator nor an order by, in place of the comparator of their entity type, null for the query order.final Bcomparators(Function<NodePath<Entity>, @Nullable Comparator<Entity>> comparators) Replaces the ordering of siblings entirely, the roots, the foreign key comparators and order bys, and the entity type comparators.final Bfinal BReplaces the default leaf detection, seeEntityTreeModel.Builder.leaves(Function), with a function deciding node by node, based on a domain attribute for example.final BReplaces the default leaf detection, which queries for the siblings referenced via the configured foreign keys, a node of an entity type no configured foreign key references always being a leaf.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<Entity> item) final BonSelectedItems(Consumer<List<Entity>> items) final BonSelectedPath(Consumer<NodePath<Entity>> path) final BonSelectedPaths(Consumer<List<NodePath<Entity>>> 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.final Brefresh(boolean refresh) protected final Bself()
-
Constructor Details
-
AbstractEntityTreeModelBuilder
protected AbstractEntityTreeModelBuilder(EntityType rootType, Consumer<EntityTreeModel.Builder.Roots> roots, EntityConnection connection) - Parameters:
rootType- the type of the root entitiesroots- configures the rootsconnection- the connection
-
-
Method Details
-
children
Description copied from interface:EntityTreeModel.BuilderAdds the entities referencing a node via the given foreign key as its children, for the nodes of the referenced entity type. A foreign key referencing its own entity type applies at every level.- Specified by:
childrenin interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Parameters:
foreignKey- the foreign key- Returns:
- this builder instance
- See Also:
-
children
Description copied from interface:EntityTreeModel.BuilderAdds the entities referencing a node via the given foreign key as its children, see
EntityTreeModel.Builder.children(ForeignKey), configuring the query selecting them. A condition is combined with the foreign key condition, and applies when finding which nodes have children as well.builder.children(Employee.REPORTSTO_FK, children -> children .condition(() -> Employee.EMAIL.isNotNull()) .select(select -> select.referenceDepth(0)));- Specified by:
childrenin interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Parameters:
foreignKey- the foreign keychildren- configures the query selecting the children- Returns:
- this builder instance
- See Also:
-
leaves
Description copied from interface:EntityTreeModel.BuilderReplaces the default leaf detection, which queries for the siblings referenced via the configured foreign keys, a node of an entity type no configured foreign key references always being a leaf.
The 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 interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Specified by:
leavesin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
leaves- the leaves function- Returns:
- this builder instance
- See Also:
-
leaf
Description copied from interface:EntityTreeModel.BuilderReplaces the default leaf detection, see
EntityTreeModel.Builder.leaves(Function), with a function deciding node by node, based on a domain attribute for example.The 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 interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Specified by:
leafin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
leaf- the leaf function- 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.set(NodePath)selecting a node once it is loaded.- Specified by:
pathin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<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:EntityTreeModel.BuilderSpecifies the comparator for the roots, and the children via each foreign key, which specify neither a comparator nor an order by, in place of the comparator of their entity type, null for the query order. Siblings of different entity types are ordered by type, in the order their foreign keys were configured.
Replaces the comparators specified via
EntityTreeModel.Builder.comparators(Function), the last one set winning.- Specified by:
comparatorin interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Specified by:
comparatorin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
comparator- the comparator, null for the query order- Returns:
- this builder instance
- See Also:
-
comparators
Description copied from interface:EntityTreeModel.BuilderReplaces the ordering of siblings entirely, the roots, the foreign key comparators and order bys, and the entity type 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.
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 interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Specified by:
comparatorsin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<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<Entity,B extends EntityTreeModel.Builder<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<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
onLoadException- the exception handler to use during loading- Returns:
- this builder instance
-
refresh
- Specified by:
refreshin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<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<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
listener- the selection listener- Returns:
- this builder instance
-
onSelectedItem
- Specified by:
onSelectedItemin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
item- receives the item of the selected node- Returns:
- this builder instance
- See Also:
-
onSelectedItems
- Specified by:
onSelectedItemsin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
items- receives the items of the selected nodes- Returns:
- this builder instance
- See Also:
-
onSelectedPath
- Specified by:
onSelectedPathin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
path- receives the path of the selected node- Returns:
- this builder instance
- See Also:
-
onSelectedPaths
- Specified by:
onSelectedPathsin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
paths- receives the paths of the selected nodes- Returns:
- this builder instance
- See Also:
-
onSelectedIndex
- Specified by:
onSelectedIndexin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
index- receives the selected index- Returns:
- this builder instance
-
onSelectedIndexes
- Specified by:
onSelectedIndexesin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
indexes- receives the selected indexes- Returns:
- this builder instance
-
build
- Specified by:
buildin interfaceEntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>- Specified by:
buildin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Returns:
- a new
EntityTreeModelinstance
-
self
- Returns:
- this builder instance
-