Jface 进度条

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();
					} 
				}
			});
 

你可能感兴趣的:(工作)