Question

Suppose I have an API method which is intended to perform long-term operation and which therefore receives monitor as a parameter, like in

org.eclipse.ui.part.EditorPart.doSave(IProgressMonitor monitor)

If I had single operation to do in this method, I would code, for instance, to write an image

imageFile.create(imageInput, false, monitor);

But what if I do SEVERAL long-term sub-routines inside single doSave? How to make that monitor measures each with 50% or something?

imageFile.create(imageInput, false, monitor);
descriptionFile.create(descriptionInput, false, monitor);
Was it helpful?

Solution

Use SubProgressMonitor for each call the methods:

monitor.beginText("task", 100);

imageFile.create(imageInput, false, new SubProgressMonitor(monitor, 50));

descriptionFile.create(descriptionInput, false, new SubProgressMonitor(monitor, 50));

The sum of the 'tick' count given to all the sub progress monitors should match the 'tick' count given on the beginTask call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top