在eclipse rcp中分离视图并以编程方式显示/隐藏它

时间:2018-10-08 08:43:52

标签: java eclipse-rcp rcp

我需要将视图添加到已分离并最初隐藏的Eclipse rcp应用程序中。用户操作后,如果它不可见,我想显示/打开它。

我设法在plugin.xml中将视图添加到了我的角度。但是我无法通过plugin.xml或代码隐藏或分离它。

我正在使用eclipse / rcp 3。

有什么想法吗?

plugin.xml

   <extension point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="a.company.infop.rcp.fahrplan.ui.perspectives.fahrplanPerspective">
         <view 
               closeable="true"
               id="a.company.infop.rcp.fahrplan.ui.views.verkehrsAnalyseView"
               minimized="false"
               ratio="0.5f"
               relationship="top"
               relative="org.eclipse.ui.editorss">
         </view>
      </perspectiveExtension>
   </extension>

   <extension point="org.eclipse.ui.views">
      <category
            id="a.company.infop.rcp.fahrplan.ui.fahrplanCategory"
            name="%fahrplan">
      </category>
      <view 
            category="a.company.infop.rcp.fahrplan.ui.fahrplanCategory"
            class="a.company.infop.rcp.fahrplan.internal.ui.views.VerkehrsanalyseView"
            icon="icons/suchergbnisse.png"
            id="a.company.infop.rcp.fahrplan.ui.views.verkehrsAnalyseView"
            name="%verkehrsanalyse"
            restorable="true">
      </view>
   </extension>

代码:

public class FahrplanPerspective implements IPerspectiveFactory {

    @Override
    public void createInitialLayout(IPageLayout layout) {
        IWorkbenchPage iWorkbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart verkehrsAnalyseView = iWorkbenchPage.findView("a.company.infop.rcp.fahrplan.ui.views.verkehrsAnalyseView");
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(verkehrsAnalyseView);
    }

}

1 个答案:

答案 0 :(得分:0)

我早些时候实现了这种功能,看看是否有帮助。 https://exploreeclipse.blogspot.com/2014/08/opening-eclipse-editor-or-view-in.html

为此,您需要具有e4工作台插件,并且它提供 org.eclipse.e4.ui.workbench.modeling API服务。

IWorkbench workbench = ActivatorPlugin.getDefault().getWorkbench();

//get editorpart somehow which you wanted to open it.
EditorPart openEditor = /*IDE.openEditor(workbench.getActiveWorkbenchWindow().getActivePage(), module, MyEditorID, false); */

//get editor site
IWorkbenchPartSite site = openEditor.getSite();

//get model service for editor site
EModelService modelService = (EModelService) site.getService(EModelService.class);
MPartSashContainerElement  mpartService = (MPart) site.getService(MPart.class);

//invoke detach on model service with coordinates.
modelService.detach(mpartService, 100, 100, 700, 700);


For view:

//Get view part
IViewPart view = workbench.getActiveWorkbenchWindow().getActivePage().findView(MyPerspective.ExplorerView_ID);

//get site for view

//invoke detach