Q:

Eclipse RCP SourceProvider listening for changes

I have a source provider that helps to provide state for enabling buttons and menu items.  The enabling part is working correctly.  My challenge is how to get the source provider called when various editors / views are activated.
I have implemented IPartListener2 on the source provider but don't see a way to get it registered for all editors and views in a generic way.  The getPartService().addPartListerner(this) will register it but only for a specific workbench part.  Also the constructor for the Source Provider is called before any part is active so getting a valid part is not working.
What is the best way to register this Source Provider for all editors and views?
Thanks for reading my question and any assistance you can provide.

A:

Use a IWindowListener to listen for workbench windows being activated:
IWorkbench workbench = PlatformUI.getWorkbench();

workbench.addWindowListener(windowListener);

In the windowActivated method of the listener use the window part service to add a part listener for the window:
public void windowActivated(IWorkbenchWindow window)
{
   window.getPartService().addPartListener(partListener);
}

As an example see org.eclipse.jdt.internal.debug.ui.actions.ActionDelegateHelper

