You can use the ProgressUtils.showProgressDialogAndRun() family of methods to show a progress bar in the center of the UI which blocks the UI until your task is done.
Implementing the ProgressRunnable interface will give your tasks access to the ProgressHandle. Then, using the showProgressDialogAndRun(ProgressRunnable<T> operation, String displayName, boolean includeDetailLabel)
method you can set the detail label for each sub-task that you need to run.
Here's a snippet showing the different ways that you could do this. The main task in this scenario is the "Running Startup" task. It drives all of the sub-tasks, passing in the ProgressHandle to each so that each sub-task can set the detail label:
...
final List<ProgressRunnable> tasks = new ArrayList<ProgressRunnable>();
tasks.add(new ProgressRunnable<Object>() {
@Override
public Object run(ProgressHandle ph) {
ph.progress("Work unit 1", 1);
return null;
}
});
tasks.add(new CancellableTask());
ProgressUtils.showProgressDialogAndRun(new ProgressRunnable<Void>() {
@Override
public Void run(ProgressHandle ph) {
// run all tasks passing in the ProgressHandle to each
for (ProgressRunnable task : tasks) {
task.run(ph);
}
return null;
}
}, "Running Startup", true);
...
// will show a Cancel button on the progress UI
private class CancellableTask implements ProgressRunnable<Object>, Cancellable {
@Override
public Object run(ProgressHandle ph) {
ph.progress("Cancellable work unit", 2);
return null;
}
@Override
public boolean cancel() {
// clean up
return true;
}
}