Search in sources :

Example 1 with RadioButtonGroup

use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method setupTrigger.

/**
 * Setup the trigger for the subordinate control.
 */
private void setupTrigger() {
    String label = drpTriggerType.getSelected() + " Trigger";
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(LABEL_WIDTH);
    buildControlPanel.add(layout);
    switch((TriggerType) drpTriggerType.getSelected()) {
        case RadioButtonGroup:
            trigger = new RadioButtonGroup();
            WFieldSet rbSet = new WFieldSet("Select an option");
            RadioButtonGroup group = (RadioButtonGroup) trigger;
            WRadioButton rb1 = group.addRadioButton("A");
            WRadioButton rb2 = group.addRadioButton("B");
            WRadioButton rb3 = group.addRadioButton("C");
            rbSet.add(group);
            rbSet.add(rb1);
            rbSet.add(new WLabel("A", rb1));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb2);
            rbSet.add(new WLabel("B", rb2));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb3);
            rbSet.add(new WLabel("C", rb3));
            layout.addField(label, rbSet);
            return;
        case CheckBox:
            trigger = new WCheckBox();
            break;
        case CheckBoxSelect:
            trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
            break;
        case DateField:
            trigger = new WDateField();
            break;
        case Dropdown:
            trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
            break;
        case EmailField:
            trigger = new WEmailField();
            break;
        case MultiSelect:
            trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
            break;
        case MultiSelectPair:
            trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
            break;
        case NumberField:
            trigger = new WNumberField();
            break;
        case PartialDateField:
            trigger = new WPartialDateField();
            break;
        case PasswordField:
            trigger = new WPasswordField();
            break;
        case PhoneNumberField:
            trigger = new WPhoneNumberField();
            break;
        case RadioButtonSelect:
            trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
            break;
        case SingleSelect:
            trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
            break;
        case TextArea:
            trigger = new WTextArea();
            ((WTextArea) trigger).setMaxLength(1000);
            break;
        case TextField:
            trigger = new WTextField();
            break;
        default:
            throw new SystemException("Trigger type not valid");
    }
    layout.addField(label, trigger);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WNumberField(com.github.bordertech.wcomponents.WNumberField) WEmailField(com.github.bordertech.wcomponents.WEmailField) WPasswordField(com.github.bordertech.wcomponents.WPasswordField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WDropdown(com.github.bordertech.wcomponents.WDropdown) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) TableWithNullOption(com.github.bordertech.wcomponents.examples.common.ExampleLookupTable.TableWithNullOption) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSingleSelect(com.github.bordertech.wcomponents.WSingleSelect) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) WDateField(com.github.bordertech.wcomponents.WDateField)

Example 2 with RadioButtonGroup

use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.

the class WLabelExample method addNullLabelExample.

/**
 * Example of when and how to use a null WLabel.
 */
private void addNullLabelExample() {
    add(new WHeading(HeadingLevel.H2, "How to use accessible null WLabels"));
    add(new ExplanatoryText("These examples shows how sometime a null WLabel is the right thing to do." + "\n This example uses a WFieldSet as the labelled component and it has its own \"label\"."));
    // We want to add a WFieldSet to a WFieldLayout but without an extra label.
    WFieldLayout fieldsFlat = new WFieldLayout();
    fieldsFlat.setMargin(new Margin(null, null, Size.XL, null));
    add(fieldsFlat);
    WFieldSet fs = new WFieldSet("Do you like Bananas?");
    fieldsFlat.addField((WLabel) null, fs);
    // now add the WRadioButtons to the WFieldSet using an inner WFieldLayout
    WFieldLayout innerLayout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    // The content will be a group of WRadioButtons
    RadioButtonGroup group1 = new RadioButtonGroup();
    WRadioButton rb1 = group1.addRadioButton(1);
    WRadioButton rb2 = group1.addRadioButton(2);
    // make the labels for the radio buttons
    WLabel rb1Label = new WLabel("", rb1);
    WImage labelImage = new WImage("/image/success.png", "I still like bananas");
    labelImage.setHtmlClass("wc-valign-bottom");
    rb1Label.add(labelImage);
    WLabel rb2Label = new WLabel("", rb2);
    labelImage = new WImage("/image/error.png", "I still dislike bananas");
    labelImage.setHtmlClass("wc-valign-bottom");
    rb2Label.add(labelImage);
    innerLayout.addField(rb1Label, rb1);
    innerLayout.addField(rb2Label, rb2);
    // add the content to the WFieldLayout - the order really doesn't matter.
    fs.add(group1);
    fs.add(innerLayout);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) WImage(com.github.bordertech.wcomponents.WImage) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WHeading(com.github.bordertech.wcomponents.WHeading) Margin(com.github.bordertech.wcomponents.Margin) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 3 with RadioButtonGroup

use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.

the class AbstractCompare method getCompareValue.

/**
 * Get the value to use in the compare.
 * <p>
 * It will return the same "value" the client would have used in its subordinate logic.
 * </p>
 * <p>
 * The compare value will either be (i) a date formatted String for WDateFields, (ii) a BigDecimal for WNumberFields
 * or (iii) a String value.
 * </p>
 *
 * @return the value to be used for the compare.
 */
