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

java.lang.Object
com.amalgamasimulation.desktop.ui.tables.AbstractTreeNode<V,N>
Type Parameters:
V - the type of the row values
N - the type of the node, the subclass itself
Direct Known Subclasses:
TreeNode

public abstract class AbstractTreeNode<V,N extends AbstractTreeNode<V,N>> extends Object
A node of ObjectTree: one row of the tree that shows a value of type V. The node keeps the value and the parent node. Usually the tree uses the ready TreeNode, which Trees.objects(roots) creates.

Groups

If a node has more than 1000 children, the tree does not show them directly under the node. It shows them in group nodes of 1000 children each. For a group, isGroup() returns true, getValue() returns null and getGroupLabel() returns the numbers of the children, for example 1001–2000. getChildren() of a group returns its part of the children of the parent. getParent() of a child in a group returns the real parent node, not the group. So a column function must check for a group: node.isGroup() ? node.getGroupLabel() : node.getValue().getName(). The tree uses groups because SWT inserts and expands rows quickly up to about 1000 children of one parent, and after that it slows down linearly.

Own subclass

Write a subclass if a row needs its own data in addition to the value, for example data that depends on the path from the root. Give the subclass as a node factory to Trees.objects(roots, nodeFactory) or to Pages.objectTree(type, nodeFactory). The factory also creates the groups, so it must accept the value null.
Author:
Ionov Ivan
  • Constructor Details

    • AbstractTreeNode

      protected AbstractTreeNode(V value, N parent)
      Creates a node. ObjectTree creates the nodes through the node factory.
      Parameters:
      value - the value of the row, null for a group
      parent - the parent node, null for a root
  • Method Details

    • getValue

      public final V getValue()
      Returns:
      the value of the row, null for a group
    • getParent

      public final N getParent()
      Returns:
      the parent node, or null for a root. A group is never a parent.
    • getChildren

      public final List<N> getChildren()
      Returns the children of the node without the groups. If the tree has not read the children yet, it reads them with the children rule. If the node is not in a tree, returns an empty list.
      Returns:
      the unmodifiable list of the children, or for a group its part of the children of the parent
    • isGroup

      public final boolean isGroup()
      Returns:
      true if the node is a group (see the Groups section of the class comment)
    • getGroupLabel

      public final String getGroupLabel()
      Returns:
      the numbers of the children of the group, for example 1–1000, or null if the node is not a group
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object