Module com.iamsoft.util.ui
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:
-
Property Summary
PropertiesTypePropertyDescriptionfinal javafx.beans.property.ReadOnlyBooleanPropertyfinal javafx.beans.property.ReadOnlyBooleanProperty -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateTask(int pFrom, int pTo, Callable<List<T>> pCallable) final javafx.beans.property.ReadOnlyBooleanPropertyget(int pIndex) protected TOverride this method if you want get method to return specific element (instead of null), while element is being loaded.intgetSourceIndex(int pIdx) javafx.concurrent.Worker.StategetState(int pIndex) javafx.beans.value.ObservableValue<javafx.concurrent.Worker.State>getStateProperty(int pIndex) intgetViewIndex(int pIdx) javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>>static booleanisDone(javafx.concurrent.Worker.State pState) final booleanCan be used to determine whether a list change occurs due to successful loading of elements, or due to cancellation of elements loading.final booleanCan be used to determine whether a list change occurs due to viewport change.voidrefresh()voidsetSize(int pSize) intsize()protected voidsourceChanged(javafx.collections.ListChangeListener.Change<? extends javafx.concurrent.Task<Map.Entry<Integer, List<T>>>> pChange) final javafx.beans.property.ReadOnlyBooleanPropertyMethods inherited from class javafx.collections.transformation.TransformationList
getSource, getSourceIndexFor, isInTransformationChainMethods inherited from class javafx.collections.ObservableListBase
addAll, addListener, addListener, beginChange, endChange, fireChange, hasListeners, nextAdd, nextPermutation, nextRemove, nextRemove, nextReplace, nextSet, nextUpdate, remove, removeAll, removeListener, removeListener, retainAll, setAll, setAllMethods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, subList, toArray, toArrayMethods inherited from interface javafx.collections.ObservableList
filtered, sorted, sorted
-
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
-
get
-
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:
sizein interfaceCollection<T>- Specified by:
sizein interfaceList<T>- Specified by:
sizein classAbstractCollection<T>
-
getSourceIndex
public int getSourceIndex(int pIdx) -
getViewIndex
public int getViewIndex(int pIdx) -
setSize
public void setSize(int pSize) -
refresh
public void refresh() -
isDone
public static boolean isDone(javafx.concurrent.Worker.State pState) -
createTask
-