Search in sources :

Example 16 with WFieldLayout

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

the class WListOptionsExample method getListControls.

/**
 * build the list controls field set.
 *
 * @return a field set for the controls.
 */
private WFieldSet getListControls() {
    // Options Layout
    WFieldSet fieldSet = new WFieldSet("List configuration");
    WFieldLayout layout = new WFieldLayout();
    // options.
    layout.addField("Type", ddType);
    layout.addField("Separator", ddSeparator);
    layout.addField("Render fields", cgBeanFields);
    layout.addField("Render Border", cbRenderBorder);
    layout.addField("Render using field layout", cbRenderUsingFieldLayout);
    layout.addField("Visible", cbVisible);
    // Apply Button
    WButton apply = new WButton("Apply");
    apply.setAction(new com.github.bordertech.wcomponents.Action() {

        @Override
        public void execute(final ActionEvent event) {
            applySettings();
        }
    });
    fieldSet.add(layout);
    fieldSet.add(apply);
    return fieldSet;
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton)

Example 17 with WFieldLayout

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

the class WPanelTypeExample method buildConfigOptions.

/**
 * Set up the UI for the configuration options.
 */
private void buildConfigOptions() {
    WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    layout.setMargin(new Margin(null, null, Size.LARGE, null));
    layout.addField("Select a WPanel Type", panelType);
    contentField = layout.addField("Panel content", panelContent);
    headingField = layout.addField("heading", tfHeading);
    showMenuField = layout.addField("Show menu", showMenu);
    showUtilBarField = layout.addField("Show utility bar", showUtilBar);
    layout.addField((WLabel) null, applyConfigButton);
    add(layout);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Margin(com.github.bordertech.wcomponents.Margin)

Example 18 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout 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 19 with WFieldLayout

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

the class WRadioButtonSelectExample 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.
 *
 * If you want to prevent the user enabling and interacting with a WRadioButtonSeelct then you should consider using
 * the readOnly state instead of the disabled state.
 */
private void addDisabledExamples() {
    add(new WHeading(HeadingLevel.H2, "Disabled WRadioButtonSelect examples"));
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    WRadioButtonSelect select = new WRadioButtonSelect("australian_state");
    select.setDisabled(true);
    layout.addField("Disabled with no selection", select);
    select = new WRadioButtonSelect("australian_state");
    select.setDisabled(true);
    select.setFrameless(true);
    layout.addField("Disabled with no selection no frame", select);
    select = new SelectWithSelection("australian_state");
    select.setDisabled(true);
    layout.addField("Disabled with selection", select);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 20 with WFieldLayout

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

the class WRadioButtonSelectExample method addInsideAFieldLayoutExample.

/**
 * When a WRadioButtonSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame,
 * the second doesn't
 */
private void addInsideAFieldLayoutExample() {
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect inside a WFieldLayout"));
    add(new ExplanatoryText("When a WRadioButtonSelect is inside a WField its label is exposed in a way which appears and behaves like a regular HTML label." + " This allows WRadioButtonSelects to be used in a layout with simple form controls (such as WTextField) and produce a consistent" + " and predicatable interface.\n" + "The third example in this set uses a null label and a toolTip to hide the labelling element. This can lead to user confusion and" + " is not recommended."));
    // Note: the wrapper WPanel here is to work around a bug in validation. See https://github.com/BorderTech/wcomponents/issues/1370
    final WPanel wrapper = new WPanel();
    add(wrapper);
    final WMessages messages = new WMessages();
    wrapper.add(messages);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    wrapper.add(layout);
    WButton resetThisBit = new WButton("Reset this bit");
    resetThisBit.setCancel(true);
    resetThisBit.setAjaxTarget(wrapper);
    resetThisBit.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            wrapper.reset();
        }
    });
    layout.addField(resetThisBit);
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    WRadioButtonSelect select = new WRadioButtonSelect(options);
    layout.addField("Select an animal", select);
    String[] options2 = new String[] { "Parrot", "Galah", "Cockatoo", "Lyre" };
    select = new WRadioButtonSelect(options2);
    select.setMandatory(true);
    layout.addField("You must select a bird", select);
    select.setFrameless(true);
    // a tooltip can be used as a label stand-in even in a WField
    String[] options3 = new String[] { "Carrot", "Beet", "Brocolli", "Bacon - the perfect vegetable" };
    select = new WRadioButtonSelect(options3);
    // if you absolutely do not want a WLabel in a WField then it has to be added using null cast to a WLabel.
    layout.addField((WLabel) null, select);
    select.setToolTip("Veggies");
    WButton btnValidate = new WButton("validate");
    btnValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // do nothing
        }
    });
    layout.addField(btnValidate);
    wrapper.add(new WAjaxControl(btnValidate, wrapper));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WMessages(com.github.bordertech.wcomponents.WMessages) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect)

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