Module com.iamsoft.util.ui
Class LazyObservableList<K,V>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- javafx.collections.ObservableListBase<E>
-
- javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
-
- com.iamsoft.util.ui.javafx.collections.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
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description 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)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javafx.concurrent.Task<V>
get(int pIdx)
static int
getFrom(com.google.common.collect.Range<Integer> pRange)
Get lower endpoint (inclusive).int
getSourceIndex(int pIdx)
static int
getTo(com.google.common.collect.Range<Integer> pRange)
Get upper endpoint (exclusive).int
getViewIndex(int pIdx)
boolean
isViewportChange()
Can be used to determine whether a list change occurs due to viewport change.void
refresh()
Clears old values and re-fetches viewport values.protected void
runLater(Runnable pRunnable)
int
size()
protected void
sourceChanged(javafx.collections.ListChangeListener.Change<? extends K> pChg)
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
-
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)
-
size
public int size()
- Specified by:
size
in interfaceCollection<K>
- Specified by:
size
in interfaceList<K>
- Specified by:
size
in classAbstractCollection<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)
-
getSourceIndex
public int getSourceIndex(int pIdx)
-
getViewIndex
public int getViewIndex(int pIdx)
-
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).
-
-