How to close a ViewPart in Eclipse?

前端 未结 6 1383
时光取名叫无心
时光取名叫无心 2020-12-10 05:52

I have a view in Eclipse (implemented by a class which extends org.eclipse.ui.part.ViewPart) which I need to close. I mean completely close, not just hide. I wa

6条回答
  •  眼角桃花
    2020-12-10 06:03

    The org.eclipse.ui.internal.ViewFactory has a method called releaseView that I think closes the view completely (though I'm not certain). It takes an IViewReference.

    You can access the ViewFactory by calling Perspective.getViewFactory, and you can access the Perspective, you then pass it an IViewReference to release the view.

    IWorkbenchPage page = 
    Workbench.getInstance().getActiveWorkbenchWindow().getActivePage()
    
    Perspective perspective = page.getPerspective();
    
    String viewId = "myViewId"; //defined by you
    
    //get the reference for your viewId
    IViewReference ref = page.findViewReference(viewId);
    
    //release the view
    perspective.getViewFactory.releaseView(ref);
    

提交回复
热议问题