* @param notify whether to send notification that the selection has changed.
*/
private void setPart(IWorkbenchPart part, boolean notify) {
if (fPart != null) {
// remove myself as a listener from the existing part
ISelectionProvider sp = fPart.getSite().getSelectionProvider();
if (sp != null) {
sp.removeSelectionChangedListener(selectionListener);
if (sp instanceof IPostSelectionProvider) {
((IPostSelectionProvider) sp)
.removePostSelectionChangedListener(postSelectionListener);
} else {
sp.removeSelectionChangedListener(postSelectionListener);
}
}
}
fPart = part;
ISelection sel = null;
if (part != null) {
ISelectionProvider sp = part.getSite().getSelectionProvider();
if (sp != null) {
sp.addSelectionChangedListener(selectionListener);
if (sp instanceof IPostSelectionProvider) {
((IPostSelectionProvider) sp)
.addPostSelectionChangedListener(postSelectionListener);
} else {
sp.addSelectionChangedListener(postSelectionListener);
}
if (notify) {
// get the selection to send below
sel = sp.getSelection();
}
}
}
if (notify) {
fireSelection(part, sel);