Module is.codion.swing.common.model
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 thisProgressWorker
produces.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.
Note that the onStarted
handler is NOT called in case the background task finishes
before the SwingWorker.StateValue.STARTED
change event is fired.
ProgressWorker.builder(this::performTask)
.onStarted(this::displayDialog)
.onDone(this::closeDialog)
.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 interface
Builds aProgressWorker
instance.static interface
Reports progress and publishes intermediate results for a ProgressWorkerstatic interface
A progress aware background task producing a result.static interface
A background task producing a result.Nested classes/interfaces inherited from class javax.swing.SwingWorker
SwingWorker.StateValue
Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
V> ProgressWorker.Builder <T, V> builder
(ProgressWorker.ProgressResultTask<T, V> task) static <T> ProgressWorker.Builder
<T, ?> builder
(ProgressWorker.ResultTask<T> task) protected T
protected void
done()
Methods inherited from class javax.swing.SwingWorker
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgress
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.Future
exceptionNow, resultNow, state
-
Method Details
-
builder
- Type Parameters:
T
- the worker result type- Parameters:
task
- the task to run- Returns:
- a new
ProgressWorker.Builder
instance
-
builder
public static <T,V> ProgressWorker.Builder<T,V> builder(ProgressWorker.ProgressResultTask<T, V> task) - Type Parameters:
T
- the worker result typeV
- the intermediate result type- Parameters:
task
- the task to run- Returns:
- a new
ProgressWorker.Builder
instance
-
doInBackground
- Specified by:
doInBackground
in classSwingWorker<T,
V> - Throws:
Exception
-
done
protected void done()- Overrides:
done
in classSwingWorker<T,
V>
-