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 Details

    • AbstractRefresher

      protected AbstractRefresher(@Nullable Supplier<Collection<T>> items, boolean async)
      Parameters:
      items - supplies the items when refreshing
      async - true if async refresh should be used
  • Method Details

    • async

      public final 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:
    • active

      public final ObservableState active()
      Description copied from interface: FilterModel.Refresher

      Changes to this state are always triggered on the UI thread.

      Specified by:
      active in interface FilterModel.Refresher<T>
      Returns:
      an observable indicating that a refresh is in progress
    • result

      public final Observer<Collection<T>> result()
      Description copied from interface: FilterModel.Refresher

      This event is always triggered on the UI thread.

      Specified by:
      result in interface FilterModel.Refresher<T>
      Returns:
      an observer notified with the result after a successful refresh
    • refresh

      public final void refresh(@Nullable Consumer<Collection<T>> onResult)
      Description copied from interface: FilterModel.Refresher

      Refreshes the data. Async refresh is performed when it is enabled (FilterModel.Refresher.async()) and this method is called on the UI thread.

      Specified by:
      refresh in interface FilterModel.Refresher<T>
      Parameters:
      onResult - called on the EDT with the result after a successful refresh, may be null
      See Also:
    • items

      protected final Optional<Supplier<Collection<T>>> 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

      protected final void notifyResult(Collection<T> result)

      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

      protected abstract void refreshAsync(@Nullable Consumer<Collection<T>> onResult)

      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

      protected abstract void refreshSync(@Nullable Consumer<Collection<T>> onResult)

      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

      protected abstract void processResult(Collection<T> result)

      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