在rcp中切换透视图

时间:2015-03-25 13:04:26

标签: java eclipse-plugin eclipse-rcp perspective

我有一个rcp应用程序,它包含两个透视图。从一个角度来看,我有一棵树。双击树中的任何项目,它将打开所选树项的详细信息,但视角相同。我想在双击时切换透视图,而不是在同一透视图中打开所选项的详细信息。我该怎么办?

我的双击监听器是

 // Add double click listener to open an element editor on double click action:
    getViewer().addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (currentTreeSelection instanceof StoreableElement) {
                openElementContentEditor((StoreableElement)currentTreeSelection);
            }

        }
    }); 

内容编辑器是显示所选树项目详细信息的部分。

 public void openElementContentEditor(StoreableElement element) {

    ElementDescriptor ed = DataStoreManagement.getInstance().getElementDescriptorById(element.getDescriptor());
    String editorID = ed.getEditor();
    IDataStoreEditorInput editorInput = DataStoreManagement.getInstance().createEditorInput(element);

    try {
        PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow()
                .getActivePage()
                .openEditor(editorInput, editorID, true,
                        IWorkbenchPage.MATCH_INPUT);

    } catch (PartInitException e) {
        e.printStackTrace();
    }
}

由于

1 个答案:

答案 0 :(得分:0)

我使用以下代码段来切换视角:

IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
workbenchWindow.getWorkbench().showPerspective("PERSPECTIVE_ID", workbenchWindow);