Ever wanted to just listen to selection events from a single IWorkbenchPart like the ‘Outline’ view? Well, org.eclipse.ui.ISelectionService is just what you need. In your own IWorkbenchPart where a call to getSite() is valid (say like in your createPartControl(Composite) method), you can use getSite().getWorkbenchWindow().getSelectionService() to get an ISelectionService. From there, you can invoke addSelectionListener(String, ISelectionListener).
To listen to selection changes from the ‘Outline’ view, all you’d need to do is pass in org.eclipse.ui.IPageLayout.ID_OUTLINE to the first parameter of the method and you’re gold. No more funky instanceof checks for those ISelections and more conditional checks for what they contain and your implementing method also isn’t called a gazillion times whenever something’s happened in the workbench. Keeps the code clean and “improved” performance thanks to it not being called all the time, you’ve just killed two birds with one stone!
Before I sign off, I’d like to remind you all to not forget about removing your ISelectionListener with removeSelectionListener(String, ISelectionListener)! Invoking the call in your dispose() method should be good. Enjoy! :)