Class ProgressWorker<T,V>
- Type Parameters:
T- the type of result thisProgressWorkerproduces.V- the type of intermediate result produced by thisProgressWorker
- All Implemented Interfaces:
Runnable,Future<T>,RunnableFuture<T>
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:
- Builder-only: pass a task and wire handlers via the builder.
- Handler interfaces: implement one of the handler interfaces (
ProgressWorker.TaskHandler,ProgressWorker.ResultTaskHandler,ProgressWorker.ProgressTaskHandler,ProgressWorker.ProgressResultTaskHandler) to encapsulate both the background task and its handlers in a single class. Handler interface methods are wired automatically and called first. Additional handlers can then be added via the builder and are called after.
On successful completion, handlers are called in this order:
onDone → onSuccess → onResult(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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceBuilds aProgressWorkerinstance.static interfaceProvides builders for a given task type.static interfaceProvides default handler methods for theProgressWorkerlifecycle.static interfaceExtendsProgressWorker.Handlerwith progress and publish handlers.static interfaceReports progress and publishes intermediate results for a ProgressWorkerstatic interfaceA progress aware background task producing a result.static interfaceAProgressWorker.ProgressResultTaskcombined withProgressWorker.ProgressHandler, for encapsulating a progress-aware, result-producing background task and its handlers in a single class.static interfaceA progress aware background task.static interfaceAProgressWorker.ProgressTaskcombined withProgressWorker.ProgressHandler, for encapsulating a progress-aware background task and its handlers in a single class.static interfaceA background task producing a result.static interfaceAProgressWorker.ResultTaskcombined withProgressWorker.Handler, for encapsulating a result-producing background task and its handlers in a single class.static interfaceA background task.static interfaceAProgressWorker.Taskcombined withProgressWorker.Handler, for encapsulating a background task and its handlers in a single class.Nested classes/interfaces inherited from class javax.swing.SwingWorker
SwingWorker.StateValueNested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Field Summary
Fields -
Method Summary
Methods inherited from class javax.swing.SwingWorker
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgressMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.concurrent.Future
exceptionNow, resultNow, state
-
Field Details
-
DEFAULT_MAXIMUM
public static final int DEFAULT_MAXIMUM- See Also:
-
-
Method Details
-
builder
- Returns:
- a
ProgressWorker.BuilderFactory
-
doInBackground
- Specified by:
doInBackgroundin classSwingWorker<T,V> - Throws:
Exception
-
done
protected void done()- Overrides:
donein classSwingWorker<T,V>
-