Module is.codion.common.model
Package is.codion.common.model
Class FilteredModel.AbstractRefresher<T>
java.lang.Object
is.codion.common.model.FilteredModel.AbstractRefresher<T>
- Type Parameters:
T- the model item type
- All Implemented Interfaces:
FilteredModel.Refresher<T>
- Enclosing interface:
- FilteredModel<T>
public abstract static class FilteredModel.AbstractRefresher<T>
extends Object
implements FilteredModel.Refresher<T>
An abstract base implementation of
FilteredModel.Refresher.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddRefreshFailedListener(Consumer<Throwable> listener) final voidaddRefreshListener(Runnable listener) final is.codion.common.state.Stateasync()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.final is.codion.common.value.Value<Supplier<Collection<T>>>final is.codion.common.state.StateObserverobserver()protected abstract voidprocessResult(Collection<T> items) Processes the refresh result, by replacing the current model items by the result items.final voidrefresh()Refreshes the items in the associated filtered model.protected abstract voidrefreshAsync(Consumer<Collection<T>> afterRefresh) Performes an async refreshprotected final voidTriggers the successful refresh eventprotected final voidrefreshFailedEvent(Throwable throwable) Triggers the refresh failed eventprotected abstract voidrefreshSync(Consumer<Collection<T>> afterRefresh) Performs a sync refreshfinal voidrefreshThen(Consumer<Collection<T>> afterRefresh) Refreshes the data in this model.final voidremoveRefreshFailedListener(Consumer<Throwable> listener) final voidremoveRefreshListener(Runnable listener) protected final voidsetRefreshing(boolean refreshing) Sets the refreshing (active) state of this refresherprotected abstract boolean
-
Constructor Details
-
AbstractRefresher
- Parameters:
itemSupplier- the item supplier
-
-
Method Details
-
async
public final is.codion.common.state.State async()Description copied from interface:FilteredModel.RefresherSometimes 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:
asyncin interfaceFilteredModel.Refresher<T>- Returns:
- the State controlling whether asynchronous refreshing is enabled
- See Also:
-
itemSupplier
- Specified by:
itemSupplierin interfaceFilteredModel.Refresher<T>- Returns:
- a Value controlling the item supplier for this refresher instance
-
refresh
public final void refresh()Description copied from interface:FilteredModel.RefresherRefreshes the items in the associated filtered model. Note that this method only throws exceptions when run synchronously.- Specified by:
refreshin interfaceFilteredModel.Refresher<T>- See Also:
-
refreshThen
Description copied from interface:FilteredModel.RefresherRefreshes the data in this model. Note that this method only throws exceptions when run synchronously. UseFilteredModel.Refresher.addRefreshFailedListener(Consumer)to listen for exceptions that happen during asynchronous refresh.- Specified by:
refreshThenin interfaceFilteredModel.Refresher<T>- Parameters:
afterRefresh- called after a successful refresh, may be null- See Also:
-
observer
public final is.codion.common.state.StateObserver observer()- Specified by:
observerin interfaceFilteredModel.Refresher<T>- Returns:
- an observer active while a refresh is in progress
-
addRefreshListener
- Specified by:
addRefreshListenerin interfaceFilteredModel.Refresher<T>- Parameters:
listener- a listener to be notified each time this model has been successfully refreshed- See Also:
-
removeRefreshListener
- Specified by:
removeRefreshListenerin interfaceFilteredModel.Refresher<T>- Parameters:
listener- the listener to remove- See Also:
-
addRefreshFailedListener
- Specified by:
addRefreshFailedListenerin interfaceFilteredModel.Refresher<T>- Parameters:
listener- a listener to be notified each time an asynchronous refresh has failed- See Also:
-
removeRefreshFailedListener
- Specified by:
removeRefreshFailedListenerin interfaceFilteredModel.Refresher<T>- Parameters:
listener- the listener to remove
-
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
-
refreshEvent
protected final void refreshEvent()Triggers the successful refresh event- See Also:
-
refreshFailedEvent
Triggers the refresh failed event- Parameters:
throwable- 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:
afterRefresh- if specified will be called after a successful refresh
-
refreshSync
Performs a sync refresh- Parameters:
afterRefresh- 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
-