Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Scout/Concepts/RadioButtonGroup"

(Description)
(Replaced content with "The Scout documentation has been moved to https://eclipsescout.github.io/.")
 
Line 1: Line 1:
{{ScoutPage|cat=Component Model}}
+
The Scout documentation has been moved to https://eclipsescout.github.io/.
 
+
Specific type of {{ScoutLink|Concepts|ValueField|value field}} to propose a choice between a limited number of possibilities.
+
 
+
* implements: {{ScoutJavadoc|IRadioButtonGroup<T>|I}}
+
* extends: {{ScoutJavadoc|AbstractRadioButtonGroup<T>|C}}
+
 
+
== Description ==
+
The RadioButtonGroup can be used to show a {{ScoutLink|Concepts|CodeType|CodeType}} or a {{ScoutLink|Concepts|LookupCall|LookupCall}} as RadioButtons. A RadioButtonGroup is a normal {{ScoutLink|Concepts|ValueField|value field}} with parameterized type <code><T></code>.
+
 
+
Only one of the RadioButtons can be selected.
+
 
+
Another possibility is to define the radio Button as Inner-Class: {{ScoutLink|Concepts|RadioButton}}. In this case, the value of the field is defined in each RadioButton with the {{ScoutProp|RadioValue}} property.
+
 
+
 
+
A RadioButtonGroup can also contain some other {{ScoutLink|Concepts|Field|fields}} in the group (as inner class).
+
{{note|TODO|Merge from [http://www.eclipse.org/forums/index.php/mv/msg/247230/739550/#msg_739550 forum]: "list" of sections where a radio button is on the left and a group box or other field is on the right}}
+
 
+
 
+
=== Example ===
+
Here is some code to propose to choose between three colors (red, green and blue):
+
<source lang="java">
+
public class ColorGroup extends AbstractRadioButtonGroup<String> {
+
 
+
  @Override
+
  protected String getConfiguredLabel() {
+
    return TEXTS.get("Color");
+
  }
+
 
+
  @Order(10.0)
+
  public class RedButton extends AbstractRadioButton {
+
 
+
    @Override
+
    protected String getConfiguredLabel() {
+
      return TEXTS.get("Red");
+
    }
+
 
+
    @Override
+
    protected Object getConfiguredRadioValue() {
+
      return "RED";
+
    }
+
  }
+
 
+
  @Order(20.0)
+
  public class GreenButton extends AbstractRadioButton {
+
 
+
    @Override
+
    protected String getConfiguredLabel() {
+
      return TEXTS.get("Green");
+
    }
+
 
+
    @Override
+
    protected Object getConfiguredRadioValue() {
+
      return "GREEN";
+
    }
+
  }
+
 
+
  @Order(30.0)
+
  public class BlueButton extends AbstractRadioButton {
+
 
+
    @Override
+
    protected String getConfiguredLabel() {
+
      return TEXTS.get("Blue");
+
    }
+
 
+
    @Override
+
    protected Object getConfiguredRadioValue() {
+
      return "BLUE";
+
    }
+
  }
+
}
+
</source>
+
 
+
Corresponding screenshot:
+
[[Image:Scout Color RadioGroup.png]]
+
 
+
The value can be set directly:
+
<source lang="java">
+
getColorGroup().setValue("RED");
+
</source>
+
where getColorGroup() is the convienece function add by the Scout SDK to get the ColorGroup field:
+
<source lang="java">
+
public ColorGroup getColorGroup() {
+
  return getFieldByClass(ColorGroup.class);
+
}
+
</source>
+
 
+
Of course, as for any other value field, it is possible to use the formData:
+
<source lang="java">
+
formData.getColorGroup().setValue("BLUE");
+
</source>
+
 
+
 
+
Another possibility to create the radio button is to use a code type. Here we use {{ScoutLink|Concepts|CodeType/Example|YesOrNoCodeType}}:
+
<source lang="java">
+
public class YesOrNoGroup extends AbstractRadioButtonGroup<Boolean> {
+
 
+
  @Override
+
  protected String getConfiguredLabel() {
+
    return TEXTS.get("YesOrNo");
+
  }
+
 
+
  @Override
+
  protected Class<? extends ICodeType> getConfiguredCodeType() {
+
    return YesOrNoCodeType.class;
+
  }
+
}
+
</source>
+
 
+
The <code><T></code> of <code>AbstractRadioButtonGroup</code> needs to match the {{ScoutProp|Id}} returned by the {{ScoutLink|Concepts|Code}}.
+
 
+
The value can also be set directly or with the formData:
+
<source lang="java">
+
getFieldByClass(YesOrNoGroup.class).setValue(Boolean.FALSE)
+
formData.getYesOrNoGroup().setValue(Boolean.TRUE);
+
</source>
+
 
+
== Screenshot ==
+
{|{{BMTableStyle}}
+
|-{{BMTHStyle}}
+
! RAP
+
! SWT
+
! Swing
+
! Swing Rayo
+
|-
+
| [[Image:Scout_3.8_RadioButtonGroup_RAP.png]] || [[Image:Scout_3.8_RadioButtonGroup_SWT.png]] || [[Image:Scout_3.8_RadioButtonGroup_Swing.png]] || [[Image:Scout_3.8_RadioButtonGroup_Swing_Rayo.png]]
+
|-
+
|}
+
 
+
== Properties ==
+
''Defined with {{ScoutLink|Concepts|GetConfigured Methods|getConfiguredXxxxxx()}} methods''.
+
 
+
See also the {{ScoutLink|Concepts|Field|Field}} and the {{ScoutLink|Concepts|ValueField|Value field}} pages for the properties that all fields have in common.
+
 
+
 
+
== Events ==
+
''Defined with {{ScoutLink|Concepts|Exec_Methods|execXxxxxx()}} methods''.
+
 
+
See also the {{ScoutLink|Concepts|Field|Field}} and the {{ScoutLink|Concepts|ValueField|Value field}} pages for the events that all fields have in common.
+
 
+
 
+
== See Also ==
+
* {{ScoutLink|Concepts|ValueField|Value field}}
+
* {{ScoutLink|Concepts|Field|Field}}
+
* {{ScoutLink|Concepts|Form|Form}}
+

Latest revision as of 04:54, 14 March 2024

The Scout documentation has been moved to https://eclipsescout.github.io/.

Back to the top