以编程方式显示Eclipse插件中的视图

时间:2021-09-26 10:51:10

I have a plug-in to an Eclipse RCP application that has a view. After an event occurs in the RCP application, the plug-in is instantiated, its methods are called to populate the plug-in's model, but I cannot find how to make the view appear without going to the "Show View..." menu.

我有一个带有视图的Eclipse RCP应用程序的插件。在RCP应用程序中发生事件后,插件被实例化,调用其方法来填充插件的模型,但是我无法找到如何在不进入“Show View ...”菜单的情况下显示视图。

I would think that there would be something in the workbench singleton that could handle this, but I have not found out how anywhere.

我认为工作台单例中会有一些东西可以解决这个问题,但我还没有发现任何地方。

4 个解决方案

#1


46  

You are probably looking for this:

你可能正在寻找这个:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");

#2


18  

If called from handler of a command

如果从命令的处理程序调用

HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);

would be better, as I know.

我知道会更好。

#3


4  

I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.

我发现在将视图打开并推到后台之后需要将视图置于前面。 activate方法可以解决问题。

PlatformUI.getWorkbench()
    .getActiveWorkbenchWindow()
    .getActivePage()
    .activate(workbenchPartToActivate);

NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.

注意:workbenchPartToActivate是IWorkbenchPart的一个实例。

#4


0  

In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.

在e4中,EPartService负责打开零件。这也可用于打开e3 ViewParts。通过IEclipseContext实例化以下类,调用openPart-Method,您应该看到Eclipse内部浏览器视图。

public class Opener {
    @Inject
    EPartService partService;

    public void openPart() {
        MPart part = partService.createPart("org.eclipse.ui.browser.view");
        part.setLabel("Browser");

        partService.showPart(part, PartState.ACTIVATE);
    }
}

Here you can find an example of how this works together with your Application.e4xmi.

在这里,您可以找到一个与Application.e4xmi一起工作的示例。

#1


46  

You are probably looking for this:

你可能正在寻找这个:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");

#2


18  

If called from handler of a command

如果从命令的处理程序调用

HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);

would be better, as I know.

我知道会更好。

#3


4  

I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.

我发现在将视图打开并推到后台之后需要将视图置于前面。 activate方法可以解决问题。

PlatformUI.getWorkbench()
    .getActiveWorkbenchWindow()
    .getActivePage()
    .activate(workbenchPartToActivate);

NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.

注意:workbenchPartToActivate是IWorkbenchPart的一个实例。

#4


0  

In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.

在e4中,EPartService负责打开零件。这也可用于打开e3 ViewParts。通过IEclipseContext实例化以下类,调用openPart-Method,您应该看到Eclipse内部浏览器视图。

public class Opener {
    @Inject
    EPartService partService;

    public void openPart() {
        MPart part = partService.createPart("org.eclipse.ui.browser.view");
        part.setLabel("Browser");

        partService.showPart(part, PartState.ACTIVATE);
    }
}

Here you can find an example of how this works together with your Application.e4xmi.

在这里,您可以找到一个与Application.e4xmi一起工作的示例。