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 开发者_C百科no such method.
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);
精彩评论