Class CellFactory<T,C extends VFXCell<T>>

java.lang.Object
io.github.palexdev.virtualizedfx.properties.CellFactory<T,C>
All Implemented Interfaces:
javafx.beans.Observable, javafx.beans.property.Property<Function<T,C>>, javafx.beans.property.ReadOnlyProperty<Function<T,C>>, javafx.beans.value.ObservableValue<Function<T,C>>, javafx.beans.value.WritableValue<Function<T,C>>

public class CellFactory<T,C extends VFXCell<T>> extends Object implements javafx.beans.property.Property<Function<T,C>>
A wrapper for cell creation functions used by virtualized containers.

Encapsulates a cell generation function (create(Object)) along with a reference to the associated VFXContainer, allowing each created cell to access the container instance upon creation. In other words, this wrapper is an easy way to provide all cells the container they belong to without radical API changes.

Basically provides a hook that invokes VFXCell.onCreated(VFXContainer) on each newly generated cell, passing the container instance to the cell. This is particularly useful when cells need contextual information from the container, such as configuration, state, selection handling.

Note 1: nothing prevents you from creating cells using the function directly, however, keep in mind that to automatically make use of the new VFXCell.onCreated(VFXContainer) hook, you must use create(Object) instead.

Note 2: for convenience this extends Property and delegates the implemented methods to the wrapped cell factory property.
  • Constructor Details

  • Method Details

    • create

      public C create(T item)
      Creates a new cell for the given item, using the current cell factory function.

      If the factory function is set, it generates a cell, calls VFXCell.onCreated(VFXContainer) on it, and then returns it. Returns null if no factory function is defined.

    • onInvalidated

      protected void onInvalidated(Function<T,C> newFactory)
      Hook method called when the cell factory function is invalidated. Subclasses may override this method to handle changes to the factory function.
    • bind

      public void bind(javafx.beans.value.ObservableValue<? extends Function<T,C>> observable)
      Specified by:
      bind in interface javafx.beans.property.Property<T>
    • unbind

      public void unbind()
      Specified by:
      unbind in interface javafx.beans.property.Property<T>
    • isBound

      public boolean isBound()
      Specified by:
      isBound in interface javafx.beans.property.Property<T>
    • bindBidirectional

      public void bindBidirectional(javafx.beans.property.Property<Function<T,C>> other)
      Specified by:
      bindBidirectional in interface javafx.beans.property.Property<T>
    • unbindBidirectional

      public void unbindBidirectional(javafx.beans.property.Property<Function<T,C>> other)
      Specified by:
      unbindBidirectional in interface javafx.beans.property.Property<T>
    • getBean

      public Object getBean()
      Specified by:
      getBean in interface javafx.beans.property.ReadOnlyProperty<T>
    • getName

      public String getName()
      Specified by:
      getName in interface javafx.beans.property.ReadOnlyProperty<T>
    • addListener

      public void addListener(javafx.beans.value.ChangeListener<? super Function<T,C>> listener)
      Specified by:
      addListener in interface javafx.beans.value.ObservableValue<T>
    • removeListener

      public void removeListener(javafx.beans.value.ChangeListener<? super Function<T,C>> listener)
      Specified by:
      removeListener in interface javafx.beans.value.ObservableValue<T>
    • getValue

      public Function<T,C> getValue()
      Specified by:
      getValue in interface javafx.beans.value.ObservableValue<T>
      Specified by:
      getValue in interface javafx.beans.value.WritableValue<T>
    • addListener

      public void addListener(javafx.beans.InvalidationListener listener)
      Specified by:
      addListener in interface javafx.beans.Observable
    • removeListener

      public void removeListener(javafx.beans.InvalidationListener listener)
      Specified by:
      removeListener in interface javafx.beans.Observable
    • setValue

      public void setValue(Function<T,C> value)
      Specified by:
      setValue in interface javafx.beans.value.WritableValue<T>
    • getOwner

      public VFXContainer<T> getOwner()
      Returns:
      the container that owns this cell factory and inherently the cells created by it.
    • canCreate

      public boolean canCreate()
      Convenience method to check whether the cell generating function is not null.