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

Bug 328909

Summary: Setting foreground color in EraseItem listener has no effect
Product: [Eclipse Project] Platform Reporter: Mark McLaren <mark.k.mclaren>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: RESOLVED FIXED QA Contact: Scott Kovatch <skovatch>
Severity: normal    
Priority: P3 CC: Silenio_Quarti
Version: 4.1   
Target Milestone: 3.7 M4   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
patch none

Description Mark McLaren CLA 2010-10-28 04:14:17 EDT
Build Identifier: 3.7m2

See example below.  The selected row should be drawn in red, but in 3.7m2 (unlike 3.6.1) the text is drawn in white, making the line appear 'blank'.  

Note that this bug affects the JFace features that allow the user to select a cell in the table (eg. FocusCellOwnerDrawHighlighter).

Reproducible: Always

Steps to Reproduce:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class EraseItemExample {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		final Color red = display.getSystemColor(SWT.COLOR_RED);
		final Table table = new Table(shell, SWT.FULL_SELECTION);
		table.setHeaderVisible(true);
		new TableColumn(table, SWT.NONE).setWidth(100);
		new TableColumn(table, SWT.NONE).setWidth(100);
		new TableColumn(table, SWT.NONE).setWidth(100);
		for (int i = 0; i < 5; i++) {
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText(0, "item " + i + " col 0");
			item.setText(1, "item " + i + " col 1");
			item.setText(2, "item " + i + " col 2");
		}
		table.pack();
		table.addListener(SWT.EraseItem, new Listener() {
			public void handleEvent(Event event) {
				if ((event.detail & SWT.SELECTED) != 0) {
					event.gc.setForeground(red);
					event.detail &= ~SWT.SELECTED;
				}
			}
		});

		shell.setSize(400, 300);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

	}
}
Comment 1 Mark McLaren CLA 2010-10-28 04:19:12 EDT
I should also mention my platform is Mac OSX cocoa 64 bit.
Comment 2 Lakshmi P Shanmugam CLA 2010-10-28 07:54:43 EDT
The fix for Bug 289868 has caused this. Sorry about it.
Comment 3 Lakshmi P Shanmugam CLA 2010-10-28 08:00:41 EDT
Created attachment 181925 [details]
patch

Put back the code to get the foreground color from gc.
Scott, please review.
Comment 4 Scott Kovatch CLA 2010-10-28 13:19:38 EDT
Looks good to me.
Comment 5 Lakshmi P Shanmugam CLA 2010-11-09 03:51:31 EST
Thanks Scott.
Fixed in HEAD > 20101109