JFace进度条

Java代码   收藏代码
  1. someButton.addSelectionListener( new  SelectionAdapter() {  
  2.                 public   void  widgetSelected(SelectionEvent e) {  
  3.                     IRunnableWithProgress runnable = new  IRunnableWithProgress () {  
  4.                         final   byte [][] result =  new   byte [ 1 ][];  
  5.                         //实现接口中的execute方法:   
  6.                         protected   void  execute(IProgressMonitor monitor)  throws  CoreException {  
  7.                            //具体的业务逻辑:   
  8.                              
  9.                         }  
  10.                          
  11.   
  12.                        //实现接口中的run方法,该方法是一个同步方法:   
  13.                        public   synchronized   final   void  run(IProgressMonitor monitor)  
  14.                          throws  InvocationTargetException, InterruptedException {  
  15.                            try  {  
  16.                                //总的工作量   
  17.                                int  totalWork = IProgressMonitor.UNKNOWN;  
  18.                                monitor.beginTask("A Progress monitor dialog example..." 1000 );  
  19.                                if  (result[ 0 ] ==  null ){  
  20.                                    totalWork = 400 ;  
  21.                                }  
  22.                                monitor.worked(totalWork);  
  23.   
  24.                                //执行业务逻辑:   
  25.                                execute(monitor);  
  26.                                if  (result[ 0 ] !=  null ) {  
  27.                                    totalWork = 1000 ;  
  28.                                }else  {  
  29.                                    totalWork = 700 ;  
  30.                                }  
  31.                                monitor.worked(totalWork);  
  32.                            
  33.                            } catch  (CoreException e) {  
  34.                                throw   new  InvocationTargetException(e);  
  35.                            } catch  (OperationCanceledException e) {  
  36.                                throw   new  InterruptedException(e.getMessage());  
  37.                            }finally  {  
  38.                                monitor.done();  
  39.                            }  
  40.                        }  
  41.                     };  
  42.                     try  {  
  43.                         new  ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()).run( true true , runnable);  
  44.                     } catch  (InvocationTargetException e1) {  
  45.                         // TODO Auto-generated catch block   
  46.                         e1.printStackTrace();  
  47.                     } catch  (InterruptedException e1) {  
  48.                         // TODO Auto-generated catch block   
  49.                         e1.printStackTrace();  
  50.                     }   
  51.                 }  
  52.             }); 

你可能感兴趣的:(JFace进度条)