Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370781 - Combo listener behavior is not consistent across platforms
Summary: Combo listener behavior is not consistent across platforms
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 368754
  Show dependency tree
 
Reported: 2012-02-06 18:05 EST by Greg Watson CLA
Modified: 2012-03-06 08:19 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Watson CLA 2012-02-06 18:05:26 EST
We see different behavior for combo listeners on different platforms. Is this expected?

The issue is shown in the following example. On Mac/Windows, clicking on the Update button results in:

update combo
modify event

On Linux, the same code produces:

update combo
modify event
modify event
modify event
fire event that should not happen!

It seems that on Linux there is an extra event generated by the system after the button listener has finished. Are we doing something wrong? If a bug, can you suggest a workaround? 

Thanks!

----------------------------

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class ComboEventTest {

	private static Combo combo;
	private static boolean initializing = false;
	private static String[] languages = new String[] { "Java" };

	public ComboEventTest() {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout(2, true));

		combo = new Combo(shell, SWT.READ_ONLY | SWT.DROP_DOWN);

		for (int i = 0; i < languages.length; i++) {
			combo.add(languages[i]);
			combo.setData(Integer.toString(i), languages[i]);
		}

		combo.select(0);
		combo.addModifyListener(new ModifyListener() {

			public void modifyText(ModifyEvent e) {
				System.out.println("modify event");
				if (!initializing) {
					System.out.println("fire event that should not happen!");
				}
			}

		});
		Button b = new Button(shell, SWT.PUSH);
		b.setText("Update");
		b.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				updateComboSelection();
			}
		});

		shell.pack();
		shell.open();

		// Set up the event loop.
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				// If no more entries in event queue
				display.sleep();
			}
		}

		display.dispose();
	}

	private static void updateComboSelection() {
		initializing = true;
		System.out.println("update combo");
		combo.removeAll();
		for (int i = 0; i < languages.length; i++) {
			combo.add(languages[i]);
			combo.setData(Integer.toString(i), languages[i]);
		}

		combo.select(0);

		combo.getParent().layout(true);
		initializing = false;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new ComboEventTest();
	}

}
Comment 1 Greg Watson CLA 2012-02-13 12:38:55 EST
Could someone take a look at this and at least let us know if this is a known problem, or a bug and we should be looking for a workaround? Thanks!
Comment 2 Felipe Heidrich CLA 2012-02-15 11:12:39 EST
modify events in the combobox are a bit of a problem, what are you trying to do ? Maybe you could be using SWT.Selection event instead ?
Comment 3 Greg Watson CLA 2012-03-06 08:19:38 EST
SWT.Selection appears to have fixed our problem. Thanks!