Class TreeDragAndDrop<V,N extends AbstractTreeNode<V,N>,R>
java.lang.Object
com.amalgamasimulation.desktop.ui.tables.TreeDragAndDrop<V,N,R>
- Type Parameters:
V- the type of the row valuesN- the type of the nodeR- the type of the builder that end() returns
Settings for moving the nodes of an ObjectTree with the mouse: the action that moves the object
in the model, and the rules that tell where the node can be dropped. dragAndDrop(action) in
Trees.objects(roots) or Pages.objectTree(type) creates this object. The rules are added in a
chain, and end() returns the tree builder.
Relation to TreeDrop. The tree describes each possible move with a TreeDrop: which node, onto which row, and to which place. TreeDragAndDrop decides what to do with this TreeDrop:
- While the user moves the node over the rows, the tree creates a TreeDrop for the row under the cursor and asks TreeDragAndDrop whether the node can be dropped there.
- TreeDragAndDrop forbids a drop of a group, a drop onto a group, and a drop of a node onto itself or onto its descendants. Then it checks all rules. The drop is allowed only if all rules return true.
- When the user releases the node at an allowed place, TreeDragAndDrop calls the action with this TreeDrop. The action moves the object in the model.
- After the action the tree itself moves the row of the node with all its children.
Rules
Without rules, the node can be dropped at any place except the places in step 2. Ready rules: withinParent() keeps the node under its parent, sameLevel() keeps the node on its level, and forbid(fromLevel, toLevel) forbids a move from one level to another. rule(predicate) sets your own condition. The variants with the level parameter apply only to the nodes of this level and let the other nodes pass. The level of a node is the number of its ancestors, 0 for a root (see TreeDrop).- Author:
- Ionov Ivan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionend()forbid(int fromLevel, int toLevel) Forbids a move of a node from level fromLevel to level toLevel.Adds your own rule.Allows a drop only if the level of the node does not change.sameLevel(int level) Same as sameLevel(), but only for the nodes of the given level.Allows a drop only if the node keeps the same parent.withinParent(int level) Same as withinParent(), but only for the nodes of the given level.
-
Constructor Details
-
TreeDragAndDrop
Creates the settings for the builder owner with the action. Usually dragAndDrop(action) of the tree builder creates them.- Parameters:
owner- the builder that end() returnsaction- the action that moves the object in the model
-
-
Method Details
-
withinParent
Allows a drop only if the node keeps the same parent. So only the order of the children can change.- Returns:
- this object
-
withinParent
Same as withinParent(), but only for the nodes of the given level.- Parameters:
level- the level of the nodes that the rule applies to- Returns:
- this object
-
sameLevel
Allows a drop only if the level of the node does not change. The parent can change.- Returns:
- this object
-
sameLevel
Same as sameLevel(), but only for the nodes of the given level.- Parameters:
level- the level of the nodes that the rule applies to- Returns:
- this object
-
forbid
Forbids a move of a node from level fromLevel to level toLevel.- Parameters:
fromLevel- the level of the node before the droptoLevel- the level of the node after the drop- Returns:
- this object
-
rule
Adds your own rule. The drop is allowed only if the rule returns true.- Parameters:
rule- the rule that gets the TreeDrop- Returns:
- this object
-
end
- Returns:
- the tree builder, to continue the chain
-