How to close a ViewPart in Eclipse?

前端 未结 6 1381
时光取名叫无心
时光取名叫无心 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条回答
  •  萌比男神i
    2020-12-10 06:22

    To close views, opened in different perspective, I overridden perspectiveDeactivated() of org.eclipse.ui.PerspectiveAdapter.

    public void perspectiveDeactivated(IWorkbenchPage page,
            IPerspectiveDescriptor perspective) {
        super.perspectiveDeactivated(page, perspective);
        boolean myPerspective = MyPerspective.PERSPECTIVE_ID.equals(perspective.getId());
        if(!myPerspective) {
            //close Error Log view if it is opened in any perspective except My perspective. 
            IViewPart errorView = page.findView("org.eclipse.pde.runtime.LogView");
            if(errorView != null) {
                page.hideView(errorView);
            }
        }
    }
    

    My requirement was to close "Error Log" view. Above code can be modified to close any view.

提交回复
热议问题