编写插件过程中,如果需要处理耗时的操作,需要使用进度条显示进度,也防止点击按钮无反应的情况
try {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
// 数字是totalWork
monitor.beginTask("处理中……", 100);
/*
* 处理事务,worked方法表示工作了多少的进度
*/
monitor.worked(10);
monitor.done();
}
};
ProgressMonitorDialog dialog = new ProgressMonitorDialog(
PlatformUI.getWorkbench().getDisplay().getActiveShell());
dialog.setCancelable(false);
dialog.run(true, true, runnable);
} catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
}
本文介绍在Eclipse插件开发中如何使用进度条显示长时间运行任务的进度,通过具体代码示例展示了如何初始化进度监视器、设置任务总数、更新进度及完成任务。
321

被折叠的 条评论
为什么被折叠?



