Jface 进度条
程序员文章站
2022-03-09 13:32:49
...
someButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IRunnableWithProgress runnable = new IRunnableWithProgress () {
final byte[][] result = new byte[1][];
//实现接口中的execute方法:
protected void execute(IProgressMonitor monitor) throws CoreException {
//具体的业务逻辑:
}
//实现接口中的run方法,该方法是一个同步方法:
public synchronized final void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
try {
//总的工作量
int totalWork = IProgressMonitor.UNKNOWN;
monitor.beginTask("A Progress monitor dialog example...", 1000);
if (result[0] == null){
totalWork = 400;
}
monitor.worked(totalWork);
//执行业务逻辑:
execute(monitor);
if (result[0] != null) {
totalWork = 1000;
}else {
totalWork = 700;
}
monitor.worked(totalWork);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
}finally {
monitor.done();
}
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()).run(true, true, runnable);
} catch (InvocationTargetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
上一篇: 【Layui】formSelects下拉多选框取值
下一篇: PHP实现用户名中文汉字正则验证