Eclipse RCP 让两个视图通信 [英] Eclipse RCP let two views communicate

查看:20
本文介绍了Eclipse RCP 让两个视图通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个基于 Eclipse 的 RCP 应用程序.在我的一个插件中,我通过代码添加了两个视图:

I am currently building a RCP application based on Eclipse. In one of my plugins I am adding two views via code:

    layout.addView("dev.asd.tableviewer.tree", IPageLayout.LEFT, 0.25f, IPageLayout.ID_EDITOR_AREA);
    layout.addView("dev.asd.tableviewer.view", IPageLayout.RIGHT, 0.75f, IPageLayout.ID_EDITOR_AREA);

第一个视图包含一个treeviewer,第二个是tableviewer.现在我想根据treeviewer的选择来更新tableviewer的内容.我的问题是,如何从 treeviewer 中引用 tableviewer?或者有没有其他方法可以解决这个问题?

The first view contains a treeviewer, the second one a tableviewer. Now I want to update the tableviewer's content according to the selection of the treeviewer. My question is, how can I reference the tableviewer from within the treeviewer? Or is there an other way to solve this problem?

推荐答案

在每个视图中,定义一个ID.ID 与您在扩展元素详细信息中定义视图时在 ID 字段中定义的相同.这是我的一个:

In each view, define an ID. The ID is the same as what you defined in the ID field when you defined the view in the extension element details. Here's one of mine:

public static final String ID = "gov.bop.rabid.ui.views.PrefetchedInmatesView";

在您的 RCP 插件中,定义以下方法:

In your RCP plug-in, define the following method:

public static IViewPart getView(IWorkbenchWindow window, String viewId) {
    IViewReference[] refs = window.getActivePage().getViewReferences();
    for (IViewReference viewReference : refs) {
        if (viewReference.getId().equals(viewId)) {
            return viewReference.getView(true);
        }
    }
    return null;
}

当您想从不同的视图中引用视图时,请使用以下代码:

When you want to reference a view from a different view, use the following code:

PrefetchedInmatesView view = (PrefetchedInmatesView) 
                RabidPlugin.getView(window,  PrefetchedInmatesView.ID);

将您的视图名称替换为 PrefetchedInmatesView,并将您的插件名称替换为 RabidPlugin.

Substitute the name of your view for PrefetchedInmatesView, and the name of your plug-in for RabidPlugin.

这篇关于Eclipse RCP 让两个视图通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