Class ProgressWorker<T,V>

java.lang.Object
javax.swing.SwingWorker<T,V>
is.codion.swing.common.model.worker.ProgressWorker<T,V>
Type Parameters:
T - the type of result this ProgressWorker produces.
V - the type of intermediate result produced by this ProgressWorker
All Implemented Interfaces:
Runnable, Future<T>, RunnableFuture<T>

public final class ProgressWorker<T,V> extends SwingWorker<T,V>

A SwingWorker implementation. Instances of this class are not reusable.

Note that this implementation does NOT coalesce progress reports or intermediate result publishing, but simply pushes those directly to the onProgress and onPublish handlers on the Event Dispatch Thread.

The onStarted handlers are guaranteed to be called on the Event Dispatch Thread before the background task executes, and the onDone handlers are guaranteed to be called after the background task completes.

All handler types support multiple handlers, which are called in the order they were added.

There are two ways to use this class:

On successful completion, handlers are called in this order: onDoneonSuccessonResult(T) (result-producing tasks only).

Builder based usage example:

 ProgressWorker.builder(this::performTask)
   .onStarted(this::displayDialog)
   .onDone(this::closeDialog)
   .onSuccess(this::handleSuccess)
   .onResult(this::handleResult)
   .onProgress(this::displayProgress)
   .onPublish(this::publishMessage)
   .onCancelled(this::displayCancelledMessage)
   .onException(this::displayException)
   .execute();
See Also: