Class TreeSelectionDelegate<I,N>
- Type Parameters:
I- The identity type of the nodes, which selection paths are made of.N- The common node type of the tree.
JTree has to say, handed to the
Action registered through
UIForTree.onSelection(sprouts.Action).
It speaks entirely in the user's own node values. The handles a bound tree keeps inside
its TreePaths are an internal matter and never surface here, which is also why
JTree.getLastSelectedPathComponent() is not a useful thing to call on a bound tree.
Note that for the common case of mirroring the selection into a view model there is no
need for this delegate at all: bind a property with
UIForTree.withSelection(Var) instead and the two stay in sync by themselves.
-
Method Summary
Modifier and TypeMethodDescriptionlead()The node the user just moved the selection onto, which is empty when the selection was cleared rather than moved.sprouts.Tuple<I> leadPath()The identity of the selected position: the ids leading from the top of the tree down to thelead()node, the root's own id first — or, in a forest, the id of the top level node it sits under.sprouts.Tuple<N> The chain of nodes from the top of the tree down to (and including) thelead()node, which is how you learn where in the structure the selection landed.property()A writable property focused on the selected node, so that an action reacting to a selection can go straight on to edit what was selected, and the edit lands in the one property the tree is bound to.sprouts.Tuple<N> Every currently selected node, in the order the tree reports them.sprouts.Tuple<sprouts.Tuple<I>> The identity of every selected position, in the order the tree reports them.toString()tree()The tree whose selection changed, in case you need to reach past this delegate.
-
Method Details
-
tree
The tree whose selection changed, in case you need to reach past this delegate.- Returns:
- The
JTreethis selection belongs to.
-
lead
The node the user just moved the selection onto, which is empty when the selection was cleared rather than moved.- Returns:
- The node the selection now leads with.
-
selection
Every currently selected node, in the order the tree reports them. For a single selection tree this holds at most one node, and it is empty when nothing is selected.- Returns:
- All selected nodes.
-
pathToLead
The chain of nodes from the top of the tree down to (and including) thelead()node, which is how you learn where in the structure the selection landed. It is empty when the selection was cleared. A forest has no root, so its trails begin at the top level node the selection sits under.- Returns:
- The nodes leading from the top of the tree to the selected node.
-
leadPath
The identity of the selected position: the ids leading from the top of the tree down to thelead()node, the root's own id first — or, in a forest, the id of the top level node it sits under. This is the same value a property bound withUIForTree.withSelection(sprouts.Var)receives, and it is empty when the selection was cleared rather than moved.Where
pathToLead()answers "what is selected", this answers "which position is selected" — the question a node value cannot answer on its own, because the same value may sit in several places at once.- Returns:
- The ids leading to the selected node.
-
selectionPaths
The identity of every selected position, in the order the tree reports them. This is what a property bound withUIForTree.withSelectionPaths(sprouts.Var)receives.- Returns:
- One path of ids per selected node.
-
property
A writable property focused on the selected node, so that an action reacting to a selection can go straight on to edit what was selected, and the edit lands in the one property the tree is bound to.It is empty when nothing is selected, or when the tree was bound to a read only
Val, in which case there is nothing to write into.- Returns:
- A lens property onto the selected node.
-
toString
-