Bug 255793 [CommonNavigator] [CNF] Chosen label provider should match content provider
Build ID: I20080918-0100 Steps To Reproduce: 1. Create 2 "org.eclipse.ui.navigator.navigatorContent" extension to provide "similar" content but needed to show different "labels" 2. Your trigger points will indicate "which types of nodes in the tree might be interesting to our extension"(M. Elder) 3. Implement your 2 content providers with the ITreePathContentProvider and use that to find out if you should provide content based on the initial content "root" of your extension point. Otherwise the content here should be the same (for the test) 4. Code your label provider to return different text/images for the same content 4. Run you explorer 5. You will notice that the content will end up coming from one label provider for both extension point. More information: In the NavigatorServiceContentLabelProvider, in the getStyledText(Object anElement) method, the label provider is determined from all the content provider with possible children and the first to return a label "wins" the race. The problem is that we define an extension point with a pair of provider (content and label) that are both required and thus would be expected to work in tandem. Here the first selected label provider will get the object and since it is one that it understands it will return a label for it. There is no way for this provider to know where the object is in the tree or who provided content for it. The label provider is a very focused class related to its content provider and responsible only to provide labels for such content. The CNF should keep track of which provider provided each element of content in the tree and delegate the label request to its paired label provider. There is no need to go around label providers to see who wants what. By definition from the extension point, content and label are required and paired.
tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/LabelProviderTest.java
private static final boolean DEBUG = false;
	public LabelProviderTest() {
		_navigatorInstanceId = "org.eclipse.ui.tests.navigator.OverrideTestView";
	}
	
	public void testSimpleResFirst() throws Exception {
		_contentService.bindExtensions(new String[] { TEST_CONTENT_OVERRIDDEN1,
				TEST_CONTENT_OVERRIDE1 }, false);
		_contentService.getActivationService().activateExtensions(
				new String[] { TEST_CONTENT_OVERRIDE1, TEST_CONTENT_OVERRIDDEN1 }, true);
		refreshViewer();
		TreeItem[] rootItems = _viewer.getTree().getItems();
		if (DEBUG) {
			DisplayHelper.sleep(Display.getCurrent(), 10000000);
		}
		if (!rootItems[0].getText().startsWith("Green"))
			fail("Wrong text: " + rootItems[0].getText());
		assertEquals(TestLabelProviderGreen.getTestColor(), rootItems[0]
				.getBackground(0));
	}