In Eclipse RCP, I am creating views for the Perspective using IPageLayout.addView(...)
But this way I don't have a reference to the view. Therefore I don't know how I can tell ViewA to update ViewB.
What's the best pattern to use here?
In Eclipse RCP, I am creating views for the Perspective using IPageLayout.addView(...)
But this way I don't have a reference to the view. Therefore I don't know how I can tell ViewA to update ViewB.
What's the best pattern to use here?
You have the different communication paradigm summarize in the IBM article
ISelectionListener
interface and must register itself with the workbench pageIAdaptable
interface: A class that implements IAdaptable
has the capability to dynamically return certain types of adapters that can then be used to retrieve further information.Regarding the first approach, the article details:
A smarter way to consume UI selections is to register the consumer views as listeners to specific view parts. As you can see in the example below, the view ID of the source view part is mentioned as a parameter during registering a selection listener.
getSite().getPage().addSelectionListener("SampleViewId",(ISelectionListener)this);
This approach will eliminate the redundant callbacks to the consumer view that would otherwise occur if that view were registered as a nonspecific listener.
The code snippet in Listing 2 shows the
createPartControl()
method of a view that creates aJFace
TableViewer
and adds it as a selection provider to the workbench site. This code enables any UI selection changes in theTableViewer
to propagate to the page and finally to the interested consumer views.Listing 2. Setting up a selection provider
public void createPartControl(Composite parent) {
// Set up a JFace Viewer
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(getViewSite());
// ADD the JFace Viewer as a Selection Provider to the View site.
getSite().setSelectionProvider(viewer);
}
You will find a similar approach in the RCP tutorial for eclipse3.5 (update February, 4th 2010)
Besides what VonC has mentioned above, you can also use ISourceProviderListener
if the changes you need are not triggered by selection.
ViewB
implements ISourceProviderListener
ISourceProvider
and register it in the servicesViewA
get the ISourceProvider
and update it to trigger the changes in ViewB
Read the documentation on those interfaces along with IServiceLocator
and ISourceProviderService
to get better idea how it all plays out.
You can also see this Lars Vogel's tutorial which has some example how to use the ISourceProvider