代码之家  ›  专栏  ›  技术社区  ›  zvikico

在Eclipse中向作业的进度监视器添加工作

  •  4
  • zvikico  · 技术社区  · 15 年前

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

    5 回复  |  直到 15 年前
        1
  •  5
  •   Robert Munteanu    15 年前

    看一看 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%跳到完成。

        2
  •  0
  •   Rich Seller    15 年前

    有一个 eclipse.org article 关于进度监视器的使用,可能对您有帮助。AFAIK没有办法调整监视器中记号的数量,因此除非你做一个初始过程来猜测任务的相对大小,并将记号分配给每个部分,否则你将得到跳跃。

        3
  •  0
  •   Alexandre Pauzies    14 年前

    听起来像“回归监视器”对我来说:-)

    假设你显示了50%的进度,你发现你实际上只有25%,你打算怎么办?回去?

    也许您可以实现自己的IProgressMonitor来实现这一点,但我不确定它对您的用户有何附加价值

        4
  •  0
  •   Eng    13 年前

    我想你会发现这个问题比你想象的要抽象一些。你问的问题其实是“我有一个工作,我不知道要花多长时间,我什么时候才能说我完成了一半?”答案是:你不能。进度条是用来显示进度占总进度的百分比。如果你不知道总数或百分比,那么进度条是没有乐趣的。

        5
  •  0
  •   Stefan    9 年前

    将IProgressMonitor转换为子监视器,然后可以调用SubMonitor.setwork剩余随时重新分配剩余的滴答数。

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