Eclipse RCP allows two views to communicate

I am currently building an Eclipse-based RCP application. In one of my plugins, I add two views through the 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); 

The first view contains a treeviewer, the second contains a tableviewer. Now I want to update the contents of the tableviewer according to the choice of treeviewer. My question is, how can I reference a tableviewer from treeviewer? Or is there another way to solve this problem?

+1
source share
2 answers

In each view, define an identifier. The identifier matches the one you defined in the ID field when you defined the detail view of the extension element. Here is 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; } 

If you want to reference a view from another view, use the following code:

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

Replace your view name with PrefetchedInmatesView and your plugin name with RabidPlugin .

+3
source

Use SelectionService for this problem. No request links are required, see http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html

+8
source

Source: https://habr.com/ru/post/1339818/


All Articles