Record Class TreeDrop<V,N extends AbstractTreeNode<V,N>>

java.lang.Object
java.lang.Record
com.amalgamasimulation.desktop.ui.tables.TreeDrop<V,N>
Type Parameters:
V - the type of the row values
N - the type of the node
Record Components:
node - the dragged node
target - the row under the cursor
location - the place relative to target

public record TreeDrop<V,N extends AbstractTreeNode<V,N>>(N extends AbstractTreeNode<V,N> node, N extends AbstractTreeNode<V,N> target, TreeDrop.Location location) extends Record
A move of one ObjectTree node with the mouse: which node was dragged, onto which row, and to which place. The tree creates a TreeDrop when dragAndDrop(action) is set for it in Trees.objects(roots) or Pages.objectTree(type).

The same TreeDrop goes to two receivers. While the user moves the node over the rows, the rules of TreeDragAndDrop get it (withinParent(), sameLevel(), forbid(), rule()). If at least one rule returns false, the node cannot be dropped at this place. When the user releases the node, the action given to dragAndDrop() gets the TreeDrop. The action must move the object in the model. After the action the tree itself moves the row of the node with all its children, so a refresh of the tree is not needed.

Drop place

Location sets the place relative to the target row:
  • ON: the node becomes the last child of target.
  • BEFORE: the node goes before target, under the same parent.
  • AFTER: the node goes after target, under the same parent.
newParent() returns the new parent of the node: target for ON, the parent of target for BEFORE and AFTER. For a root it is null.

The level of a node is the number of its ancestors: 0 for a root, 1 for its children. fromLevel() returns the level of the node before the drop, and toLevel() returns the level after it. The rules forbid(fromLevel, toLevel), withinParent(level) and sameLevel(level) check these levels.

Drops that do not arrive

Only one node can be dragged, and only inside the same tree. Group nodes (isGroup()) cannot be dragged and are never the target. The tree forbids a drop of a node onto itself or onto its descendants before the rules are checked. So the rules and the action never get such a TreeDrop.
Author:
Ionov Ivan
  • Constructor Details

    • TreeDrop

      public TreeDrop(N node, N target, TreeDrop.Location location)
      Creates an instance of a TreeDrop record class.
      Parameters:
      node - the value for the node record component
      target - the value for the target record component
      location - the value for the location record component
  • Method Details

    • newParent

      public N newParent()
      Returns:
      the new parent of the node: target for ON, the parent of target for BEFORE and AFTER, or null if the node becomes a root
    • fromLevel

      public int fromLevel()
      Returns:
      the level of the node before the drop, 0 for a root
    • toLevel

      public int toLevel()
      Returns:
      the level of the node after the drop, 0 for a root
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • node

      public N node()
      Returns the value of the node record component.
      Returns:
      the value of the node record component
    • target

      public N target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • location

      public TreeDrop.Location location()
      Returns the value of the location record component.
      Returns:
      the value of the location record component