Class TreeItemBuilder<T>

java.lang.Object
io.github.sosuisen.jfxbuilder.controls.TreeItemBuilder<T>

public class TreeItemBuilder<T> extends Object
The TreeItemBuilder class constructs instances of the TreeItem class and offers a fluent interface for creating and configuring it.

This class includes a static create method that accepts the same arguments as the original TreeItem constructor and returns an instance of the TreeItemBuilder.

You can use method chaining to call the builder methods for configuring the TreeItem. Finally, invoke the build method to generate an instance of the TreeItem class.

Note that intermediate builder methods are not evaluated until the build method is called, meaning they are evaluated lazily.

Author:
Hidekazu Kubota <hidekazu.kubota@gmail.com>
  • Method Details

    • create

      public static <T> TreeItemBuilder<T> create()
      Returns an instance of the TreeItemBuilder<T>.
      Returns:
      an instance of the TreeItemBuilder<T>.
    • create

      public static <T> TreeItemBuilder<T> create(T value)
      Accepts the constructor arguments of TreeItem(T) and returns an instance of TreeItemBuilder<T>.
      Returns:
      an instance of the TreeItemBuilder<T>.
    • create

      public static <T> TreeItemBuilder<T> create(T value, Node graphic)
      Accepts the constructor arguments of TreeItem(T, Node) and returns an instance of TreeItemBuilder<T>.
      Returns:
      an instance of the TreeItemBuilder<T>.
    • build

      public TreeItem<T> build()
      Builds and returns an instance of the TreeItem class.

      Intermediate builder methods are not evaluated until the build method is called; in other words, they are evaluated lazily.

      Returns:
      new instance of the TreeItem class
    • apply

      public TreeItemBuilder<T> apply(Consumer<TreeItem<T>> func)
      Applies a function to the TreeItem instance being constructed. Most operations on the instance can be performed using this method.
      Returns:
      builder instance
    • expanded

      public TreeItemBuilder<T> expanded(boolean value)
      A builder method that invokes the setExpanded method on the instance being constructed.
      Returns:
      builder instance
    • graphic

      public TreeItemBuilder<T> graphic(Node value)
      A builder method that invokes the setGraphic method on the instance being constructed.
      Returns:
      builder instance
    • value

      public TreeItemBuilder<T> value(T value)
      A builder method that invokes the setValue method on the instance being constructed.
      Returns:
      builder instance
    • addChildren

      @SafeVarargs public final TreeItemBuilder<T> addChildren(TreeItem<T>... elements)
      Calls the addAll method on the ObservableList returned by the TreeItem#getChildren() method.
      Returns:
      builder instance
    • addChildren

      public final TreeItemBuilder<T> addChildren(Collection<? extends TreeItem<T>> col)
      Calls the addAll method on the ObservableList returned by the TreeItem#getChildren() method.
      Returns:
      builder instance
    • withChildren

      @SafeVarargs public static <T> TreeItemBuilder<T> withChildren(TreeItem<T>... elements)
      Creates an instance of the builder, then calls the addAll method on the ObservableList returned by the TreeItem#getChildren() method.
      Returns:
      builder instance
    • withChildren

      public static <T> TreeItemBuilder<T> withChildren(Collection<? extends TreeItem<T>> col)
      Creates an instance of the builder, then calls the addAll method on the ObservableList returned by the TreeItem#getChildren() method.
      Returns:
      builder instance
    • expandedPropertyApply

      public TreeItemBuilder<T> expandedPropertyApply(Consumer<BooleanProperty> op)
      Applies a function to the expandedProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.expandedProperty().bind(anotherProperty))
      
      // Use shorthand form
      .expandedPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • graphicPropertyApply

      public TreeItemBuilder<T> graphicPropertyApply(Consumer<ObjectProperty<Node>> op)
      Applies a function to the graphicProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.graphicProperty().bind(anotherProperty))
      
      // Use shorthand form
      .graphicPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • leafPropertyApply

      public TreeItemBuilder<T> leafPropertyApply(Consumer<ReadOnlyBooleanProperty> op)
      Applies a function to the leafProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.leafProperty().bind(anotherProperty))
      
      // Use shorthand form
      .leafPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • parentPropertyApply

      public TreeItemBuilder<T> parentPropertyApply(Consumer<ReadOnlyObjectProperty<TreeItem<T>>> op)
      Applies a function to the parentProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.parentProperty().bind(anotherProperty))
      
      // Use shorthand form
      .parentPropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance
    • valuePropertyApply

      public TreeItemBuilder<T> valuePropertyApply(Consumer<ObjectProperty<T>> op)
      Applies a function to the valueProperty of the instance being constructed. This serves as a shorthand form of the apply method.

      Example:

      // Use apply
      .apply(obj -> obj.valueProperty().bind(anotherProperty))
      
      // Use shorthand form
      .valuePropertyApply(prop -> prop.bind(anotherProperty))
      
      Returns:
      builder instance