IRunnableWithProgress operation = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.beginTask("Main task running ...", 5);
for (int i = 0; i < 5; i++) {
monitor.subTask("Subtask # " + i + " running.");
runSubTask(new SubProgressMonitor(monitor, 1), i);
}
}
};
Now the question is what happens when the runSubTask() method sets another subTask on the SubProgressMonitor?
private void runSubTask(IProgressMonitor monitor, int subTaskId) {
monitor.beginTask("Sub task running", 10);
for (int i = 0; i < 10; i++) {
monitor.subTask("Inside subtask, " + i + " out of 10");
// do something here ...
monitor.worked(1);
if (monitor.isCanceled())
throw new OperationCanceledException();
}
monitor.done();
}
}
Basically the SubProgressMonitor's subTask() overwrites the parent's subTask(). Thats the default behaviour. You can customize it with the style bits provided in the SubProgressMonitor:
If you want to append the SubProgressMonitor's subTask info, use the style PREPEND_MAIN_LABEL_TO_SUBTASK:
new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK), i);
Else if you want to ignore it altogher then use the SUPPRESS_SUBTASK_LABEL style:
new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), i);



0 comments:
Post a Comment