开发者

How to reopen a viewpart from menu?

开发者 https://www.devze.com 2022-12-23 03:56 出处:网络
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 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:

  1. I want the perspective to be shown empty, just a background image should being shown. (How do I do that?)
  2. 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;      
    }      
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消