java.lang.Object
is.codion.common.model.FilterModel.AbstractRefresher<T>
- Type Parameters:
T
- the model item type
- All Implemented Interfaces:
FilterModel.Refresher<T>
- Direct Known Subclasses:
AbstractFilterModelRefresher
- Enclosing interface:
- FilterModel<T>
public abstract static class FilterModel.AbstractRefresher<T>
extends Object
implements FilterModel.Refresher<T>
An abstract base implementation of
FilterModel.Refresher
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal State
async()
Sometimes we'd like to be able to refresh one or more models and perform some action on the refreshed data, after the refresh has finished, such as selecting a particular item or such.failure()
protected final void
notifyFailure
(Exception exception) Triggers the refresh failed eventprotected final void
notifySuccess
(Collection<T> items) Triggers the successful refresh event with the given itemsfinal StateObserver
observer()
protected abstract void
processResult
(Collection<T> items) Processes the refresh result, by replacing the current model items by the result items.protected final void
refresh
(Consumer<Collection<T>> onRefresh) Refreshes the data.protected abstract void
refreshAsync
(Consumer<Collection<T>> onRefresh) Performes an async refreshprotected abstract void
refreshSync
(Consumer<Collection<T>> onRefresh) Performs a sync refreshprotected final void
setRefreshing
(boolean refreshing) Sets the refreshing (active) state of this refresherfinal Observer<Collection<T>>
success()
protected final Supplier<Collection<T>>
supplier()
protected abstract boolean
-
Constructor Details
-
AbstractRefresher
- Parameters:
supplier
- supplies the items when refreshing
-
-
Method Details
-
async
Description copied from interface:FilterModel.Refresher
Sometimes we'd like to be able to refresh one or more models and perform some action on the refreshed data, after the refresh has finished, such as selecting a particular item or such. This is quite difficult to achieve with asynchronous refresh enabled, so here's a way to temporarily disable asynchronous refresh, for a more predictable behaviour.- Specified by:
async
in interfaceFilterModel.Refresher<T>
- Returns:
- the
State
controlling whether asynchronous refreshing is enabled - See Also:
-
observer
- Specified by:
observer
in interfaceFilterModel.Refresher<T>
- Returns:
- an observer active while a refresh is in progress
-
success
- Specified by:
success
in interfaceFilterModel.Refresher<T>
- Returns:
- an observer notified each time a successful refresh has been performed
-
failure
- Specified by:
failure
in interfaceFilterModel.Refresher<T>
- Returns:
- an observer notified each time an asynchronous refresh has failed
-
supplier
- Returns:
- the item supplier for this refresher instance
-
refresh
Refreshes the data. Note that this method only throws exceptions when run synchronously. Usefailure()
to listen for exceptions that happen during asynchronous refresh.- Parameters:
onRefresh
- called after a successful refresh, may be null- Throws:
RuntimeException
- in case of an exception when running synchronously.- See Also:
-
setRefreshing
protected final void setRefreshing(boolean refreshing) Sets the refreshing (active) state of this refresher- Parameters:
refreshing
- true if refresh is starting, false if ended
-
notifySuccess
Triggers the successful refresh event with the given items- Parameters:
items
- the refresh result- See Also:
-
notifyFailure
Triggers the refresh failed event- Parameters:
exception
- the refresh exception- See Also:
-
supportsAsyncRefresh
protected abstract boolean supportsAsyncRefresh()- Returns:
- true if we're running on a thread which supports async refresh, such as a UI or application thread
-
refreshAsync
Performes an async refresh- Parameters:
onRefresh
- if specified will be called after a successful refresh
-
refreshSync
Performs a sync refresh- Parameters:
onRefresh
- if specified will be called after a successful refresh
-
processResult
Processes the refresh result, by replacing the current model items by the result items.- Parameters:
items
- the items resulting from the refresh operation
-