Eclipse RCP let two views communicate

半世苍凉 提交于 2019-12-01 00:59:47

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";

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);

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

Use the SelectionService for this issue. No referencing of views required, see http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!