欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
					} 
				}
			});
 
相关标签: 工作