Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 288565 - [Widgets] Table shows wrong text in second and third columns
Summary: [Widgets] Table shows wrong text in second and third columns
Status: RESOLVED DUPLICATE of bug 228695
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Bogdan Gheorghe CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-03 16:23 EDT by Grant Gayed CLA
Modified: 2011-03-09 10:31 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Gayed CLA 2009-09-03 16:23:16 EDT
From the newsgroup, appears to be an swt problem because of platform difference.  The cell.getColumnIndex() invocations in update() seem to be getting the correct value.  Note that StyledCellLabelProvider uses custom draw, maybe we're sending some events with incorrect field values?

/**
 * This class demonstrates a problem with Eclipse Gtk and SWT on Linux. By 
contrast, the same exact code works fine on Windows.
 * The Linux platform is: CentOS 5, GNOME 2.16.0, Eclipse RCP/Plug-in 
Developers (Eclipse 3.5), Eclipse Build ID: 20090619-0625
 * The Windows platform is: Windows XP SP3, Eclipse RCP/Plug-in Developers 
(Eclipse 3.5), Eclipse Build ID: 20090619-0625
 * A simple 3-row, 3-column table is displayed in a window on the screen. 
 * Each cell in the table has its text set to "Row # Column #". 
 * On Windows, this looks like:
 * Row 0 Column 0 | Row 0 Column 1 | Row 0 Column 2
 * Row 1 Column 0 | Row 1 Column 1 | Row 1 Column 2
 * Row 2 Column 0 | Row 2 Column 1 | Row 2 Column 2
 * This is correct.
 * 
 * However, on Linux, this looks like:
 * Row 0 Column 0 | Row 0 Column 0 | Row 0 Column 0
 * Row 1 Column 0 | Row 1 Column 0 | Row 1 Column 0
 * Row 2 Column 0 | Row 2 Column 0 | Row 2 Column 0
 * This is NOT correct. The text values in the first column are being 
repeated in the 2nd and 3rd column.
 * Why is this happening?
 *  
 */

import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
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.Table;
import org.eclipse.swt.widgets.TableColumn;

public class ExampleProblem {
    
    private static Display DISPLAY = Display.getDefault(); 
    
    public static void main(String[] args) {

        Shell shell = new Shell(DISPLAY, SWT.CLOSE | SWT.RESIZE);
        shell.setSize(400, 400);
        shell.setLayout(new GridLayout(1, false));

        ExampleProblem example = new ExampleProblem();
        Control composite = example.createPartControl(shell);
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, 
true, 1, 1));
        
        shell.open();

        while (!shell.isDisposed()) {
            if (!DISPLAY.readAndDispatch()) {
                DISPLAY.sleep();
            }
        }
        DISPLAY.dispose();
    }

    public ExampleProblem() {
    }

    public Composite createPartControl(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);

        TableColumnLayout tcLayout = new TableColumnLayout();
        
        composite.setLayout(tcLayout);
        
        final TableViewer tableViewer = new TableViewer(composite, 
SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        
        Table table = tableViewer.getTable();
         
        TableColumn firstColumn = new TableColumn(table, SWT.LEFT);
        firstColumn.setText("First Column");
        tcLayout.setColumnData(firstColumn, new ColumnWeightData(1));
        
        TableColumn secondColumn = new TableColumn(table, SWT.LEFT);
        secondColumn.setText("Second Column");
        tcLayout.setColumnData(secondColumn, new ColumnWeightData(1));
        
        TableColumn thirdColumn = new TableColumn(table, SWT.LEFT);
        secondColumn.setText("Third Column");
        tcLayout.setColumnData(thirdColumn, new ColumnWeightData(1));
        
        ExampleLabelProvider labelProvider = new ExampleLabelProvider();
        FileSystemContentProvider contentProvider= new 
FileSystemContentProvider();
        
        tableViewer.setContentProvider(contentProvider);
        tableViewer.setLabelProvider(labelProvider);

        GridData data = new GridData(GridData.FILL, GridData.FILL, true, 
true);
        tableViewer.getControl().setLayoutData(data);
        tableViewer.setInput(new Object());

        return composite;
    }
    
    private static class ExampleLabelProvider extends 
StyledCellLabelProvider {

        private static final Image IMAGE1 = new Image(DISPLAY, 
DISPLAY.getSystemImage(SWT.ICON_WARNING).getImageData().scaledTo(16, 16));
        private static final Image IMAGE2 = new Image(DISPLAY, 
DISPLAY.getSystemImage(SWT.ICON_ERROR).getImageData().scaledTo(16, 16));

        public ExampleLabelProvider() {
        }
        
        public void update(ViewerCell cell) {
            // On Linux, the second and third cells contain the text of the first cell --> INCORRECT
            // On Windows, the second and third cells contain the correct text
            // However, the image is NOT repeated on Linux or Windows (correct behavior on both platforms)
            cell.setText((String)cell.getElement() + " Column " + 
cell.getColumnIndex());
            if (cell.getColumnIndex() == 0) {
                cell.setImage(IMAGE1);
            } else if (cell.getColumnIndex() == 1) {
                cell.setImage(IMAGE2);
            } else {
                cell.setImage(IMAGE2);
            }
            super.update(cell);
        }
    }

    private static class FileSystemContentProvider implements 
IStructuredContentProvider {

        public Object[] getElements(Object element) {
            Object[] objArr = new Object[3];
            for (int i = 0; i < objArr.length; i++) {
                objArr[i] = "Row " + i + ": ";
            }
            return objArr;
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object 
newInput) {
        }
    }
}
Comment 1 Remy Suen CLA 2009-09-03 22:43:48 EDT
From my analysis of the problem, the TableItem is setting and getting the right text. Hence, it is likely the same problem as bug 257919 which supposedly is caused by bug 228695.
Comment 2 Bogdan Gheorghe CLA 2009-09-24 17:04:29 EDT
This was caused by 228695, fixed in HEAD > 20090924.

*** This bug has been marked as a duplicate of bug 228695 ***
Comment 3 Chris McGee CLA 2011-03-09 10:31:26 EST
I witnessed a very similar problem on ubunu Linux 10.04 and I can confirm that the problem has been fixed as of eclipse 3.6.2.