Search code examples
eventsfocusprojectrcpexplorer

Eclipse RCP Project Explorer focus event


Is there a way to detect when the user makes focus on the Project Explorer window in a RCP application? Is there an event I could use?

I researched and found that Project Explorer's id is org.eclipse.ui.navigator.ProjectExplorer but I still didn't find any solution to my problem.


Solution

  • You can use org.eclipse.ui.IPartListener to listen for changes to which part is active (and several other events).

    You call the IPartService addPartListener method to set this up. You can get the part service in several ways depending on where you code is running. One of these is:

    IPartService partService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
    
    partService.addPartListener(listener);