Class LazyObservableList<K,V>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
javafx.collections.ObservableListBase<E>
javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
com.iamsoft.util.ui.javafx.collections.LazyObservableList<K,V>
Type Parameters:
K - Key type.
V - Value type.
All Implemented Interfaces:
Iterable<javafx.concurrent.Task<V>>, Collection<javafx.concurrent.Task<V>>, List<javafx.concurrent.Task<V>>, javafx.beans.Observable, javafx.collections.ObservableList<javafx.concurrent.Task<V>>

public class LazyObservableList<K,V> extends javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
Observable list that fetches values from potentially slow resource. A 'viewport' defines the range of values that should be retrieved. When values exit viewport, they are immediately discarded and associated tasks are canceled. Thus, LazyObservableList typically contains mostly nulls with a narrow band of 'task' objects. Values are expected to be immutable. If change occurs, base ObservableList should simply replace object. To simulate mutation, use a decorator on top of LazyObservableList.
See Also:
  • Property Details

    • viewportChange

      public final javafx.beans.property.ReadOnlyBooleanProperty viewportChangeProperty
      See Also:
  • Constructor Details

    • LazyObservableList

      public LazyObservableList(javafx.collections.ObservableList<K> pKeys, javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>> pViewportRange, Function<com.google.common.collect.Range<Integer>,Map<K,javafx.concurrent.Task<V>>> pFetchFunction, Consumer<K> pUnsubscribeFunction)
      Parameters:
      pKeys - List of unique item identifiers.
      pViewportRange - Range (offset to length) within which data should be fetched and actively monitored. Range is allowed to extend beyond key list size.
      pFetchFunction - Function for retrieving actively-monitored remote data. Function is responsible for starting tasks. Where possible, it is encouraged to request all data with a single 'parent' request upon which child tasks depend. In this case, canceling all child tasks should cancel parent.
      pUnsubscribeFunction - Function to cease active monitoring of a value.
  • Method Details

    • viewportChangeProperty

      public final javafx.beans.property.ReadOnlyBooleanProperty viewportChangeProperty()
      See Also:
    • isViewportChange

      public final boolean isViewportChange()
      Can be used to determine whether a list change occurs due to viewport change.
    • get

      public javafx.concurrent.Task<V> get(int pIdx)
      Specified by:
      get in interface List<K>
      Specified by:
      get in class AbstractList<javafx.concurrent.Task<V>>
    • size

      public int size()
      Specified by:
      size in interface Collection<K>
      Specified by:
      size in interface List<K>
      Specified by:
      size in class AbstractCollection<javafx.concurrent.Task<V>>
    • refresh

      public void refresh()
      Clears old values and re-fetches viewport values.
    • runLater

      protected void runLater(Runnable pRunnable)
    • sourceChanged

      protected void sourceChanged(javafx.collections.ListChangeListener.Change<? extends K> pChg)
      Specified by:
      sourceChanged in class javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
    • getSourceIndex

      public int getSourceIndex(int pIdx)
      Specified by:
      getSourceIndex in class javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
    • getViewIndex

      public int getViewIndex(int pIdx)
      Specified by:
      getViewIndex in class javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
    • getFrom

      public static int getFrom(com.google.common.collect.Range<Integer> pRange)
      Get lower endpoint (inclusive).
    • getTo

      public static int getTo(com.google.common.collect.Range<Integer> pRange)
      Get upper endpoint (exclusive).