Project: Eclipse_Platform_UI
Bug 311778 [CommonNavigator] Project Explorer selects File object instead of the requested object in the Explorer tree
Reported: 2010-05-05 14:40:43 | Status: verified fixed

Build Identifier: eclipse SDK 3.6.0 M7 Build id: I20100426-0852 When we request the CommonNavigator to select a specific element on the explorer tree that is not yet visible, the Project explorer calls the convertSelection method and this changes the requested target object to the File object. Thus, the File is object is selected in Project explorer which is incorrect. Instead, it should expand the tree to show the target element first and then select this requested object. (see attached image). package org.eclipse.ui.navigator.resources; public final class ProjectExplorer extends CommonNavigator { . . . public void selectReveal(ISelection selection) { if (getCommonViewer() != null) { getCommonViewer().setSelection(convertSelection(selection), true); } } private Object convertElement(Object original) { NavigatorContentService ncs = (NavigatorContentService) getNavigatorContentService(); Object found = ncs.getViewerElementData(original); if (found != null) return original; if (original instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) original; found = adaptable.getAdapter(IResource.class); if (found != null) return found; IWorkbenchAdapter wba = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class); if (wba != null) { found = wba.getParent(original); if (found != null) return convertElement(found); } } return original; } It should not returns the adaptable.getAdapter(IResource.class) object. Reproducible: Always Steps to Reproduce: 1. Expand the tree structure just 1 level deep in the Project Explorer. The tree elements are adaptable to IResource. 2. Invoke the org.eclipse.ui.navigator.resources.ProjectExplorer.selectReveal and pass it a child object that is not yet visible (for example, the target object is 5 levels deep). Expect: the tree is expanse and select the requested element. Result: the file object is selected.

Files changed in fix:
bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ProjectExplorer.java