该方法org.eclipse.core.runtime.IProgressMonitor.worked(int)
接收表示增量的整数。这意味着,唯一可用的单位是自然单位。例如,它不能是百分比。
所以,如果我在作业中处理一些文件,我不能报告计数阶段,因为我应该调用的第一个方法是org.eclipse.core.runtime.IProgressMonitor.beginTask(String, int)
需要我知道总量。
如何实现?
更新
我在下面写了一个包装器,但这看起来很荒谬,需要这样做:
public class ProgressMonitorDoubleWrapper implements IProgressMonitor {
private IProgressMonitor delegate;
private int currentWork, totalWork;
private double currentWorkDouble;
public ProgressMonitorDoubleWrapper(IProgressMonitor monitor) {
this.delegate = monitor;
}
@Override
public void beginTask(String name, int totalWork) {
beginTask(name, (double) totalWork);
}
public void beginTask(String name, double totalWork) {
this.totalWork = (int) totalWork;
currentWork = 0;
currentWorkDouble = 0;
delegate.beginTask(name, this.totalWork);
}
@Override
public void done() {
delegate.done();
}
@Override
public void internalWorked(double work) {
delegate.internalWorked(work);
}
@Override
public boolean isCanceled() {
return delegate.isCanceled();
}
@Override
public void setCanceled(boolean value) {
delegate.setCanceled(value);
}
@Override
public void setTaskName(String name) {
delegate.setTaskName(name);
}
@Override
public void subTask(String name) {
delegate.subTask(name);
}
@Override
public void worked(int work) {
worked((double)work);
}
public void worked(double work) {
currentWorkDouble += work;
int increment = (int)(currentWorkDouble - (double)currentWork);
currentWork += increment;
delegate.worked(increment);
}
}