Class DynamicTreeNodeModel<V>

Type Parameters:
V - The type of value contained in the tree node.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, com.globalmentor.model.MutableValued<V>, com.globalmentor.model.Valued<V>, ActionListenable, ActionModel, Model, Selectable, TreeNodeModel<V>, ValueModel<V>, Iterable<TreeNodeModel<?>>

public abstract class DynamicTreeNodeModel<V> extends DefaultTreeNodeModel<V>
A node in a tree model that can dynamically load its children when needed.

Child classes must override determineLeaf() and determineChildren().

Property change events on one tree node will be bubbled up the hierarchy, with the source indicating the tree node on which the property change occurred.

Author:
Garret Wilson
  • Constructor Details

    • DynamicTreeNodeModel

      public DynamicTreeNodeModel(Class<V> valueClass)
      Constructs a tree node model indicating the type of value it can hold.
      Parameters:
      valueClass - The class indicating the type of value held in the model.
      Throws:
      NullPointerException - if the given value class is null.
    • DynamicTreeNodeModel

      public DynamicTreeNodeModel(Class<V> valueClass, V initialValue)
      Constructs a tree node model indicating the type of value it can hold, along with an initial value.
      Parameters:
      valueClass - The class indicating the type of value held in the model.
      initialValue - The initial value, which will not be validated.
      Throws:
      NullPointerException - if the given value class is null.
  • Method Details

    • isLeaf

      public boolean isLeaf()
      Determines whether this node could be considered a leaf node. This method may return false even if it currently has no children, if it intends to load them later and there is no way to know ahead of time if there will be children.

      This implementation true if child nodes are not loaded and this is not a predictive dynamic tree node.

      TODO comment
      Specified by:
      isLeaf in interface TreeNodeModel<V>
      Overrides:
      isLeaf in class DefaultTreeNodeModel<V>
      Returns:
      true if this is a leaf node, else false if this node should not be considered a leaf.
    • setExpanded

      public void setExpanded(boolean newExpanded)
      Description copied from interface: TreeNodeModel
      Sets whether the node is expanded, showing its children, if any. This is a bound property of type Boolean.
      Specified by:
      setExpanded in interface TreeNodeModel<V>
      Overrides:
      setExpanded in class DefaultTreeNodeModel<V>
      Parameters:
      newExpanded - true if the node is expanded.
      See Also:
    • clear

      public void clear()
      Removes all of the child tree nodes from this tree node.

      This version resets the children determined status.

      Specified by:
      clear in interface TreeNodeModel<V>
      Overrides:
      clear in class DefaultTreeNodeModel<V>
    • determineLeaf

      protected abstract boolean determineLeaf()
      Dynamically determines whether this node is a leaf.
      Returns:
      Whether this node should be considered a leaf with no children.
    • determineChildren

      protected abstract List<TreeNodeModel<?>> determineChildren()
      Dynamically determines children.
      Returns:
      The dynamically loaded list of children.