views:

15

answers:

1

I'm writing a plugin for a poorly-documented Eclipse RCP application and I need to add a listener to what I believe is a TreeViewer within a view. I have access to the IWorkbenchPart representing the view, but how can I get the TreeViewer it contains? I'd guess I need a method to return the child components (i.e. something equivalent to AWT's getComponents() method), but I see no such method.

A: 

If the part contains a TreeViewer then it is likely that this viewer been set as the ISelectionProvider for the IWorkbenchSite containing the view.

Therefore you could try the following using the IViewPart reference that you have:

IViewPart; // Your reference to the IViewPart instance

ISelectionProvider provider = part.getSite().getSelectionProvider(); //Hopefully the TreeViewer

provider.addSelectionChangedListener(yourListener);
tbone