Class FilterModel.AbstractRefresher<T>

java.lang.Object
is.codion.common.model.FilterModel.AbstractRefresher<T>
Type Parameters:
T - the model item type
All Implemented Interfaces:
FilterModel.Refresher<T>
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 Details

    • AbstractRefresher

      protected AbstractRefresher(Supplier<Collection<T>> items)
      Parameters:
      items - supplies the items
  • Method Details

    • async

      public final is.codion.common.state.State 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 interface FilterModel.Refresher<T>
      Returns:
      the State controlling whether asynchronous refreshing is enabled
      See Also:
    • items

      public final is.codion.common.value.Value<Supplier<Collection<T>>> items()
      Specified by:
      items in interface FilterModel.Refresher<T>
      Returns:
      a Value controlling the item supplier for this refresher instance
    • refresh

      public final void refresh()
      Description copied from interface: FilterModel.Refresher
      Refreshes the items in the associated filter model. Note that this method only throws exceptions when run synchronously.
      Specified by:
      refresh in interface FilterModel.Refresher<T>
      See Also:
    • refreshThen

      public final void refreshThen(Consumer<Collection<T>> afterRefresh)
      Description copied from interface: FilterModel.Refresher
      Refreshes the data in this model. Note that this method only throws exceptions when run synchronously. Use FilterModel.Refresher.refreshFailedEvent() to listen for exceptions that happen during asynchronous refresh.
      Specified by:
      refreshThen in interface FilterModel.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:
      observer in interface FilterModel.Refresher<T>
      Returns:
      an observer active while a refresh is in progress
    • refreshEvent

      public final is.codion.common.event.EventObserver<?> refreshEvent()
      Specified by:
      refreshEvent in interface FilterModel.Refresher<T>
      Returns:
      an observer notified each time this model has been successfully refreshed
      See Also:
    • refreshFailedEvent

      public final is.codion.common.event.EventObserver<Exception> refreshFailedEvent()
      Specified by:
      refreshFailedEvent in interface FilterModel.Refresher<T>
      Returns:
      an observer notified each time an asynchronous refresh has failed
      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

      protected final void notifySuccess()
      Triggers the successful refresh event
      See Also:
    • notifyFailure

      protected final void notifyFailure(Exception exception)
      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

      protected abstract void refreshAsync(Consumer<Collection<T>> afterRefresh)
      Performes an async refresh
      Parameters:
      afterRefresh - if specified will be called after a successful refresh
    • refreshSync

      protected abstract void refreshSync(Consumer<Collection<T>> afterRefresh)
      Performs a sync refresh
      Parameters:
      afterRefresh - if specified will be called after a successful refresh
    • processResult

      protected abstract void processResult(Collection<T> items)
      Processes the refresh result, by replacing the current model items by the result items.
      Parameters:
      items - the items resulting from the refresh operation