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

查看:741
本文介绍了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,第二个是viewviewer。现在我想根据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字段中定义的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天全站免登陆