* Adds workbench listeners. This will give us control over workbench events that drive the
* view's contents. Eg. workbench selection, view activation, etc.
*/
private void addWorkbenchListeners() {
final IWorkbenchPartSite partSite = getSite();
final ISelectionService selectionService = partSite.getWorkbenchWindow()
.getSelectionService();
// Add workbench selection listener
workbenchSelectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(part instanceof DocumentView)) {
handleWorkbenchSelection(selection);
}
}
};
selectionService.addPostSelectionListener(workbenchSelectionListener);
// Add workbench part listener
workbenchPartListener = new IPartListener() {
@Override
public void partOpened(IWorkbenchPart part) {
if (part instanceof DocumentView) {
handleWorkbenchSelection(selectionService.getSelection());
}
}
@Override
public void partDeactivated(IWorkbenchPart part) {
// Nothing
}
@Override
public void partClosed(IWorkbenchPart part) {
// Nothing
}
@Override
public void partBroughtToTop(IWorkbenchPart part) {
// Nothing
}
@Override
public void partActivated(IWorkbenchPart part) {
isActive = (part instanceof DocumentView);
}
};
partSite.getPage().addPartListener(workbenchPartListener);
}