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

Bug 209975

Summary: On GTK PopupList throws an exception while open if the parent window closes. PopupList also fails to gain focus on open.
Product: [Eclipse Project] Platform Reporter: Jason Safavi <jason.safavi>
Component: SWTAssignee: Xi Yan <xixiyan>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4, dave.smith, ericwill, gheorghe, peter, pinnamur, Silenio_Quarti, xixiyan
Version: 3.4Keywords: triaged
Target Milestone: 4.9 M2   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/124491
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=3a449ba573dc88c6875f0f7ccd6b3a19476b0468
Whiteboard:
Attachments:
Description Flags
Patch v01 none

Description Jason Safavi CLA 2007-11-15 11:09:00 EST
Build ID: 3.3

Steps To Reproduce:
See attached code snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.custom.PopupList;
import org.eclipse.swt.graphics.Rectangle;

public class List
{
	public List()
	{
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Test");
		GridLayout layout = new GridLayout(4, false);
		shell.setLayout(layout);
		field1 = new Text(shell, SWT.SINGLE);
		field2 = new Text(shell, SWT.SINGLE);

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

	private FocusAdapter focus = new FocusAdapter() {
		public void focusGained(FocusEvent e) { }
		public void focusLost(FocusEvent e)
		{
			list = new PopupList(field1.getShell());
			String[] items = {"item 1", "item 2", "item 3"};
			list.setItems(items);
			Rectangle rect = new Rectangle(0, 0, 100, 100);
			list.open(rect);
		}
	};

	public static void main(String args[])
	{
		new List();
	}

	private Text field1;
	private Text field2;
	private PopupList list;
}

More information:
The PopupList fails to gain focus when it opens.
Comment 1 Praveen CLA 2010-01-05 09:23:55 EST
Created attachment 155329 [details]
Patch v01

I couldn't reproduce the scenario where opening the popupList throws an exception when it's parent closes. However, I've noticed that the popupList doesn't not take focus when it is opened in the FocusListener of a different widget. Since there is an inconsistency in popupList taking focus, I had added code changes that might set the focus to popupList in required scenarios.

Bogdan, Please review the patch. Thanks.
Comment 2 Praveen CLA 2011-02-28 01:44:08 EST
Bog/Silenio, Would it be possible to review this simple patch ?
Comment 3 Eric Williams CLA 2018-05-14 13:48:50 EDT
Still reproducible on 4.8 M7, GTK3.22, and Fedora 28.
Comment 4 Eclipse Genie CLA 2018-06-13 15:30:35 EDT
New Gerrit change created: https://git.eclipse.org/r/124491
Comment 6 Eric Williams CLA 2018-06-15 11:12:32 EDT
(In reply to Eclipse Genie from comment #5)
> Gerrit change https://git.eclipse.org/r/124491 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=3a449ba573dc88c6875f0f7ccd6b3a19476b0468

In master now, thanks Xi.