Search in sources :

Example 6 with WFieldLayout

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

the class WDateFieldExample method addContraintExamples.

/**
 * Add constraint example.
 */
private void addContraintExamples() {
    add(new WHeading(WHeading.MAJOR, "Date fields with input constraints"));
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(33);
    add(layout);
    /* mandatory */
    WDateField constrainedDateField = new WDateField();
    constrainedDateField.setMandatory(true);
    layout.addField("Mandatory date field", constrainedDateField);
    /* min date */
    constrainedDateField = new WDateField();
    constrainedDateField.setMinDate(new Date());
    layout.addField("Minimum date today", constrainedDateField);
    /* max date */
    constrainedDateField = new WDateField();
    constrainedDateField.setMaxDate(new Date());
    layout.addField("Maximum date today", constrainedDateField);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WDateField(com.github.bordertech.wcomponents.WDateField) WHeading(com.github.bordertech.wcomponents.WHeading) Date(java.util.Date)

Example 7 with WFieldLayout

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

the class WFieldLayoutExample method recursiveFieldLayout.

/**
 * Create a recursive field layout.
 *
 * @param ordered true if all nested layouts are ordered.
 * @param curr recursion index
 * @param startAt the ordered offset
 * @return the recursive field layout.
 */
private WFieldLayout recursiveFieldLayout(final boolean ordered, final int curr, final int startAt) {
    WFieldLayout innerLayout = new WFieldLayout();
    innerLayout.setLabelWidth(20);
    if (curr == 0 && startAt == 0) {
        innerLayout.setMargin(new Margin(Size.LARGE, null, null, null));
    }
    innerLayout.setOrdered(ordered);
    if (ordered && startAt > 1) {
        innerLayout.setOrderedOffset(startAt);
    }
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt : 1), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 1 : 2), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 2 : 2), new WTextField());
    if (curr < 4) {
        int next = curr + 1;
        innerLayout.addField("indent level " + String.valueOf(next), recursiveFieldLayout(curr % 2 == 1, next, 0));
    }
    innerLayout.addField("Test after nest", new WTextField());
    return innerLayout;
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Margin(com.github.bordertech.wcomponents.Margin)

Example 8 with WFieldLayout

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

the class WFieldLayoutExample method recursiveFieldLayout.

/**
 * Create a recursive field layout.
 *
 * @param curr recursion index
 * @param startAt the ordered offset
 * @return the recursive field layout.
 */
private WFieldLayout recursiveFieldLayout(final int curr, final int startAt) {
    WFieldLayout innerLayout = new WFieldLayout();
    innerLayout.setLabelWidth(20);
    if (curr == 0 && startAt == 0) {
        innerLayout.setMargin(new Margin(Size.LARGE, null, null, null));
    }
    innerLayout.setOrdered(true);
    if (startAt > 1) {
        innerLayout.setOrderedOffset(startAt);
    }
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt : 1), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 1 : 2), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 2 : 2), new WTextField());
    if (curr < 4) {
        int next = curr + 1;
        innerLayout.addField("indent level " + String.valueOf(next), recursiveFieldLayout(next, 0));
    }
    innerLayout.addField("Test after nest", new WTextField());
    return innerLayout;
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Margin(com.github.bordertech.wcomponents.Margin)

Example 9 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout 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 com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
    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)

Example 10 with WFieldLayout

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

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