Class TreeControl

All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, io.clogr.Clogged, Component, CompositeComponent, Control, InputFocusableComponent, ActionListenable, ActionModel, Displayable, Enableable, InfoModel, LabelModel, Model, TreeModel, PresentationModel, DepictedObject

A tree control. Property change events and action events on one tree node will be repeated to this object's listeners, with the tree node initiating the event accessible via TargetedEvent.getTarget().
Author:
Garret Wilson
  • Field Details

    • ROOT_NODE_DISPLAYED_PROPERTY

      public static final String ROOT_NODE_DISPLAYED_PROPERTY
      The bound property of whether the root node is displayed.
    • TREE_NODE_DRAG_ENABLED_PROPERTY

      public static final String TREE_NODE_DRAG_ENABLED_PROPERTY
      The bound property of whether the tree node components have dragging enabled.
  • Constructor Details

    • TreeControl

      public TreeControl()
      Default constructor with a default tree model.
    • TreeControl

      public TreeControl(TreeModel treeModel)
      Tree model constructor.
      Parameters:
      treeModel - The component tree model.
      Throws:
      NullPointerException - if the given tree model is null.
  • Method Details

    • getTreeModel

      protected TreeModel getTreeModel()
      Returns:
      The tree model used by this component.
    • isTreeNodeDragEnabled

      public boolean isTreeNodeDragEnabled()
      Returns:
      Whether the tree node component have dragging enabled.
    • setTreeNodeDragEnabled

      public void setTreeNodeDragEnabled(boolean newTreeNodeDragEnabled)
      Sets whether the tree node components have dragging enabled. This is a bound property of type Boolean.
      Parameters:
      newTreeNodeDragEnabled - true if each tree node component should allow dragging, else false.
      See Also:
    • isRootNodeDisplayed

      public boolean isRootNodeDisplayed()
      Returns:
      Whether the root node is displayed.
      See Also:
    • setRootNodeDisplayed

      public void setRootNodeDisplayed(boolean newRootNodeDisplayed)
      Sets whether the root node is displayed. This is a bound property of type Boolean. If the root is requested not to be displayed, the root is automatically expanded.
      Parameters:
      newRootNodeDisplayed - true if the root node should be displayed, else false.
      See Also:
    • setTreeNodeRepresentationStrategy

      public <V> TreeControl.TreeNodeRepresentationStrategy<? super V> setTreeNodeRepresentationStrategy(Class<V> valueClass, TreeControl.TreeNodeRepresentationStrategy<? super V> treeNodeRepresentationStrategy)
      Installs the given tree node representation strategy to produce representation components for the given value class.
      Type Parameters:
      V - The type of value to represent.
      Parameters:
      valueClass - The class of value with which the strategy should be associated.
      treeNodeRepresentationStrategy - The strategy for generating components to represent values of the given type.
      Returns:
      The representation strategy previously associated with the given value type.
    • getTreeNodeRepresentationStrategy

      public <V> TreeControl.TreeNodeRepresentationStrategy<? super V> getTreeNodeRepresentationStrategy(Class<V> valueClass)
      Returns the given tree node representation strategy assigned to produce representation components for the given value class.
      Type Parameters:
      V - The type of value to represent.
      Parameters:
      valueClass - The class of value with which the strategy should be associated.
      Returns:
      The strategy for generating components to represent values of the given type, or null if there is no associated representation strategy.
      See Also:
    • getComponent

      public Component getComponent(TreeNodeModel<?> treeNode)
      Retrieves the component for the given object. If no component yet exists for the given object, one will be created.

      This version is provided to allow public access.

      Overrides:
      getComponent in class AbstractCompositeStateComponent<TreeNodeModel<?>,TreeControl.TreeNodeComponentState>
      Parameters:
      treeNode - The object for which a representation component should be returned.
      Returns:
      The child component representing the given object.
    • createComponentState

      protected TreeControl.TreeNodeComponentState createComponentState(TreeNodeModel<?> treeNode)
      Creates a component state to represent the given object.

      This implementation delegates to createTypedComponentState(TreeNodeModel).

      Specified by:
      createComponentState in class AbstractCompositeStateComponent<TreeNodeModel<?>,TreeControl.TreeNodeComponentState>
      Parameters:
      treeNode - The object with which the component state is to be associated.
      Returns:
      The component state to represent the given object.
    • getRootNode

      public TreeNodeModel<?> getRootNode()
      Specified by:
      getRootNode in interface TreeModel
      Returns:
      The root node of the tree model.
    • setRootNode

      public void setRootNode(TreeNodeModel<?> newRootNode)
      Sets the root node of the tree model. This is a bound property.

      If the this control requests that the root not be displayed, this implementation automatically expanded the root node after it is added. This is a bound property.

      Specified by:
      setRootNode in interface TreeModel
      Parameters:
      newRootNode - The new root node of the tree model.
      See Also:
    • setAllExpanded

      public void setAllExpanded(boolean newAllExpanded)
      Description copied from interface: TreeModel
      Sets whether all tree nodes are expanded. This method delegates to the root node TreeNodeModel.setAllExpanded(boolean).
      Specified by:
      setAllExpanded in interface TreeModel
      Parameters:
      newAllExpanded - true if all the nodes should be expanded, or false if they should be collapsed.
    • addActionListener

      public void addActionListener(ActionListener actionListener)
      Description copied from interface: ActionListenable
      Adds an action listener.
      Specified by:
      addActionListener in interface ActionListenable
      Parameters:
      actionListener - The action listener to add.
    • removeActionListener

      public void removeActionListener(ActionListener actionListener)
      Description copied from interface: ActionListenable
      Removes an action listener.
      Specified by:
      removeActionListener in interface ActionListenable
      Parameters:
      actionListener - The action listener to remove.
    • getActionListeners

      public Iterable<ActionListener> getActionListeners()
      Specified by:
      getActionListeners in interface ActionModel
      Returns:
      all registered action listeners.
    • performAction

      public void performAction()
      Description copied from interface: ActionModel
      Performs the action with default force and default option. An ActionEvent is fired to all registered ActionListeners. This method delegates to ActionModel.performAction(int, int).
      Specified by:
      performAction in interface ActionModel
    • performAction

      public void performAction(int force, int option)
      Description copied from interface: ActionModel
      Performs the action with the given force and option. An ActionEvent is fired to all registered ActionListeners.
      Specified by:
      performAction in interface ActionModel
      Parameters:
      force - The zero-based force, such as 0 for no force or 1 for an action initiated by from a mouse single click.
      option - The zero-based option, such as 0 for an event initiated by a mouse left button click or 1 for an event initiated by a mouse right button click.
    • fireActionPerformed

      protected void fireActionPerformed(int force, int option)
      Fires an action event to all registered action listeners. This method delegates to fireActionPerformed(ActionEvent).
      Parameters:
      force - The zero-based force, such as 0 for no force or 1 for an action initiated by from a mouse single click.
      option - The zero-based option, such as 0 for an event initiated by a mouse left button click or 1 for an event initiaged by a mouse right button click.
      See Also:
    • fireActionPerformed

      protected void fireActionPerformed(ActionEvent actionEvent)
      Fires a given action event to all registered action listeners.
      Parameters:
      actionEvent - The action event to fire.