I’m trying to create ProgressMonitor with changing totalWork.
Lets assume that I have 2 steps. The first step is retrieving a list of objects. The totalWork=-1 (UNKNOWN).
In the second step I change every object from the lisl. So I want to change totalWork to the size of the list. I’ve tried something like the code below, but it didn’t work:
int totalWork = -1
monitor.beginTask("Task", totalWork);
monitor.subTask("Start Subtask 1");
final List<Object> list = retrieveList();
totalWork = list.size();
monitor.subTask("Retrieve Events");
for(Object obj:list){
//do some job
monitor.worked(1)
}
monitor.done()
Is there a way to achieve that ?
EDIT: I’m extending Job and the code above is in the run method.
Short answer: No!
Longer answer:
If the first step takes less than 100ms (even for very large data sets), then this is usually done before
beginTask…In many cases will the initial count operation take an amount of time that is very much comparable to the actual operation. And in this case you can use an embedded
SubProgressMonitor. Lets say the initial count takes 1/20 of the later operation: