Bug 311778 [CommonNavigator] Project Explorer selects File object instead of the requested object in the Explorer tree
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.
bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ProjectExplorer.java
private String workingSetLabel;
	public void createPartControl(Composite aParent) {
		super.createPartControl(aParent);
		
		if (!false)
			getCommonViewer().setMapper(new ResourceToItemsMapper(getCommonViewer()));
	}	
	
	/**
	 * The superclass does not deal with the content description, handle it
	 * here.
	 * 
	 * @noreference
	 */
	public void updateTitle() {
		super.updateTitle();
		Object input = getCommonViewer().getInput();
		if (input == null || input instanceof IAggregateWorkingSet) {
			setContentDescription(""); 
			return;
		}
		if (!(input instanceof IResource)) {
			if (input instanceof IAdaptable) {
				IWorkbenchAdapter wbadapter = (IWorkbenchAdapter) ((IAdaptable) input)
						.getAdapter(IWorkbenchAdapter.class);
				if (wbadapter != null) {
					setContentDescription(wbadapter.getLabel(input));
					return;
				}
			}