Class AggregatedListBinding<T,S,R>

java.lang.Object
javafx.beans.binding.ObjectExpression<R>
javafx.beans.binding.ObjectBinding<R>
com.dlsc.gemsfx.binding.AggregatedListBinding<T,S,R>
Type Parameters:
T - the type of the elements in the source list
S - the type of the elements in the nested lists
R - the type of the result computed from the stream of elements in the nested lists
All Implemented Interfaces:
javafx.beans.binding.Binding<R>, javafx.beans.Observable, javafx.beans.value.ObservableObjectValue<R>, javafx.beans.value.ObservableValue<R>

public class AggregatedListBinding<T,S,R> extends javafx.beans.binding.ObjectBinding<R>
Binds an ObservableList of items to a computed value based on the elements of their associated nested ObservableLists. This binding listens for changes not only in the top-level list but also in the nested lists of each item. It aggregates or computes values dynamically as the lists change, making it ideal for applications where the data model is highly dynamic.

This class is designed to be used with a consistent source of ObservableLists provided by the itemToListFunction. The function must return the same ObservableList instance for any given item throughout its lifecycle to ensure correct behavior and prevent memory leaks.

Important Considerations:

  • Stable List References: The itemToListFunction should not return different instances of ObservableList over time for the same item. If the lists are stored in properties such as ObjectProperty or SimpleListProperty, ensure that these properties are not reassigned new lists during the lifecycle of an item, as this can lead to erratic behavior and potential memory leaks if listeners are not removed from old lists.
  • Managing Listeners: If using properties to store the lists, manage listeners carefully. Ensure that any list set on a property has listeners appropriately added or removed to prevent memory leaks. This may require overriding property setters or using property change listeners to add/remove list listeners when the property's value changes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AggregatedListBinding(javafx.collections.ObservableList<T> source, Function<T, javafx.collections.ObservableList<S>> itemToListFunction, Function<Stream<S>, R> aggregationFunction)
    Constructs a new AggregatedListBinding.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected R
     
    void
     

    Methods inherited from class javafx.beans.binding.ObjectBinding

    addListener, addListener, allowValidation, bind, get, getDependencies, invalidate, isObserved, isValid, onInvalidating, removeListener, removeListener, toString, unbind

    Methods inherited from class javafx.beans.binding.ObjectExpression

    asString, asString, asString, getValue, isEqualTo, isEqualTo, isNotEqualTo, isNotEqualTo, isNotNull, isNull, objectExpression

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.beans.Observable

    subscribe

    Methods inherited from interface javafx.beans.value.ObservableValue

    flatMap, getValue, map, orElse, subscribe, subscribe, when
  • Constructor Details

    • AggregatedListBinding

      public AggregatedListBinding(javafx.collections.ObservableList<T> source, Function<T, javafx.collections.ObservableList<S>> itemToListFunction, Function<Stream<S>, R> aggregationFunction)
      Constructs a new AggregatedListBinding.
      Parameters:
      source - the observable list of source items that should be stable (not dynamically replaced).
      itemToListFunction - a function to retrieve an observable list from each source item, which must consistently return the same observable list instance for any given item throughout its lifecycle.
      aggregationFunction - a function to compute a result from all elements in the nested lists, based on current data in those lists.
  • Method Details

    • computeValue

      protected R computeValue()
      Specified by:
      computeValue in class javafx.beans.binding.ObjectBinding<R>
    • dispose

      public void dispose()
      Specified by:
      dispose in interface javafx.beans.binding.Binding<T>
      Overrides:
      dispose in class javafx.beans.binding.ObjectBinding<R>