Search in sources :

Example 1 with WField

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

the class WDropdownOptionsExample method getDropDownControls.

/**
 * build the drop down controls.
 *
 * @return a field set containing the dropdown controls.
 */
private WFieldSet getDropDownControls() {
    WFieldSet fieldSet = new WFieldSet("Drop down configuration");
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    fieldSet.add(layout);
    rbsDDType.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    rbsDDType.setSelected(WDropdown.DropdownType.NATIVE);
    rbsDDType.setFrameless(true);
    layout.addField("Dropdown Type", rbsDDType);
    nfWidth.setMinValue(0);
    nfWidth.setDecimalPlaces(0);
    layout.addField("Width", nfWidth);
    layout.addField("ToolTip", tfToolTip);
    layout.addField("Include null option", cbNullOption);
    rgDefaultOption.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
    rgDefaultOption.setButtonColumns(2);
    rgDefaultOption.setSelected(NONE);
    rgDefaultOption.setFrameless(true);
    layout.addField("Default Option", rgDefaultOption);
    layout.addField("Action on change", cbActionOnChange);
    layout.addField("Ajax", cbAjax);
    WField subField = layout.addField("Subordinate", cbSubordinate);
    // .getLabel().setHint("Does not work with Dropdown Type COMBO");
    layout.addField("Submit on change", cbSubmitOnChange);
    layout.addField("Visible", cbVisible);
    layout.addField("Disabled", cbDisabled);
    // Apply Button
    WButton apply = new WButton("Apply");
    fieldSet.add(apply);
    WSubordinateControl subSubControl = new WSubordinateControl();
    Rule rule = new Rule();
    subSubControl.addRule(rule);
    rule.setCondition(new Equal(rbsDDType, WDropdown.DropdownType.COMBO));
    rule.addActionOnTrue(new Disable(subField));
    rule.addActionOnFalse(new Enable(subField));
    fieldSet.add(subSubControl);
    apply.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            applySettings();
        }
    });
    return fieldSet;
}
Also used : WField(com.github.bordertech.wcomponents.WField) Action(com.github.bordertech.wcomponents.Action) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) Equal(com.github.bordertech.wcomponents.subordinate.Equal) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) WButton(com.github.bordertech.wcomponents.WButton) Disable(com.github.bordertech.wcomponents.subordinate.Disable)

Example 2 with WField

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

the class WFieldSetExample method addFieldSet.

/**
 * Creates a WFieldSet with content and a given FrameType.
 *
 * @param title The title to give to the WFieldSet.
 * @param type The decorative model of the WFieldSet
 * @return a WFieldSet with form control content.
 */
private WFieldSet addFieldSet(final String title, final WFieldSet.FrameType type) {
    final WFieldSet fieldset = new WFieldSet(title);
    fieldset.setFrameType(type);
    fieldset.setMargin(new Margin(null, null, Size.LARGE, null));
    final WFieldLayout layout = new WFieldLayout();
    fieldset.add(layout);
    layout.setLabelWidth(25);
    layout.addField("Street address", new WTextField());
    final WField add2Field = layout.addField("Street address line 2", new WTextField());
    add2Field.getLabel().setHidden(true);
    layout.addField("Suburb", new WTextField());
    layout.addField("State/Territory", new WDropdown(new String[] { "", "ACT", "NSW", "NT", "QLD", "SA", "TAS", "VIC", "WA" }));
    // NOTE: this is an Australia-specific post code field. An Australian post code is not a number as they may contain a leading zero.
    final WTextField postcode = new WTextField();
    postcode.setMaxLength(4);
    postcode.setColumns(4);
    postcode.setMinLength(3);
    layout.addField("Postcode", postcode);
    add(fieldset);
    return fieldset;
}
Also used : WField(com.github.bordertech.wcomponents.WField) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WDropdown(com.github.bordertech.wcomponents.WDropdown) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Margin(com.github.bordertech.wcomponents.Margin)

Example 3 with WField

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

the class AbstractSetMandatory_Test method testExecute.

