Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 295319

Summary: Table: Background color not drawn with empty EraseItem-Listener
Product: [Eclipse Project] Platform Reporter: Martin Platter <martin.platter>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Felipe Heidrich <eclipse.felipe>
Severity: normal    
Priority: P3 CC: eclipse.felipe, tom.schindl
Version: 4.0Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug
Attachments:
Description Flags
Screenshot show how background color of the first line in the table is not painted correctly none

Description Martin Platter CLA 2009-11-17 04:57:36 EST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5
Build Identifier: 3.5.1.v3555a

The correct background color of the TableItem is not drawn if (empty)EraseItem-Listener is added to a table.

Reproducible: Always

Steps to Reproduce:
public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		shell.setBounds(10,10,200,200);
		shell.setLayout(new FillLayout());
		
		TableViewer tv = new TableViewer(shell, SWT.MULTI | SWT.FULL_SELECTION);
		Table table = tv.getTable();

		table.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        table.setHeaderVisible(false);
        table.setLinesVisible(true);
        tv.setContentProvider(new ArrayContentProvider());
        
        class lbp extends LabelProvider implements ITableColorProvider {
			public Color getBackground(Object element, int columnIndex) {
					return new Color(display, 255, 255,255);
			}
			public Color getForeground(Object element, int columnIndex) {
				return null;
			}
        }
        tv.setLabelProvider(new lbp());
        
        table.addListener(SWT.EraseItem, new Listener() {
        	private int count = 1;
			public void handleEvent(Event event) {
			}
        });
        
        TableColumn text = new TableColumn(table, SWT.LEFT, 0);
		text.setWidth(800);

//		table.setSelection(0);
//		table.deselect(0);
		tv.setInput(new String[]{"Hoi!", "Pfiati!"});

		shell.layout(true, true);
		shell.update();
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();

	}
Comment 1 Martin Platter CLA 2009-11-17 05:34:00 EST
Created attachment 152375 [details]
Screenshot show how background color of the first line in the table is not painted correctly
Comment 2 Felipe Heidrich CLA 2009-11-17 09:24:06 EST
I suspect this is a JFace problem.

Note: if you hook paintitem/measureitem/eraseitem the table becomes custom draw, it doesn't matter if the listener is empty or not.
Comment 3 Thomas Schindl CLA 2009-11-17 09:48:52 EST
Not sure what what JFace should do here. We are simply calling TableItem#setBackground(). Maybe it would help if we could get a SWT only snippet which shows the problem.
Comment 4 Felipe Heidrich CLA 2009-11-17 09:58:18 EST
(In reply to comment #3)
> Not sure what what JFace should do here. We are simply calling
> TableItem#setBackground(). 

I noticed the label provider has getBackground(), I don't know what that does to the table.


> Maybe it would help if we could get a SWT only
> snippet which shows the problem.

Agree.
Comment 5 Thomas Schindl CLA 2009-11-17 10:16:17 EST
(In reply to comment #4)
> (In reply to comment #3)
> > Not sure what what JFace should do here. We are simply calling
> > TableItem#setBackground(). 
> 
> I noticed the label provider has getBackground(), I don't know what that does
> to the table.
> 

Well we have 2 methods here:
----------------------------
LabelProvider#getBackground(Object)
ITableColorProvider#getBackground(Object,int)

If TableViewer finds a IITableColorProvider it calls ITableColorProvider#getBackground(Object,int) foreach TableItem-Index and calls TableItem#setBackground(Color,int) else it calls LabelProvider#getBackground(Object) and calls TableItem#setBackground(Color,int) for all indices.
Comment 6 Thomas Schindl CLA 2009-11-17 10:24:10 EST
(In reply to comment #5)
> (In reply to comment #4)
> > (In reply to comment #3)
> > > Not sure what what JFace should do here. We are simply calling
> > > TableItem#setBackground(). 
> > 
> > I noticed the label provider has getBackground(), I don't know what that does
> > to the table.
> > 
> 
> Well we have 2 methods here:
> ----------------------------
> LabelProvider#getBackground(Object)
> ITableColorProvider#getBackground(Object,int)
> 
> If TableViewer finds a IITableColorProvider it calls
> ITableColorProvider#getBackground(Object,int) foreach TableItem-Index and calls
> TableItem#setBackground(Color,int) else it calls
> LabelProvider#getBackground(Object) and calls
> TableItem#setBackground(Color,int) for all indices.

Just to mention the code above leaks resources :-)
Comment 7 Felipe Heidrich CLA 2009-11-18 14:12:29 EST
this is SWT:
public static void main (String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);

    TableColumn column = new TableColumn(table, SWT.LEFT, 0);
    column.setWidth(800);
    for (int i = 0; i < 4; i++) {
    	TableItem item = new TableItem(table, SWT.NONE);
    	item.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
    	item.setText("Item " + i);
    }
    table.addListener(SWT.EraseItem, new Listener() {
        public void handleEvent(Event event) {
        }
    });
    shell.setBounds(10,10,300,200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}

----
custom draw table when drawing the focus item only fills the cell background to the extent of the content (instead of the column).
Comment 8 Felipe Heidrich CLA 2009-11-23 10:49:57 EST
(In reply to comment #7)
> custom draw table when drawing the focus item only fills the cell background to
> the extent of the content (instead of the column).

the same problem also happens when the table is not custom draw and not full selection, see bug 295869.
Comment 9 Leo Ufimtsev CLA 2017-08-03 12:33:33 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 10 Eclipse Genie CLA 2020-04-22 05:54:10 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.