Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320636 - [Custom Widgets] CCombo setFocus does not work
Summary: [Custom Widgets] CCombo setFocus does not work
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-22 10:18 EDT by Martin Kalina CLA
Modified: 2011-03-11 11:01 EST (History)
3 users (show)

See Also:


Attachments
patch (831 bytes, patch)
2011-02-04 06:52 EST, Lakshmi P Shanmugam CLA
no flags Details | Diff

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