Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337217 - RadioButton get selected when user clicks on a Composite created by FormToolkit
Summary: RadioButton get selected when user clicks on a Composite created by FormToolkit
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 4.1   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: platform-ua-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-15 09:41 EST by Jean-Marc CLA
Modified: 2011-02-22 13:23 EST (History)
1 user (show)

See Also:


Attachments
Example to replicate the problem (63.50 KB, application/octet-stream)
2011-02-15 09:42 EST, Jean-Marc CLA
no flags Details

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