Search in sources :

Example 46 with WHeading

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

the class WConfirmationButtonExample method addAjaxExample.

/**
 * This is used to reproduce a WComponents bug condition to make sure we do not re-create it once it is fixed.
 * See https://github.com/BorderTech/wcomponents/issues/1266.
 */
private void addAjaxExample() {
    add(new WHeading(HeadingLevel.H2, "Confirm as ajax trigger"));
    final String before = "Before";
    final String after = "After";
    final WText ajaxContent = new WText("Before");
    final WPanel target = new WPanel(WPanel.Type.BOX);
    add(target);
    target.add(ajaxContent);
    WButton confirmWithAjax = new WButton("Replace");
    confirmWithAjax.setMessage("Are you sure?");
    confirmWithAjax.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            ajaxContent.setText(before.equals(ajaxContent.getText()) ? after : before);
        }
    });
    add(confirmWithAjax);
    add(new WAjaxControl(confirmWithAjax, target));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 47 with WHeading

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

the class WDateFieldExample method addDateRangeExample.

/**
 * Add date range example.
 */
private void addDateRangeExample() {
    add(new WHeading(WHeading.MAJOR, "Example of a date range component"));
    WFieldSet dateRange = new WFieldSet("Enter the expected arrival and departure dates.");
    add(dateRange);
    WPanel dateRangePanel = new WPanel();
    dateRangePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0));
    dateRange.add(dateRangePanel);
    final WDateField arrivalDate = new WDateField();
    final WDateField departureDate = new WDateField();
    // One could add some validation rules around this so that "arrival" was always earlier than or equal to "departure"
    WLabel arrivalLabel = new WLabel("Arrival", arrivalDate);
    arrivalLabel.setHint("dd MMM yyyy");
    WLabel departureLabel = new WLabel("Departure", departureDate);
    departureLabel.setHint("dd MMM yyyy");
    dateRangePanel.add(arrivalLabel);
    dateRangePanel.add(arrivalDate);
    dateRangePanel.add(departureLabel);
    dateRangePanel.add(departureDate);
    // subordinate control to ensure that the departure date is only enabled if the arrival date is populated
    WSubordinateControl control = new WSubordinateControl();
    add(control);
    Rule rule = new Rule(new Equal(arrivalDate, null));
    control.addRule(rule);
    rule.addActionOnTrue(new Disable(departureDate));
    rule.addActionOnFalse(new Enable(departureDate));
    control.addRule(rule);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WPanel(com.github.bordertech.wcomponents.WPanel) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WDateField(com.github.bordertech.wcomponents.WDateField) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHeading(com.github.bordertech.wcomponents.WHeading) Disable(com.github.bordertech.wcomponents.subordinate.Disable) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 48 with WHeading

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

the class WLabelExample method addNestedFieldExamples.

/**
 * Examples showing WLabel with a nested input control WComponent.
 * This is VERY dangerous as only a very few WComponents are valid for this scenario. If you go down this route: stop!!
 * These are really here for framework testing, not as examples as to  how to do things.
 */
private void addNestedFieldExamples() {
    add(new WHeading(HeadingLevel.H2, "Label nesting which is technically OK"));
    /* Just because it is OK to do this does not mean you should! So these "examples" have far fewer comments. */
    WPanel errorLayoutPanel = new WPanel();
    errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
    errorLayoutPanel.setMargin(new Margin(null, null, Size.XL, null));
    add(errorLayoutPanel);
    errorLayoutPanel.add(new ExplanatoryText("This example shows WLabels with a single nested simple form control WTextField." + " This is not a contravention of the HTML specification but you should not do it."));
    WLabel outerLabel = new WLabel("Label with nested WTextField and not 'for' anything");
    errorLayoutPanel.add(outerLabel);
    outerLabel.add(new WTextField());
    WTextField innerField = new WTextField();
    outerLabel = new WLabel("Label 'for' nested WTextField", innerField);
    errorLayoutPanel.add(outerLabel);
    outerLabel.add(innerField);
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WTextField(com.github.bordertech.wcomponents.WTextField) WHeading(com.github.bordertech.wcomponents.WHeading) Margin(com.github.bordertech.wcomponents.Margin) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 49 with WHeading

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

the class WRadioButtonSelectExample method makeSimpleExample.

/**
 * Make a simple editable example. The label for this example is used to get the example for use in the unit tests.
 */
private void makeSimpleExample() {
    add(new WHeading(HeadingLevel.H3, "Simple WRadioButtonSelect"));
    WPanel examplePanel = new WPanel();
    examplePanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.MEDIUM));
    add(examplePanel);
    /**
     * The radio button select.
     */
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Update");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            text.setText("The selected item is: " + rbSelect.getSelected());
        }
    });
    // setting the default submit button improves usability. It can be set on a WPanel or the WRadioButtonSelect directly
    examplePanel.setDefaultSubmitButton(update);
    examplePanel.add(new WLabel("Select a state or territory", rbSelect));
    examplePanel.add(rbSelect);
    examplePanel.add(text);
    examplePanel.add(update);
    add(new WAjaxControl(update, text));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 50 with WHeading

use of com.github.bordertech.wcomponents.WHeading 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

WHeading (com.github.bordertech.wcomponents.WHeading)53 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)26 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)18 WPanel (com.github.bordertech.wcomponents.WPanel)17 WButton (com.github.bordertech.wcomponents.WButton)16 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)13 WLabel (com.github.bordertech.wcomponents.WLabel)13 Action (com.github.bordertech.wcomponents.Action)12 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)12 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)12 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)10 WTextField (com.github.bordertech.wcomponents.WTextField)10 WText (com.github.bordertech.wcomponents.WText)9 ColumnLayout (com.github.bordertech.wcomponents.layout.ColumnLayout)7 FlowLayout (com.github.bordertech.wcomponents.layout.FlowLayout)7 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)6 Test (org.junit.Test)5 Margin (com.github.bordertech.wcomponents.Margin)4 Alignment (com.github.bordertech.wcomponents.layout.ColumnLayout.Alignment)4 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)4