编写插件过程中,如果需要处理耗时的操作,需要使用进度条显示进度,也防止点击按钮无反应的情况
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();
}