采用Wizard的时候,当操作很费时时,采用进度条指示会提供一个良好的界面视觉。幸运的是,Eclipse已经为我们准备了一个进度条,只要合理利用,就可以让它显示出来。
在Wizard的performFinish方法中,不要直接写完成方法,采用如下方法:
public boolean performFinish() {
try {
this.getContainer().run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("task.name", 100);
//下面的代码写业务逻辑,别忘了调用monitor.worked(..)让进度条前进
monitor.done();
}
});
return true;
} catch (InvocationTargetException e) {
//异常处理
} catch (InterruptedException e) {
;//
}
return false;
}
这样,当点击完成时,就会有一个进度条在Wizard底部显示。操作完成后,整个Wizard自动关闭。
以上代码通过阅读WizardProjectsImportPage.java获得。
在Wizard的performFinish方法中,不要直接写完成方法,采用如下方法:
public boolean performFinish() {
try {
this.getContainer().run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("task.name", 100);
//下面的代码写业务逻辑,别忘了调用monitor.worked(..)让进度条前进
monitor.done();
}
});
return true;
} catch (InvocationTargetException e) {
//异常处理
} catch (InterruptedException e) {
;//
}
return false;
}
这样,当点击完成时,就会有一个进度条在Wizard底部显示。操作完成后,整个Wizard自动关闭。
以上代码通过阅读WizardProjectsImportPage.java获得。