我正在运行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;
}
答案 0 :(得分: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;
}