2009-07-10 52 views
4

我有一个在Eclipse中运行的作业(扩展了org.eclipse.core.runtime.jobs.Job的类)。这项工作得到了一个IProgressMonitor,我用它来报告进度,这很好。将工作添加到Eclipse中的作业进度监视器

这是我的问题:在处理过程中,我有时会发现有更多的工作比我预期的要多。有时甚至翻番。但是,一旦我在进度监视器中设置了滴答总数,就无法更改此值。

关于如何克服这个问题的任何想法?

回答

5

看看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)); 
    } 

技术细节不谈,这是我会怎么做:

  • 你平常的工作是100;
  • 设置了200的初始工作;
  • 当你进步时,根据需要增加工作量,假设要完成的工作总数为100;
  • 工作完成时,表示完成。

这有以下影响:

  • 定期工作项目,这需要100个单位,它最终完成50%后进步非常快;
  • 对一个长期的工作项目,它结束了一个不错的稳定进展。

这比完成用户期望的速度更快,而且看起来不会长时间卡住。

对于奖励积分,如果/当检测到潜在的长时间子任务足够快时,仍然以大量增加进度。这避免了从50%跳跃到完成。

+0

我熟悉它,这是没有好。如果您事先知道您需要更多工作,这只会有所帮助。除此之外,我可以在第一时间给出更高的分数。如果没有更多的工作,第一个30%将会爬行,然后下一个会飞。这不是一个好的用户体验。 – zvikico 2009-07-10 07:44:42

+1

如果您首先投入最多的工作量,它确实有帮助。 – 2009-07-10 08:00:05

0

有一个eclipse.org article使用进度监视器,可以帮助你一般。 AFAIK无法调整显示器中的刻度数量,因此除非您通过初始阶段猜测任务的相对大小并将刻度分配给每个部分,否则您将跳转。

您可以分配第一个10%来确定工作的大小,尽管在完成之前您无法做到这一点,所以您最终只能将进度条上的关键点转移。

0

听起来像一个“回归显示器”给我:-)

比方说,你是显示50%的进步,你会发现,你只在25%实际上是,你有什么打算做?回去?

也许你能实现自己的IProgressMonitor的做到这一点,但我不知道的附加值,为您的用户

0

我想你会发现这个问题是有点更抽象的比你想象的。你问的问题真的是“我有一份工作,我不知道需要多长时间,我什么时候可以说我已经完成了一半?”答案是:你不能。进度条可以显示整体的进度。如果你不知道总数或百分比,那么进度条并不好玩。

0

将您的IProgressMonitor转换为SubMonitor,然后您可以随时调用SubMonitor.setWorkRemaining重新分配剩余的滴答数。

为副监视器的Javadoc有这个例子演示了如何报告进度,如果你不事先知道蜱总数:

// 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; 
     } 
    }