Class SimpleLazyObservableList<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
javafx.collections.ObservableListBase<E>
javafx.collections.transformation.TransformationList<T,javafx.concurrent.Task<Map.Entry<Integer,List<T>>>>
com.iamsoft.util.ui.javafx.collections.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:
  • Property Details

    • viewportChange

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

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

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

    • getViewportRange

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

      public final javafx.beans.property.ReadOnlyBooleanProperty elementLoadingEventProperty()
      See Also:
    • 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>>>>
    • get

      public T get(int pIndex)
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<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)
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
    • 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)
    • createTask

      public static <T> javafx.concurrent.Task<Map.Entry<Integer,List<T>>> createTask(int pFrom, int pTo, Callable<List<T>> pCallable)