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

Bug 333386

Summary: Inconsistent behavior of Combo#setItems() on MacOSX Cocoa
Product: [Eclipse Project] Platform Reporter: Alexander Nyßen <nyssen>
Component: SWTAssignee: Scott Kovatch <skovatch>
Status: RESOLVED FIXED QA Contact: Silenio Quarti <Silenio_Quarti>
Severity: normal    
Priority: P3 CC: skovatch
Version: 3.6.1   
Target Milestone: 3.7 M5   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Bug Depends on:    
Bug Blocks: 300837    

Description Alexander Nyßen CLA 2011-01-02 14:20:38 EST
Using the following snippet, one may observe that using Combo#setItems to set items on a combo (with an already selected item) will cause a selection event to occor on MacOSX Cocoa. This event does not occur on Windows XP; it does also not occur if no item is selected on the combo.

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.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Bug300837 {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		final Combo combo = new Combo(shell, SWT.DROP_DOWN);
		combo.setItems(new String[] { "1", "2", "3" });

		combo.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				System.out.println("widget selected " + e);
			};

			public void widgetDefaultSelected(SelectionEvent e) {
				System.out.println("widget default selected " + e);
			}
		});
		combo.select(1); // if not selecting an item here, the selection event,
							// mentioned below, will not occur
		combo.setItems(new String[] { "1", "2", "3" }); // this will cause a
														// selection event on
														// MacOSX Cocoa, while
														// it does not on
														// Windowx XP

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

This is the cause for bug 300837, which depends on not receiving a respective selection event, so I think the behavior on other platforms may be that of Windows XP (while not having verified this).
Comment 1 Scott Kovatch CLA 2011-01-02 16:12:46 EST
This wouldn't surprise me. We had a similar bug in List, Table and Tree. Cocoa always sends a notification when the selected item changes, no matter how it changes (index in the list or otherwise.)
Comment 2 Scott Kovatch CLA 2011-01-04 12:33:12 EST
Fixed > 20110103. Combo#setItems, as well as removeAll, can fire a selection event. Only fire selection events on user action.