Adding work to progress monitor in Eclipse

I have a job (a class that extends org.eclipse.core.runtime.jobs.Job) running inside Eclipse. The job receives an IProgressMonitor, and I use it to report progress that everything is fine.

Here is my problem: during processing, I sometimes find that there is more work than I expected. Sometimes it even doubles. However, as soon as I set the total number of ticks in the progress monitor, there is no way to change this value.

Any ideas on how to overcome this problem?

+4
source share
5 answers

Take a look at SubMonitor .

void doSomething(IProgressMonitor monitor) { // Convert the given monitor into a progress instance SubMonitor progress = SubMonitor.convert(monitor, 100); // Use 30% of the progress to do some work doSomeWork(progress.newChild(30)); // Advance the monitor by another 30% progress.worked(30); // Use the remaining 40% of the progress to do some more work doSomeWork(progress.newChild(40)); } 

Technical details aside, here's how I do it:

  • Your usual job is 100;
  • set the initial work 200;
  • The increment works as needed when you progress, believing that the total work should be 100;
  • when the work is completed, inform about its completion.

This has the following effects:

  • on a regular work item that takes 100 units, it ends very quickly after 50% progress;
  • on a long work item, it ends with a good steady progress.

This is better than faster than the user expects, and does not seem to be stuck for a long time.

For bonus points, if / when the detected potentially long subtask is fast enough, still increase the progress by a large amount. This avoids the transition from 50% to completion.

+5
source

There's an eclipse.org article on using progress monitors that can help you in general. AFAIK there is no way to change the size of ticks on the monitor, so if you do not make the initial pass to guess the relative size of tasks and assign ticks for each part, you will get jumps.

You can allocate the first 10% to determine the size of the task, often, although you cannot do it until you finish, so you just move the anchor point to the progress bar.

0
source

Sounds like a "regression monitor" to me :-)

Say you are showing 50% progress and you will find out that you are actually only 25%, what are you going to do? Come back?

Perhaps you can implement your own IProgressMonitor for this, but I'm not sure about the added value for your user.

0
source

I think you will find that the problem is a bit more abstract than you think. The question you ask is actually "I have a job, I don’t know how long it will take, when can I say that I'm halfway?" Answer: You cannot. Progress bars show progress as a percentage of the whole. If you do not know the total or percentage, then the progress indicator is not fun.

0
source

Convert your IProgressMonitor to SubMonitor, then you can call SubMonitor.setWorkRemaining at any time to redistribute the remaining number of ticks.

There is this example in javadoc for SubMonitor, demonstrating how to report progress if you do not know the total number of ticks in advance:

 // This example demonstrates how to report logarithmic progress in // situations where the number of ticks cannot be easily computed in advance. void doSomething(IProgressMonitor monitor, LinkedListNode node) { SubMonitor progress = SubMonitor.convert(monitor); while (node != null) { // Regardless of the amount of progress reported so far, // use 0.01% of the space remaining in the monitor to process the next node. progress.setWorkRemaining(10000); doWorkOnElement(node, progress.newChild(1)); node = node.next; } } 
0
source

All Articles