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

发布于 2024-07-06 08:28:50 字数 160 浏览 6 评论 0原文

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

我认为工作台单例中会有一些东西可以处理这个问题,但我还没有在任何地方找到如何处理。

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ゞ记忆︶ㄣ 2024-07-13 08:28:50

您可能正在寻找这个:

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

You are probably looking for this:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");
桃扇骨 2024-07-13 08:28:50

据我所知,如果从命令的处理程序调用

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

会更好。

If called from handler of a command

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

would be better, as I know.

野侃 2024-07-13 08:28:50

我发现需要在视图打开并推到后台后将其带到前面。 activate 方法就可以解决这个问题。

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

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

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.

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

NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.

迷途知返 2024-07-13 08:28:50

在e4中,EPartService负责打开Part。 这也可用于打开 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);
    }
}

在这里您可以找到一个示例,说明它如何与您的应用程序一起使用。 e4xmi。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文