2011-05-26 25 views
0

我正在運行execute方法,但是我在下面的代碼中給出了一些logError錯誤。請幫忙!PDE(java中的插件開發)

public Object execute(ExecutionEvent event) throws ExecutionException { 
     //get the active window 
     IWorkbenchWindow window=HandlerUtil.getActiveWorkbenchWindowChecked(event); 
     if(window==null) 
      return null; 
     //get the active page 
     IWorkbenchPage page= window.getActivePage(); 
     if(page==null) 
      return null; 
     //open and activate the Favorite view 
     try{ 
      page.showView(ViewPart.ID); 
     } 
     catch(PartInitException e){ 
      FavoritesLog.logError("Failed to open the favorites view", e); 


     } 
     return null; 
    } 
+0

請編輯您的問題,以包括你得到的例外。 – ShiDoiSi 2011-09-08 13:41:22

回答

0

不確定到底發生了什麼錯誤,但是您應該嘗試將執行代碼的內部包裝在UIJob中。 類似這樣的:

public Object execute(final ExecutionEvent event) throws ExecutionException { //get the active window 
    Job job = new UIJob("Show View") { 
     public IStatus runInUIThread(IProgressMonitor monitor) { 
      IWorkbenchWindow window=HandlerUtil.getActiveWorkbenchWindowChecked(event); 
      if(window==null) { 
       return Status.CANCEL_STATUS; 
      } 
      //get the active page 
      IWorkbenchPage page = window.getActivePage(); 
      if(page==null) { 
       return return Status.CANCEL_STATUS; 
      } 
      //open and activate the Favorite view 
      try{ 
       page.showView(ViewPart.ID); 
      } catch(PartInitException e){ 
       FavoritesLog.logError("Failed to open the favorites view", e); 
       return return Status.CANCEL_STATUS; 
      } 
      return Status.OK_STATUS; 
    }; 
    job.schedule(); 
    return null; 
}