Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333386 - Inconsistent behavior of Combo#setItems() on MacOSX Cocoa
Summary: Inconsistent behavior of Combo#setItems() on MacOSX Cocoa
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Scott Kovatch CLA
QA Contact: Silenio Quarti CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 300837
  Show dependency tree
 
Reported: 2011-01-02 14:20 EST by Alexander Nyßen CLA
Modified: 2011-01-25 16:37 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.