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

Bug 330299

Summary: Tree default selection event doesn't have item field set
Product: [Eclipse Project] Platform Reporter: Mark McLaren <mark.k.mclaren>
Component: SWTAssignee: Scott Kovatch <skovatch>
Status: RESOLVED FIXED QA Contact: Silenio Quarti <Silenio_Quarti>
Severity: normal    
Priority: P3 CC: skovatch
Version: 4.1   
Target Milestone: 3.7 M4   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Mark McLaren CLA 2010-11-15 18:01:48 EST
Build Identifier: 3.7m3

Run example snippet below, select a tree item and press Enter - the 'item' field of the Event object is null.  

Reproducible: Always

Steps to Reproduce:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class TestTreeDefaultSelection {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		final Tree tree = new Tree(shell, SWT.BORDER);
		for (int i = 0; i < 4; i++) {
			TreeItem iItem = new TreeItem(tree, 0);
			iItem.setText("TreeItem (0) -" + i);
			for (int j = 0; j < 4; j++) {
				TreeItem jItem = new TreeItem(iItem, 0);
				jItem.setText("TreeItem (1) -" + j);
				for (int k = 0; k < 4; k++) {
					TreeItem kItem = new TreeItem(jItem, 0);
					kItem.setText("TreeItem (2) -" + k);
				}
			}
		}
		tree.addSelectionListener(new SelectionListener() {
			public void widgetDefaultSelected(SelectionEvent e) {
				System.out.println("Item Default: " + e.item);
			}

			public void widgetSelected(SelectionEvent e) {
				System.out.println("Item Selected: " + e.item);

			}
		});
		shell.setSize(200, 200);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 1 Scott Kovatch CLA 2010-11-16 12:37:18 EST
fixed > 20101116. Return/enter handling wasn't looking for the selected item.