Class SimpleLazyObservableList<T>

  • Type Parameters:
    T - List element type.
    All Implemented Interfaces:
    Iterable<T>, Collection<T>, List<T>, javafx.beans.Observable, javafx.collections.ObservableList<T>

    public class SimpleLazyObservableList<T>
    extends javafx.collections.transformation.TransformationList<T,​javafx.concurrent.Task<Map.Entry<Integer,​List<T>>>>
    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. This lazy ObservableList implementation is suitable for cases, where viewport sublist is fetched within single task. For example, when fetching data from database.
    See Also:
    ViewportRange
    • Constructor Detail

      • SimpleLazyObservableList

        public SimpleLazyObservableList​(javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>> pViewportRange,
                                        Function<com.google.common.collect.Range<Integer>,​javafx.concurrent.Task<Map.Entry<Integer,​List<T>>>> pFetchFunction)
        Parameters:
        pViewportRange - Range (offset to length) within which data should be fetched and actively monitored.
        pFetchFunction - Function for retrieving actively-monitored remote data. Function is responsible for starting task. The result of the task is a pair of range offset and list of elements for the specified range.
    • Method Detail

      • getViewportRange

        public javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>> getViewportRange()
      • 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.
      • elementLoadingEventProperty

        public final javafx.beans.property.ReadOnlyBooleanProperty elementLoadingEventProperty()
      • isElementLoadingEvent

        public final boolean isElementLoadingEvent()
        Can be used to determine whether a list change occurs due to successful loading of elements, or due to cancellation of elements loading.
      • sourceChanged

        protected void sourceChanged​(javafx.collections.ListChangeListener.Change<? extends javafx.concurrent.Task<Map.Entry<Integer,​List<T>>>> pChange)
        Specified by:
        sourceChanged in class javafx.collections.transformation.TransformationList<T,​javafx.concurrent.Task<Map.Entry<Integer,​List<T>>>>
      • getLoadingElement

        protected T getLoadingElement()
        Override this method if you want get method to return specific element (instead of null), while element is being loaded. This can be used, for example, to ensure proper updates of cell content in TableView - otherwise, TableView will ignore the change events which will notify about finishing of elements loading, because old values of those change events will be equal to the new values - null. As a result, the loading graphic will not always be shown.
      • getState

        public javafx.concurrent.Worker.State getState​(int pIndex)
      • getStateProperty

        public javafx.beans.value.ObservableValue<javafx.concurrent.Worker.State> getStateProperty​(int pIndex)
      • getSourceIndex

        public int getSourceIndex​(int pIdx)
        Specified by:
        getSourceIndex in class javafx.collections.transformation.TransformationList<T,​javafx.concurrent.Task<Map.Entry<Integer,​List<T>>>>
      • getViewIndex

        public int getViewIndex​(int pIdx)
        Specified by:
        getViewIndex in class javafx.collections.transformation.TransformationList<T,​javafx.concurrent.Task<Map.Entry<Integer,​List<T>>>>
      • setSize

        public void setSize​(int pSize)
      • refresh

        public void refresh()
      • isDone

        public static boolean isDone​(javafx.concurrent.Worker.State pState)