Interface EntityTreeModel.Builder<B extends EntityTreeModel.Builder<B>>
- Type Parameters:
B- the builder type
- All Superinterfaces:
FilterTreeModel.Builder<Entity,B>
- All Known Subinterfaces:
SwingEntityTreeModel.Builder
- All Known Implementing Classes:
AbstractEntityTreeModelBuilder
- Enclosing interface:
EntityTreeModel
EntityTreeModel.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceConfigures the children via a foreign key: their condition, combined with the foreign key condition owned by the tree, theEntityConnection.Selectthey are selected with and their comparator.static interfaceProvides aEntityTreeModel.Builderstatic interfaceConfigures the roots: their condition, theEntityConnection.Selectthey are selected with and their comparator.static interfaceProvides aEntityTreeModel.Builder.ConnectionStepNested classes/interfaces inherited from interface is.codion.common.model.component.tree.FilterTreeModel.Builder
FilterTreeModel.Builder.ChildrenStep<T> -
Method Summary
Modifier and TypeMethodDescriptionbuild()children(ForeignKey foreignKey) Adds the entities referencing a node via the given foreign key as its children, for the nodes of the referenced entity type.children(ForeignKey foreignKey, Consumer<EntityTreeModel.Builder.Children> children) Adds the entities referencing a node via the given foreign key as its children, seechildren(ForeignKey), configuring the query selecting them.comparator(@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.comparators(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.Replaces the default leaf detection, seeleaves(Function), with a function deciding node by node, based on a domain attribute for example.Replaces 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.Methods inherited from interface is.codion.common.model.component.tree.FilterTreeModel.Builder
included, onLoadException, onSelectedIndex, onSelectedIndexes, onSelectedItem, onSelectedItems, onSelectedPath, onSelectedPaths, onSelectionChanged, path, refresh
-
Method Details
-
children
Adds 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.- Parameters:
foreignKey- the foreign key- Returns:
- this builder instance
- Throws:
IllegalArgumentException- in case the foreign key has already been added, or another foreign key of the same entity type referencing the same entity type, since an entity would then appear twice below a node- See Also:
-
children
Adds the entities referencing a node via the given foreign key as its children, see
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)));- Parameters:
foreignKey- the foreign keychildren- configures the query selecting the children- Returns:
- this builder instance
- Throws:
IllegalArgumentException- in case the foreign key has already been added, or another foreign key of the same entity type referencing the same entity type- See Also:
-
leaves
Replaces 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 interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
leaves- the leaves function- Returns:
- this builder instance
- See Also:
-
leaf
Replaces the default leaf detection, see
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 interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Parameters:
leaf- the leaf function- Returns:
- this builder instance
- See Also:
-
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. Siblings of different entity types are ordered by type, in the order their foreign keys were configured.
Replaces the comparators specified via
comparators(Function), the last one set winning.- 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
Replaces 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 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:
-
build
EntityTreeModel build()- Specified by:
buildin interfaceFilterTreeModel.Builder<Entity,B extends EntityTreeModel.Builder<B>> - Returns:
- a new
EntityTreeModelinstance - Throws:
IllegalArgumentException- in case a foreign key references an entity type which is neither the root type nor the type of another foreign key, so it can never apply
-