Class 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:
    ViewportRange
    • Constructor Detail

      • 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 Detail

      • viewportChangeProperty

        public final javafx.beans.property.ReadOnlyBooleanProperty viewportChangeProperty()
      • 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>>
      • 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).