您的位置:首页 > 编程语言 > Java开发

Eclipse平台中“进度条对话框”(ProgressMonitorDialog)的简单实现

2006-03-29 15:13 543 查看
运行环境:Eclipse 3.0.x

下面是的方法实现了一个简单的“进度条对话框”:

private byte[] progressMonitorDialogTest(final String bhContent, final String root, final String userName, final String pwd, final String payload) throws Exception {
final byte[][] result = new byte[1][];
IRunnableWithProgress pro = new IRunnableWithProgress () {

//实现接口中的execute方法:
protected void execute(IProgressMonitor monitor) throws CoreException {

//具体的业务逻辑:
result[0] = invokeDLL(bhContent, root, userName, pwd, payload);
}

//实现接口中的run方法,该方法是一个同步方法:
public synchronized final void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
try {

//总的工作量
int totalWork = IProgressMonitor.UNKNOWN;
monitor.beginTask("A Progress monitor dialog example...", totalWork);
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, false, pro);
}
catch (Exception e) {
e.printStackTrace();
}

return result[0];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: