问题描述
|
我正在运行execute方法,但是在以下代码中,我在logError上给出了一些错误。请帮忙!
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;
}
解决方法
不确定到底出现了什么错误,但是您应该尝试将执行代码的内部包装在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;
}