// get all the view and editor parts
final List<IWorkbenchPart> parts = Lists.newArrayList();
IWorkbenchPartReference refs[] = page.getViewReferences();
for (int i = 0; i < refs.length; i++) {
final IWorkbenchPart part = refs[i].getPart(false);
if (part != null) {
parts.add(part);
}
}
refs = page.getEditorReferences();
for (int i = 0; i < refs.length; i++) {
if (refs[i].getPart(false) != null) {
parts.add(refs[i].getPart(false));
}
}
final ISelection selection = new StructuredSelection(resource);
final Iterator<IWorkbenchPart> itr = parts.iterator();
while (itr.hasNext()) {
final IWorkbenchPart part = itr.next();
// get the part's ISetSelectionTarget implementation
ISetSelectionTarget target = null;
if (part instanceof ISetSelectionTarget) {
target = (ISetSelectionTarget) part;
} else {
target = (ISetSelectionTarget) part.getAdapter(ISetSelectionTarget.class);
}
if (target != null) {
// select and reveal resource
final ISetSelectionTarget finalTarget = target;