protected Object getCompareValue() {
    // Date Compare (Use Date Formatted String - YYYY-MM-DD)
    if (trigger instanceof WDateField) {
        return value == null ? null : new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(value);
    } else if (trigger instanceof WNumberField) {
        // Number Compare (Use Number Object)
        return value;
    } else if (trigger instanceof AbstractWSelectList) {
        // String Compare - List (Use the Option's Code)
        final AbstractWSelectList listTrigger = (AbstractWSelectList) trigger;
        final List<?> options = listTrigger.getOptions();
        // No options, just return the compare value (so that a test against null works correctly)
        if (options == null || options.isEmpty()) {
            return value == null ? null : value.toString();
        }
        // Check if the value is a valid option allowing for "Legacy" matching
        if (SelectListUtil.containsOptionWithMatching(options, value)) {
            Object option = SelectListUtil.getOptionWithMatching(options, value);
            String code = listTrigger.optionToCode(option);
            return code;
        }
        // Return the value as a String - Treat empty the same as null
        return (value == null || Util.empty(value.toString())) ? null : value.toString();
    } else if (trigger instanceof RadioButtonGroup && value instanceof WRadioButton) {
        // String Compare for RadioButtonGroup and value is WRadioButton (Use the button value)
        // Note - This is only for backward compatibility where projects have used a radio button
        // in the trigger. Projects should use the value expected, not the radio button.
        // If the radio button passed into the compare is used in a repeater, then this compare will not work.
        String data = ((WRadioButton) value).getValue();
        // Treat empty the same as null
        return Util.empty(data) ? null : data;
    } else {
        // Treat empty the same as null
        return (value == null || Util.empty(value.toString())) ? null : value.toString();
    }
}
Also used : AbstractWSelectList(com.github.bordertech.wcomponents.AbstractWSelectList) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WNumberField(com.github.bordertech.wcomponents.WNumberField) WDateField(com.github.bordertech.wcomponents.WDateField) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with RadioButtonGroup

use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.

the class WRadioButtonRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    RadioButtonGroup group = new RadioButtonGroup();
    WRadioButton button = group.addRadioButton(1);
    button.setVisible(true);
    assertSchemaMatch(button);
    assertXpathExists("//ui:radiobutton", button);
    assertXpathEvaluatesTo(button.getId(), "//ui:radiobutton/@id", button);
    assertXpathEvaluatesTo(button.getGroupName(), "//ui:radiobutton/@groupName", button);
    assertXpathEvaluatesTo(button.getValue(), "//ui:radiobutton/@value", button);
    assertXpathNotExists("//ui:radiobutton/@submitOnChange", button);
    // Check selected
    assertXpathNotExists("//ui:radiobutton/@selected", button);
    button.setSelected(true);
    assertSchemaMatch(button);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@selected", button);
    // Check disabled
    assertXpathNotExists("//ui:radiobutton/@disabled", button);
    button.setDisabled(true);
    assertSchemaMatch(button);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@disabled", button);
    // Check hidden
    assertXpathNotExists("//ui:radiobutton/@hidden", button);
    setFlag(button, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(button);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@hidden", button);
    // Check required
    assertXpathNotExists("//ui:radiobutton/@required", button);
    group.setMandatory(true);
    assertSchemaMatch(button);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@required", button);
    // Check toolTip
    String toolTip = "WRadioButton_Test.testRenderedFormat.toolTip";
    button.setToolTip(toolTip);
    assertSchemaMatch(button);
    assertXpathEvaluatesTo(toolTip, "//ui:radiobutton/@toolTip", button);
    button.setToolTip(null);
    assertSchemaMatch(button);
    assertXpathNotExists("//ui:radiobutton/@toolTip", button);
    // Check submitOnChange
    group = new RadioButtonGroup();
    button = group.addRadioButton(1);
    group.setSubmitOnChange(true);
    assertSchemaMatch(button);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@submitOnChange", button);
}
Also used : WRadioButton(com.github.bordertech.wcomponents.WRadioButton) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) Test(org.junit.Test)

Example 5 with RadioButtonGroup

use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.

the class WRadioButtonRenderer_Test method testIsNullOption.

@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
    WPanel root = new WPanel();
    RadioButtonGroup group = new RadioButtonGroup();
    root.add(group);
    WRadioButton button1 = group.addRadioButton(null);
    WRadioButton button2 = group.addRadioButton("");
    WRadioButton button3 = group.addRadioButton("A");
    root.add(button1);
    root.add(button2);
    root.add(button3);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@isNull", button1);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@isNull", button2);
    assertXpathEvaluatesTo("", "//ui:radiobutton/@isNull", button3);
}
Also used : WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WPanel(com.github.bordertech.wcomponents.WPanel) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) Test(org.junit.Test)

Aggregations

RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)11 WRadioButton (com.github.bordertech.wcomponents.WRadioButton)9 Test (org.junit.Test)8 WLabel (com.github.bordertech.wcomponents.WLabel)3 WDateField (com.github.bordertech.wcomponents.WDateField)2 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2 WNumberField (com.github.bordertech.wcomponents.WNumberField)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 AbstractWSelectList (com.github.bordertech.wcomponents.AbstractWSelectList)1 Margin (com.github.bordertech.wcomponents.Margin)1 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WHeading (com.github.bordertech.wcomponents.WHeading)1 WImage (com.github.bordertech.wcomponents.WImage)1 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)1