Module is.codion.common.model
Package is.codion.common.model.filter
Class FilterModel.AbstractRefresher<T>
java.lang.Object
is.codion.common.model.filter.FilterModel.AbstractRefresher<T>
- Type Parameters:
T- the model item type
- All Implemented Interfaces:
FilterModel.Refresher<T>
- Direct Known Subclasses:
AbstractRefreshWorker
- 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
ConstructorsModifierConstructorDescriptionprotectedAbstractRefresher(@Nullable Supplier<Collection<T>> items, boolean async) -
Method Summary
Modifier and TypeMethodDescriptionfinal ObservableStateactive()Changes to this state are always triggered on the UI thread.final 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.protected abstract booleanprotected final Optional<Supplier<Collection<T>>> items()protected final voidnotifyResult(Collection<T> result) Triggers the successful refresh event with the given result itemsprotected abstract voidprocessResult(Collection<T> result) Processes the refresh result, by replacing the current model items by the result items.final voidrefresh(@Nullable Consumer<Collection<T>> onResult) Refreshes the data.protected abstract voidrefreshAsync(@Nullable Consumer<Collection<T>> onResult) Performes an async refreshprotected abstract voidrefreshSync(@Nullable Consumer<Collection<T>> onResult) Performs a sync refreshfinal Observer<Collection<T>> result()This event is always triggered on the UI thread.protected final voidsetActive(boolean refreshActive) Sets the active state of this refresher.
-
Constructor Details
-
AbstractRefresher
- Parameters:
items- supplies the items when refreshingasync- true if async refresh should be used
-
-
Method Details
-
async
Description copied from interface:FilterModel.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 interfaceFilterModel.Refresher<T>- Returns:
- the
Statecontrolling whether asynchronous refreshing is enabled - See Also:
-
active
Description copied from interface:FilterModel.RefresherChanges to this state are always triggered on the UI thread.
- Specified by:
activein interfaceFilterModel.Refresher<T>- Returns:
- an observable indicating that a refresh is in progress
-
result
Description copied from interface:FilterModel.RefresherThis event is always triggered on the UI thread.
- Specified by:
resultin interfaceFilterModel.Refresher<T>- Returns:
- an observer notified with the result after a successful refresh
-
refresh
Description copied from interface:FilterModel.RefresherRefreshes the data. Async refresh is performed when it is enabled (
FilterModel.Refresher.async()) and this method is called on the UI thread.- Specified by:
refreshin interfaceFilterModel.Refresher<T>- Parameters:
onResult- called on the EDT with the result after a successful refresh, may be null- See Also:
-
items
- Returns:
- the item supplier for this refresher instance
-
setActive
protected final void setActive(boolean refreshActive) Sets the active state of this refresher.
This method must be called on the UI thread.
- Parameters:
refreshActive- true if refresh is starting, false if ending
-
notifyResult
Triggers the successful refresh event with the given result items
This method must be called on the UI thread.
- Parameters:
result- the refresh result- See Also:
-
isUserInterfaceThread
protected abstract boolean isUserInterfaceThread()- Returns:
- true if we're running on a UI thread
-
refreshAsync
Performes an async refresh
This method must be called on the UI thread.
- Parameters:
onResult- if specified will be called on the EDT with the result after a successful refresh
-
refreshSync
Performs a sync refresh
This method must be called on the UI thread.
- Parameters:
onResult- if specified will be called with the result after a successful refresh
-
processResult
Processes the refresh result, by replacing the current model items by the result items.
This method must be called on UI thread.
- Parameters:
result- the items resulting from the refresh operation
-