RCR开发:启动时创建多透视图切换按钮

来源:互联网 发布:sql sum函数 小数点 编辑:程序博客网 时间:2024/06/11 02:52

RCR开发:启动时创建多透视图切换按钮

在开发RCP应用时,往往根据需要在一个主窗口创建多个透视图。但是程序默认只显示其中WorkbenchAdvisor子类(即ApplicationWorkbenchAdvisor)中getInitialWindowPerspectiveId方法所返回透视图ID的那一个。如图:

只有一个RCP透视图显示。并且没有切换选项。要打开其他透视图需要左面菜单手动创建
那么如何实现程序运行就开启多个透视图呢?
在WorkbenchAdvisor子类(即ApplicationWorkbenchAdvisor)中添加如下方法即可

    @Override    public void postStartup() {        // TODO Auto-generated method stub        super.postStartup();        IWorkbenchWindow iWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();        //        PerspectiveBarManager perspectiveBarManager = ((WorkbenchWindow)iWorkbenchWindow).getPerspectiveBar();        if(perspectiveBarManager != null){            IPerspectiveDescriptor iPerspectiveDescriptor = WorkbenchPlugin.getDefault().getPerspectiveRegistry().findPerspectiveWithId("MenuTest1.perspective4");            PerspectiveBarContributionItem item = new PerspectiveBarContributionItem(iPerspectiveDescriptor, iWorkbenchWindow.getActivePage());            perspectiveBarManager.addItem(item);        }    }}
实现此方法后,再运行RCP程序,其默认就已经打开了其他的透视图,如图:

这里启动后默认打开了第二个透视图US..不需要手工添加打开

转载请注明出处!

原创粉丝点击