How to reopen a viewpart from menu?
i have one perspective and one viewpart. The viewpart is shown as soon as the program opens. The viewpart should be the only one and should be closeable.
I have two problems with that behaviour:
- I want the perspective to be shown empty, just a background image should being shown. (How do I do that?)
- I want to open the viewpart from the menu, using the command style menu.
So far I can close my viewpart and the perspective is empty.
but
I can not call it from the menu with my selfdefined command. The code is like
public class C开发者_JAVA百科allMyViewPart extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
MyViewPart myViewPart = new MyViewPart();
return null;
}
}
What am I doing wrong? Thanks!
Well, it was easier than I thought.
public class CallMyViewPart extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
try {
page.showView("somedomain.mainViewpart");
} catch (PartInitException e) {
e.printStackTrace();
}
return null;
}
}
精彩评论