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

Bug 337217

Summary: RadioButton get selected when user clicks on a Composite created by FormToolkit
Product: [Eclipse Project] Platform Reporter: Jean-Marc <jmp>
Component: User AssistanceAssignee: platform-ua-inbox <platform-ua-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: cgold
Version: 4.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Example to replicate the problem none

Description Jean-Marc CLA 2011-02-15 09:41:08 EST
Build Identifier: Build id: 20100218-1602

In this scenario, none of the radio button are selected by default.

If the radio button are on a Composite created by new Composite, then it all works as expected.


If the radio button are on a Composite created by toolkit.createComposite, then if you clock anywhere on the composite, the first radio button will be selected.

I believe this is because the adapt() method in the FormToolkit add a MouseDown listener to the Composite. The listener then call setFocus on the first control of the form. If this is a radio button in a group where there is no selection, the first button gets selected.

Suggest to not calll setFocus() in that particular context, or use forceFocus on the Composite itself.


Reproducible: Always

Steps to Reproduce:
Attaching code sample project com.jmp.demo.project.zip. Code is in ApplicationWorkbenchWindowAdvisor::createWindowContents( shell ).
Comment 1 Jean-Marc CLA 2011-02-15 09:42:48 EST
Created attachment 189001 [details]
Example to replicate the problem

See code in ApplicationWorkbenchWindowAdvisor::createWindowContents(Shell shell).
Comment 2 Chris Goldthorpe CLA 2011-02-21 15:23:36 EST
This is working as designed. Composites and other controls created by FormToolkit are "adapted" which involves setting the background color and adding a mouse down listener which sets focus. If you want to set the background but not add the listener you can use this kind of sequence:

    Composite rbc2 = new Composite(parent, SWT.BORDER);
    toolkit.adapt(rbc2, false, false);
Comment 3 Jean-Marc CLA 2011-02-22 11:39:59 EST
I would argue the problem is with the `mouse down listener which sets focus`.

If the controls on the composite are radio button, and none are selected, setting the focus on a radio button of the group will select the first radio button which is not what the user intended. 

I would suggest that in that particular case, no focus change is made.

Thoughts ?
Comment 4 Chris Goldthorpe CLA 2011-02-22 12:12:23 EST
I don't want to change the current behavior because that would affect the way existing applications work. I agree with you that in the case of Radio buttons this causes some odd side effects but there is a workaround. I did not write the original code and had I done so I probably would not have added the mouse click listener, having said that I would rather leave the current behavior as is since it has been that way for a long time.
Comment 5 Jean-Marc CLA 2011-02-22 13:23:31 EST
Understood...

That is a better answer than `working as designed`. Work around does not quite work with us for some other reasons, but feel free to close.

Thanks

JM