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

Bug 320636

Summary: [Custom Widgets] CCombo setFocus does not work
Product: [Eclipse Project] Platform Reporter: Martin Kalina <martin.kalina>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4, martin.kalina, oleg.v.danilov
Version: 4.0   
Target Milestone: 3.7 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
patch none

Description Martin Kalina CLA 2010-07-22 10:18:18 EDT
Build Identifier: M20100211-1343

When trying to set initial focus on a CCombo during creation of cotrols, it does not work. The reason is IMHO that it does not override forceFocus() method, which is used when restoring saved focus from shell. 

Reproducible: Always
Comment 1 Lakshmi P Shanmugam CLA 2011-02-04 06:44:02 EST
Snippet showing the problem:

public class Bug320636 {
	public static void main(String[] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		Text textbox = new Text(shell, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
		textbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		textbox.setText("textbox");
		CCombo combo = new CCombo(shell,  SWT.FLAT | SWT.BORDER);
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		for (int i = 0; i < 5; i++) {
			combo.add("item" + i);
		}
		combo.setText("item0");
		combo.setFocus ();
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Comment 2 Lakshmi P Shanmugam CLA 2011-02-04 06:52:05 EST
Created attachment 188310 [details]
patch

CCombo.setFocus() should set focus on the text and this happens when text.setFocus() is called. But, we return before text.setFocus() is called because the CCombo's parent is not yet visible and isVisible() returns false.

The patch uses getVisible() instead of isVisible().

Carolyn, can you please review the patch?
Comment 3 Carolyn MacLeod CLA 2011-02-08 16:23:09 EST
Looks good, Lakshmi - go for it!
Comment 4 Lakshmi P Shanmugam CLA 2011-02-09 06:05:11 EST
Thanks Carolyn!
Fixed in HEAD > 20110209