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:
ViewportRange
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> javafx.concurrent.Task<Map.Entry<Integer,List<T>>>
createTask(int pFrom, int pTo, Callable<List<T>> pCallable)
javafx.beans.property.ReadOnlyBooleanProperty
elementLoadingEventProperty()
T
get(int pIndex)
protected T
getLoadingElement()
Override this method if you want get method to return specific element (instead of null), while element is being loaded.int
getSourceIndex(int pIdx)
javafx.concurrent.Worker.State
getState(int pIndex)
javafx.beans.value.ObservableValue<javafx.concurrent.Worker.State>
getStateProperty(int pIndex)
int
getViewIndex(int pIdx)
javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>>
getViewportRange()
static boolean
isDone(javafx.concurrent.Worker.State pState)
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.boolean
isViewportChange()
Can be used to determine whether a list change occurs due to viewport change.void
refresh()
void
setSize(int pSize)
int
size()
protected void
sourceChanged(javafx.collections.ListChangeListener.Change<? extends javafx.concurrent.Task<Map.Entry<Integer,List<T>>>> pChange)
javafx.beans.property.ReadOnlyBooleanProperty
viewportChangeProperty()
-
Methods inherited from class javafx.collections.transformation.TransformationList
getSource, getSourceIndexFor, isInTransformationChain
-
Methods 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, setAll
-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods 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, toArray
-
-
-
-
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)
-
get
public T get(int pIndex)
-
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 interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in 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)
-
-