@Test
public void testExecute() {
    // ---------------------
    // Valid Target (WInput) and TRUE Boolean Value
    SubordinateTarget target1 = new MyTarget();
    AbstractSetMandatory mandatory = new MyMandatory(target1, Boolean.TRUE);
    // Should be mandatory
    mandatory.execute();
    Assert.assertTrue("Target (Mandatable) should be mandatory", ((Mandatable) target1).isMandatory());
    // FALSE Boolean Value
    mandatory = new MyMandatory(target1, Boolean.FALSE);
    // Should not be mandatory
    mandatory.execute();
    Assert.assertFalse("Target (Mandatable) should not be mandatory", ((Mandatable) target1).isMandatory());
    // ---------------------
    // Valid Target (WField) and TRUE Boolean Value
    Input textArea = new WTextArea();
    WField target2 = new WFieldLayout().addField("test", textArea);
    mandatory = new MyMandatory(target2, Boolean.TRUE);
    // Should be mandatory
    mandatory.execute();
    Assert.assertTrue("Target (WField) should be mandatory", textArea.isMandatory());
    // FALSE Boolean Value
    mandatory = new MyMandatory(target2, Boolean.FALSE);
    // Should not be mandatory
    mandatory.execute();
    Assert.assertFalse("Target (WField) should not be mandatory", textArea.isMandatory());
    // ---------------------
    // Valid Target (WFieldSet) and TRUE Boolean Value
    WFieldSet target3 = new WFieldSet("Test");
    mandatory = new MyMandatory(target3, Boolean.TRUE);
    // Should be mandatory
    mandatory.execute();
    Assert.assertTrue("Target (WFieldSet) should be mandatory", target3.isMandatory());
    // FALSE Boolean Value
    mandatory = new MyMandatory(target3, Boolean.FALSE);
    // Should not be mandatory
    mandatory.execute();
    Assert.assertFalse("Target (WFieldSet) should not be mandatory", target3.isMandatory());
    // ---------------------
    // Invalid Target (Cannot be set Mandatory) and Boolean Value
    MyInvalidTarget target4 = new MyInvalidTarget();
    mandatory = new MyMandatory(target4, Boolean.TRUE);
    // Should do nothing
    mandatory.execute();
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Input(com.github.bordertech.wcomponents.Input) WField(com.github.bordertech.wcomponents.WField) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Test(org.junit.Test)

Example 4 with WField

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

the class WRadioButtonSelectExample method addAntiPatternExamples.

/**
 * Examples of what not to do when using WRadioButtonSelect.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WRadioButtonSelect anti-pattern examples"));
    add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
    // Even compound controls need a label
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with no labelling component"));
    add(new ExplanatoryText("All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip."));
    add(new WRadioButtonSelect("australian_state"));
    // submitOnChange is a WRadioButtonSelect no no!!
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with submitOnChange"));
    add(new ExplanatoryText("SubmitOnChange is bad in most cases but terrible with radio buttons because there is no way to change the selection" + " between non-contiguous options using the keyboard without having multiple page submits.\nIn the following example try to change " + "the selection from 'Outside Australia' to 'Queensland' using only your keyboard. To make this easier the WRadioButtonSelect has" + " an access key of 'M'"));
    final WRadioButtonSelect select = new SelectWithSelection("australian_state");
    final WTextField selected = new WTextField();
    selected.setReadOnly(true);
    select.setActionOnChange(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            // does not matter what this is
            selected.setText(select.getValueAsString());
        }
    });
    select.setSubmitOnChange(true);
    // now put them all into the UI
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    WField selectField = layout.addField("Make a selection to update the page", select);
    selectField.getLabel().setAccessKey('M');
    layout.addField("Selected option", selected);
    // Too many options anti-pattern
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with too many options"));
    add(new ExplanatoryText("Don't use a WRadioButtonSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
    // use the country code list at your peril!!
    WRadioButtonSelect rbsTooBig = new WRadioButtonSelect(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" });
    rbsTooBig.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
    rbsTooBig.setButtonColumns(6);
    rbsTooBig.setFrameless(true);
    rbsTooBig.setToolTip("Select your country of birth");
    add(rbsTooBig);
    // Don't use a radioButtonSelect if the user can make no selection unless you provide a null option
    add(new WHeading(HeadingLevel.H3, "Optional WRadioButtonSelect with no null option"));
    add(new ExplanatoryText("Once a radio button group has a selection it cannot be removed. If a WRadioButtonSelect is not mandatory it should" + " include a 'none of these' type null option.\nWhat happens if you make a selection in the following but then change your mind" + " (even ugly chairs are not your scene). To concentrate the mind I have made a selection for you."));
    WRadioButtonSelect noneOfTheAboveSelect = new SelectWithSelection(new String[] { "spike", "broken glass", "ugly chair", "wet paint" });
    noneOfTheAboveSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    noneOfTheAboveSelect.setFrameless(true);
    layout = new WFieldLayout();
    add(layout);
    layout.addField("Where would you like to sit?", noneOfTheAboveSelect);
    // don't use a yes/no group of radio buttons for something which should be a checkbox
    add(new WHeading(HeadingLevel.H3, "Yes/No options"));
    add(new ExplanatoryText("If the only answers to your question is one of yes or no then you do not have a group of radio buttons, you have a check box.\n" + "In the following example the WRadioButtonSelect should be a WCheckBox and the label be 'I agree to the terms and conditions'"));
    layout = new WFieldLayout();
    add(layout);
    WRadioButtonSelect yesNoSelect = new WRadioButtonSelect(new String[] { "yes", "no" });
    yesNoSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    yesNoSelect.setFrameless(true);
    layout.addField("Do you agree to the terms and conditions?", yesNoSelect);
    add(new WHeading(HeadingLevel.H3, "No options"));
    add(new ExplanatoryText("An interactive WRadioButtonSelect with no options is rather pointless."));
    layout = new WFieldLayout();
    add(layout);
    layout.addField("Select from no options", new WRadioButtonSelect());
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WField(com.github.bordertech.wcomponents.WField) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMessageBox(com.github.bordertech.wcomponents.WMessageBox) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 5 with WField

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

the class WCheckBoxExample_Test method testFindByLabelId.

/**
 * Test that ByLabel works for CheckBoxes by label id.
 */
@Test
public void testFindByLabelId() {
    // Launch the web browser to the LDE
    WebDriver driver = getDriver();
    WContainer container = (WContainer) getUi();
    WFieldLayout layout = (WFieldLayout) container.getChildAt(0);
    WField field = (WField) layout.getChildAt(0);
    String labelId = field.getLabel().getId();
    String componentId = field.getField().getId();
    WebElement checkBox = driver.findElement(new ByLabel(labelId));
    Assert.assertNotNull("Unable to find checkbox by labelId", checkBox);
    Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WContainer(com.github.bordertech.wcomponents.WContainer) WField(com.github.bordertech.wcomponents.WField) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WebElement(org.openqa.selenium.WebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Aggregations

WField (com.github.bordertech.wcomponents.WField)11 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)10 Test (org.junit.Test)7 WTextField (com.github.bordertech.wcomponents.WTextField)4 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)3 Action (com.github.bordertech.wcomponents.Action)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)2 WContainer (com.github.bordertech.wcomponents.WContainer)2 WTextArea (com.github.bordertech.wcomponents.WTextArea)2 ByLabel (com.github.bordertech.wcomponents.test.selenium.ByLabel)2 WebDriver (org.openqa.selenium.WebDriver)2 WebElement (org.openqa.selenium.WebElement)2 Input (com.github.bordertech.wcomponents.Input)1 Margin (com.github.bordertech.wcomponents.Margin)1 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)1 WButton (com.github.bordertech.wcomponents.WButton)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WHeading (com.github.bordertech.wcomponents.WHeading)1 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)1 WLabel (com.github.bordertech.wcomponents.WLabel)1