Class AbstractChangeTracker<T extends javafx.beans.Observable>

java.lang.Object
com.dlsc.gemsfx.binding.AbstractChangeTracker<T>
Type Parameters:
T - the type of Observable elements in the list that is being tracked
Direct Known Subclasses:
NestedListChangeTracker

public abstract class AbstractChangeTracker<T extends javafx.beans.Observable> extends Object
This abstract class provides a framework for tracking changes in an ObservableList of Observable elements. It encapsulates common logic for adding and removing change listeners to the observable elements within the list and provides a mechanism to notify changes through a specified Consumer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Consumer<javafx.collections.ObservableList<T>>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractChangeTracker(javafx.collections.ObservableList<T> source)
    Constructs an AbstractChangeTracker with the provided source list.
    AbstractChangeTracker(javafx.collections.ObservableList<T> source, Consumer<javafx.collections.ObservableList<T>> onChanged)
    Constructs an AbstractChangeTracker with the provided source list and change handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disposes this tracker by removing all listeners from the source and nested lists.
    protected void
    Initializes the listener for the outer list.
    protected void
     
    protected abstract void
     
    protected abstract void
     
    void
    setOnChanged(Consumer<javafx.collections.ObservableList<T>> onChanged)
    Sets the consumer that will be notified when changes occur.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • onChanged

      protected Consumer<javafx.collections.ObservableList<T extends javafx.beans.Observable>> onChanged
  • Constructor Details

    • AbstractChangeTracker

      public AbstractChangeTracker(javafx.collections.ObservableList<T> source)
      Constructs an AbstractChangeTracker with the provided source list.
      Parameters:
      source - the observable list of elements that is being monitored
    • AbstractChangeTracker

      public AbstractChangeTracker(javafx.collections.ObservableList<T> source, Consumer<javafx.collections.ObservableList<T>> onChanged)
      Constructs an AbstractChangeTracker with the provided source list and change handler.
      Parameters:
      source - the observable list of elements that is being monitored
      onChanged - the consumer to handle change notifications
  • Method Details

    • initOuterListener

      protected void initOuterListener()
      Initializes the listener for the outer list. This method should be called after subclass constructors have fully initialized any necessary fields to ensure that listeners interact with a fully initialized object.
    • setOnChanged

      public void setOnChanged(Consumer<javafx.collections.ObservableList<T>> onChanged)
      Sets the consumer that will be notified when changes occur.
      Parameters:
      onChanged - the consumer to be notified of changes
    • notifyChange

      protected void notifyChange()
    • safeAddListener

      protected abstract void safeAddListener(T value)
    • safeRemoveListener

      protected abstract void safeRemoveListener(T value)
    • dispose

      public void dispose()
      Disposes this tracker by removing all listeners from the source and nested lists. It is recommended to call this method when the tracker is no longer needed. Doing so helps ensure that resources are properly released and helps prevent potential memory leaks. Calling this method is particularly important in environments with limited resources or in applications that create and dispose many trackers over their lifetime.