You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If a dialog contains radio buttons and a button for opening a file dialog, after selecting the second radio button and opening and closing the file dialogue using the button, the selection of the radio button becomes the first element again.
To Reproduce
importstaticorg.assertj.core.api.Assertions.assertThat;
importorg.eclipse.jface.dialogs.TitleAreaDialog;
importorg.eclipse.jface.layout.GridDataFactory;
importorg.eclipse.jface.layout.GridLayoutFactory;
importorg.eclipse.swt.SWT;
importorg.eclipse.swt.events.SelectionAdapter;
importorg.eclipse.swt.events.SelectionEvent;
importorg.eclipse.swt.widgets.Button;
importorg.eclipse.swt.widgets.Composite;
importorg.eclipse.swt.widgets.Control;
importorg.eclipse.swt.widgets.Event;
importorg.eclipse.swt.widgets.FileDialog;
importorg.eclipse.swt.widgets.Shell;
importorg.junit.jupiter.api.Test;
publicclassSWTRadioButtonFocusTest {
privateSimpleDialog_dialog;
@Test/** * This is a user test - only opens the Dialog to test the behavior by self */voidtestRadioButtons() {
Shellshell = newShell();
SimpleDialogdialog = newSimpleDialog(shell, true);
dialog.open();
}
@TestvoidtestRadioButtonsAuto() {
Shellshell = newShell();
_dialog = newSimpleDialog(shell, false);
_dialog.setBlockOnOpen(false);
_dialog.open();
_dialog.getRadioButton1().setSelection(false);
_dialog.getRadioButton2().setSelection(true);
_dialog.getRadioButton2().notifyListeners(SWT.Selection, newEvent()); //select radio button 2assertThat(_dialog.getRadioButton2().getSelection()).isTrue(); //check if radio button 2 is selected_dialog.getFileChooserButton().notifyListeners(SWT.Selection, newEvent()); //click the browse button to open fileChooserassertThat(_dialog.getRadioButton2().getSelection()).isTrue(); //after closing the fileChooser, radio button 2 should be still selected - but radio button 1 is selected instead
}
privateclassSimpleDialogextendsTitleAreaDialog {
privateboolean_userTest;
privateButton_radio1;
privateButton_radio2;
privateButton_button;
publicSimpleDialog(ShellparentShell, booleanuserTest) {
this(parentShell);
_userTest = userTest;
}
publicSimpleDialog(ShellparentShell) {
super(parentShell);
}
@Overridepublicvoidcreate() {
super.create();
setTitle("SWT Radio Buttons");
setMessage("Select Radio Button 2 and then open the FileChooser and close it afterwards.");
}
@OverrideprotectedControlcreateDialogArea(Compositeparent) {
Compositearea = (Composite) super.createDialogArea(parent);
Compositecontainer = newComposite(area, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(container);
GridLayoutFactory.fillDefaults().applyTo(container);
createRadioButtons(container);
createFileChooserButton(container);
returnarea;
}
privatevoidcreateRadioButtons(Compositeparent) {
_radio1 = newButton(parent, SWT.RADIO);
_radio1.setText("Option 1");
GridDataFactory.fillDefaults().grab(true, false).applyTo(_radio1);
_radio2 = newButton(parent, SWT.RADIO);
_radio2.setText("Option 2");
GridDataFactory.fillDefaults().grab(true, false).applyTo(_radio2);
}
privatevoidcreateFileChooserButton(Compositeparent) {
_button = newButton(parent, SWT.PUSH);
_button.setText("Browse...");
_button.addSelectionListener(createSelectionAdapter());
}
privateSelectionAdaptercreateSelectionAdapter() {
if (_userTest) {
returnnewSelectionAdapter() {
@OverridepublicvoidwidgetSelected(SelectionEvente) {
/** * The error only occurs if the current shell is used! If a new shell is created, there is no error behavior. */FileDialogfileDialog = newFileDialog(getShell(), SWT.OPEN);
fileDialog.setText("Select File");
fileDialog.open();
}
};
} else {
returnnewSelectionAdapter() {
@OverridepublicvoidwidgetSelected(SelectionEvente) {
SimpleDialogsimpleDialog = newSimpleDialog(getShell());
simpleDialog.setBlockOnOpen(false);
simpleDialog.open();
simpleDialog.close();
}
};
}
}
publicButtongetRadioButton1() {
return_radio1;
}
publicButtongetRadioButton2() {
return_radio2;
}
publicButtongetFileChooserButton() {
return_button;
}
}
}
select the radio button "option 2"
open the file dialog via the "browse"-button
close the file dialog
Expected behavior
The selection of the radio buttons should not change after opening and closing a FileDialog
Environment:
Select the platform(s) on which the behavior is seen:
All OS
Windows
Linux
macOS
JRE/JDK version: corretto-jdk11.0.23.9.1_x86_64
SWT version: 3.126.0.v20240528-0813
Workaround
Any known workarounds for the problem?
setFocus() on radio button in SelectionListener or new Shell for the FileDialog.
The text was updated successfully, but these errors were encountered:
Describe the bug
If a dialog contains radio buttons and a button for opening a file dialog, after selecting the second radio button and opening and closing the file dialogue using the button, the selection of the radio button becomes the first element again.
To Reproduce
Expected behavior
The selection of the radio buttons should not change after opening and closing a FileDialog
Environment:
Workaround
Any known workarounds for the problem?
setFocus() on radio button in SelectionListener or new Shell for the FileDialog.
The text was updated successfully, but these errors were encountered: