Search in sources :

Example 36 with WFieldLayout

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

the class RepeaterExampleWithEditableRows method createExampleUi.

/**
 * Add all the required UI artefacts for this example.
 */
private void createExampleUi() {
    add(new WHeading(HeadingLevel.H2, "Contacts"));
    add(repeater);
    WButton addBtn = new WButton("Add");
    addBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            addNewContact();
        }
    });
    newNameField.setDefaultSubmitButton(addBtn);
    WButton printBtn = new WButton("Print");
    printBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            printEditedDetails();
        }
    });
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    layout.addField("New contact name", newNameField);
    layout.addField((WLabel) null, addBtn);
    layout.addField("Print output", console);
    layout.addField((WLabel) null, printBtn);
    // Ajax controls to make things zippier
    add(new WAjaxControl(addBtn, new AjaxTarget[] { repeater, newNameField }));
    add(new WAjaxControl(printBtn, console));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Example 37 with WFieldLayout

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

the class SubordinateControlMandatoryExample method build.

/**
 * Creates the component to be added to the validation container. This is doen in a static method because the
 * component is passed into the superclass constructor.
 *
 * @return the component to be added to the validation container.
 */
private static WComponent build() {
    WContainer root = new WContainer();
    WSubordinateControl control = new WSubordinateControl();
    root.add(control);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
    WCheckBox checkBox = new WCheckBox();
    layout.addField("Set Mandatory", checkBox);
    WTextField text = new WTextField();
    layout.addField("Might need this field", text);
    WTextField mandatoryField = new WTextField();
    layout.addField("Another field always mandatory", mandatoryField);
    mandatoryField.setMandatory(true);
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    layout.addField("Select a state", rbSelect);
    root.add(layout);
    Rule rule = new Rule();
    rule.setCondition(new Equal(checkBox, Boolean.TRUE.toString()));
    rule.addActionOnTrue(new Mandatory(text));
    rule.addActionOnFalse(new Optional(text));
    rule.addActionOnTrue(new Mandatory(rbSelect));
    rule.addActionOnFalse(new Optional(rbSelect));
    control.addRule(rule);
    return root;
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 38 with WFieldLayout

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

the class WCheckBoxSelectExample method addDisabledExamples.

/**
 * Examples of disabled state. You should use {@link WSubordinateControl} to set and manage the disabled state
 * unless there is no facility for the user to enable a control.
 */
private void addDisabledExamples() {
    add(new WHeading(HeadingLevel.H2, "Disabled WCheckBoxSelect examples"));
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
    select.setDisabled(true);
    layout.addField("Disabled with no default selection", select);
    add(new WHeading(HeadingLevel.H3, "Disabled with no selection and no frame"));
    select = new WCheckBoxSelect("australian_state");
    select.setDisabled(true);
    select.setFrameless(true);
    layout.addField("Disabled with no selection and no frame", select);
    select = new SelectWithSingleSelected("australian_state");
    select.setDisabled(true);
    layout.addField("Disabled with one selection", select);
    select = new SelectWithManySelected("australian_state");
    select.setDisabled(true);
    select.setButtonLayout(WCheckBoxSelect.LAYOUT_COLUMNS);
    select.setButtonColumns(3);
    layout.addField("Disabled with many selections and COLUMN layout", select);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 39 with WFieldLayout

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

the class WCheckBoxSelectExample method addAntiPatternExamples.

/**
 * Examples of what not to do when using WCheckBoxSelect.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WCheckBoxSelect 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."));
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with submitOnChange"));
    WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    add(layout);
    WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
    select.setSubmitOnChange(true);
    layout.addField("Select a state or territory with auto save", select);
    select = new WCheckBoxSelect("australian_state");
    select.setSubmitOnChange(true);
    layout.addField("Select a state or territory with auto save and hint", select).getLabel().setHint("This is a hint");
    // Even compound controls need a label
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect 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 WCheckBoxSelect("australian_state"));
    // Too many options anti-pattern
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with too many options"));
    add(new ExplanatoryText("Don't use a WCheckBoxSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
    select = new WCheckBoxSelect(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" });
    select.setButtonLayout(WCheckBoxSelect.LAYOUT_COLUMNS);
    select.setButtonColumns(6);
    select.setFrameless(true);
    add(new WLabel("Select your country of birth", select));
    add(select);
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with no options."));
    add(new ExplanatoryText("An interactive WCheckBoxSelect with no options is rather pointless."));
    select = new WCheckBoxSelect();
    add(new WLabel("WCheckBoxSelect with no options", select));
    add(select);
}
Also used : WMessageBox(com.github.bordertech.wcomponents.WMessageBox) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 40 with WFieldLayout

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

the class WRadioButtonSelectExample method addMandatorySelectExample.

/**
 * adds a WRadioButtonSelect with setMandatory(true).
 */
private void addMandatorySelectExample() {
    add(new WHeading(HeadingLevel.H3, "Mandatory WRadioButtonSelect"));
    add(new ExplanatoryText("When a WRadioButtonSelect is mandatory it needs a visible labelling element, otherwise many users may not know that " + "the component requires an answer."));
    final WRadioButtonSelect select = new WRadioButtonSelect("australian_state");
    select.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    select.setMandatory(true);
    add(new WLabel("Mandatory selection", select));
    add(select);
    add(new WHeading(HeadingLevel.H3, "Mandatory WRadioButtonSelect in a WFieldLayout"));
    WRadioButtonSelect select2 = new WRadioButtonSelect("australian_state");
    select2.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    select2.setMandatory(true);
    final WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    add(layout);
    layout.addField("Required selection", select2).getLabel().setHint("Required");
    select2 = new WRadioButtonSelect("australian_state");
    select2.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    select2.setMandatory(true);
    select2.setToolTip("Select a state");
    layout.addField((WLabel) null, select2);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel)

Aggregations

WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)47 WHeading (com.github.bordertech.wcomponents.WHeading)18 Test (org.junit.Test)13 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)12 WButton (com.github.bordertech.wcomponents.WButton)11 WTextField (com.github.bordertech.wcomponents.WTextField)11 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)11 Margin (com.github.bordertech.wcomponents.Margin)10 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)10 WField (com.github.bordertech.wcomponents.WField)10 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)10 Action (com.github.bordertech.wcomponents.Action)8 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)7 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)6 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)5 WContainer (com.github.bordertech.wcomponents.WContainer)5 WLabel (com.github.bordertech.wcomponents.WLabel)5 WText (com.github.bordertech.wcomponents.WText)5 Equal (com.github.bordertech.wcomponents.subordinate.Equal)5 Rule (com.github.bordertech.wcomponents.subordinate.Rule)5