Package swingtree
Class TreeNodeConf<N,B extends N>
java.lang.Object
swingtree.TreeNodeConf<N,B>
- Type Parameters:
N- The common node type of the tree this rule belongs to.B- The concrete node type this rule applies to.
Describes how the nodes of one particular type behave inside a
JTree built through UIFactoryMethods.tree(sprouts.Var, swingtree.api.Configurator).
You never create one of these yourself, instead you receive it inside the
Configurator lambda passed to
TreeConf.nodesOf(Class, swingtree.api.Configurator):
UI.tree(fileSystem, conf -> conf
.nodesOf(Dir.class, dir -> dir
.children(Dir::entries, Dir::withEntries)
.text(Dir::name, Dir::withName)
.icon(dir -> Icons.FOLDER)
)
.nodesOf(Doc.class, doc -> doc
.text(Doc::name)
)
);
A configuration block like this is the tree's equivalent of one case in a
switch over a sealed type, which is why a sum type based tree usually has
exactly one nodesOf(..) block per permitted subtype.
A getter alone is read only, a getter together with a wither is a lens and
therefore two way. This is the same rule the Var.zoomTo(Function, BiFunction)
method follows, and it applies to every aspect declared here: children(Function)
makes a branch the user cannot restructure, children(Function, BiFunction) makes
one they can, text(Function) renders a label and text(Function, BiFunction)
additionally permits renaming the node in place.
Instances of this class are immutable values, so every method returns a new instance instead of modifying the receiver.
-
Method Summary
Modifier and TypeMethodDescription<C extends N>
TreeNodeConf<N, B> Declares that nodes of this type are branches whose children are read from the supplied getter, and that the user may not restructure them.<C extends N>
TreeNodeConf<N, B> Declares that nodes of this type are branches whose children are read from the supplied getter and written back through the supplied wither, which makes the branch structure editable and gives every node below it a writable lens reaching all the way up into the root property.<C extends N>
TreeNodeConf<N, B> Declares the children of this node type through aLens, which is equivalent tochildren(Function, BiFunction)but lets you reuse a lens you already have, or write one whose focus needs logic of its own.icon(Function<B, IconDeclaration> getter) Declares the icon shown next to nodes of this type.isLeaf(boolean isLeaf) Overrides whether nodes of this type are leaves.Declares the label shown for nodes of this type.Declares the label shown for nodes of this type together with a wither, which additionally permits the user to rename the node in place.Declares the tool tip shown when the pointer rests on a node of this type.toString()
-
Method Details
-
children
Declares that nodes of this type are branches whose children are read from the supplied getter, and that the user may not restructure them.
Declaring a children rule is also what turns a node type into a branch: a type without one is a leaf, and a branch stays a branch even while it happens to have no children (see.nodesOf(Dir.class, dir -> dir.children(Dir::entries))TreeConf.leafWhenEmpty(boolean)).- Type Parameters:
C- The type of the children, which must be assignable to the tree's node type.- Parameters:
getter- Reads the children of a node of this type.- Returns:
- An updated configuration.
-
children
public <C extends N> TreeNodeConf<N,B> children(Function<B, sprouts.Tuple<C>> getter, BiFunction<B, sprouts.Tuple<C>, B> wither) Declares that nodes of this type are branches whose children are read from the supplied getter and written back through the supplied wither, which makes the branch structure editable and gives every node below it a writable lens reaching all the way up into the root property..nodesOf(Dir.class, dir -> dir.children(Dir::entries, Dir::withEntries))- Type Parameters:
C- The type of the children, which must be assignable to the tree's node type.- Parameters:
getter- Reads the children of a node of this type.wither- Returns a new node of this type with the given children.- Returns:
- An updated configuration.
-
children
Declares the children of this node type through aLens, which is equivalent tochildren(Function, BiFunction)but lets you reuse a lens you already have, or write one whose focus needs logic of its own.- Type Parameters:
C- The type of the children, which must be assignable to the tree's node type.- Parameters:
lens- Focuses the children collection of a node of this type.- Returns:
- An updated configuration.
-
text
Declares the label shown for nodes of this type. Without a text rule the tree falls back toObject.toString(), which is rarely what a record should show.- Parameters:
getter- Produces the label of a node of this type.- Returns:
- An updated configuration.
-
text
Declares the label shown for nodes of this type together with a wither, which additionally permits the user to rename the node in place. The edited text is handed to the wither and the resulting node is written back into the root property.
Renaming additionally requires the tree to be bound to a mutable.nodesOf(Dir.class, dir -> dir.text(Dir::name, Dir::withName))Varand every branch above the node to declare a children wither, because that is the chain the new value has to travel back up.- Parameters:
getter- Produces the label of a node of this type.wither- Returns a new node of this type carrying the edited label.- Returns:
- An updated configuration.
-
icon
Declares the icon shown next to nodes of this type. The returnedIconDeclarationis resolved through the regular SwingTree icon cache, so SVG sources and HiDPI scaling work exactly as they do everywhere else.- Parameters:
getter- Produces the icon declaration of a node of this type.- Returns:
- An updated configuration.
-
toolTip
Declares the tool tip shown when the pointer rests on a node of this type.- Parameters:
getter- Produces the tool tip text of a node of this type.- Returns:
- An updated configuration.
-
isLeaf
Overrides whether nodes of this type are leaves. By default a node type is a leaf exactly when it declares nochildren(..)rule, which is the answer a sum type based model wants. Override it when a node has no children yet but must still show a handle, because expanding it is what triggers the load:.nodesOf(Pending.class, p -> p.text(Pending::label).isLeaf(false))- Parameters:
isLeaf- True to force nodes of this type to be leaves, false to force them to be branches.- Returns:
- An updated configuration.
-
toString
-