Project: Eclipse_Platform_UI
Bug 184712 [Viewers] Label provider of a tree vewier is not called
Reported: 2007-04-30 11:21:36 | Status: verified fixed

Build ID: Eclipse 3.3 M6 Steps To Reproduce: I created a tree viewer on eclipse 3.2, same viewer doesn't work on eclipse 3.3 (The labels and Images are gone). I set a break point in my label provider, it is not called. I have 2 viewers on my page, one is tree viewer and another one is table viewer, the label provider is shared. It implements both of ILabelProvider and ITableLabelProvider. On the new eclipse 3.3 driver, I have to comment out the part of ITableLabelProvider. More information: Here is the example: import java.util.ArrayList; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; public class TreeViewerTest { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); createDialogArea(shell); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } protected static Control createDialogArea(Composite parent) { SummaryInfoLabelProvider lProvider = new SummaryInfoLabelProvider(); SummaryInfoContentProvider cProvider = new SummaryInfoContentProvider(); Composite primary = new Composite(parent, SWT.NONE); primary.setLayout(new GridLayout()); primary.setLayoutData(new GridData(GridData.FILL_BOTH)); // create summary tree Tree tree = new Tree(parent, SWT.BORDER); TreeViewer summaryViewer = new TreeViewer(tree); GridData gd = new GridData(GridData.FILL_BOTH); GridLayout layout = (GridLayout)parent.getLayout(); if(layout != null) gd.horizontalSpan = layout.numColumns; tree.setLayoutData(gd); summaryViewer.setLabelProvider(lProvider); summaryViewer.setContentProvider(cProvider); ArrayList input = new ArrayList(); for(int i = 0; i < 10; i ++) { StringBuffer name = new StringBuffer("TreeNode ").append(i); input.add(name); } summaryViewer.setInput(input); return (primary); } public static class SummaryInfoLabelProvider extends LabelProvider implements ITableLabelProvider { /* (non-Javadoc) * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) */ public Image getImage(Object element) { return null; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) */ public String getText(Object element) { return element.toString(); } public Image getColumnImage(Object element, int columnIndex) { return null; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) */ public String getColumnText(Object element, int columnIndex) { return ""; } } public static class SummaryInfoContentProvider implements ITreeContentProvider { /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) */ public Object[] getChildren(Object parentElement) { if(parentElement instanceof ArrayList) return ((ArrayList)parentElement).toArray(); return new Object[0]; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) */ public Object getParent(Object element) { return null; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) */ public boolean hasChildren(Object element) { return getChildren(element).length > 0; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ public Object[] getElements(Object inputElement) { return getChildren(inputElement); } /* (non-Javadoc) * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public void dispose() { } } }

Files changed in fix:
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CellLabelProvider.java bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/SimpleTreeViewerTest.java