Search in sources :

Example 1 with Margin

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

Example 2 with Margin

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

the class RepeaterExampleWithStaticIDs method createPrintContactsSubForm.

/**
 * Create the UI artefacts for the "Print contacts" sub form.
 */
private void createPrintContactsSubForm() {
    add(new WHeading(HeadingLevel.H3, "Print to CSV"));
    WButton printBtn = new WButton("Print");
    printBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            printDetails();
        }
    });
    printBtn.setImage("/image/document-print.png");
    printBtn.setImagePosition(WButton.ImagePosition.EAST);
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    layout.setMargin(new Margin(Size.LARGE, null, null, null));
    layout.addField("Print output", printOutput);
    layout.addField((WLabel) null, printBtn);
    add(new WAjaxControl(printBtn, printOutput));
}
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) Margin(com.github.bordertech.wcomponents.Margin)

Example 3 with Margin

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

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

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

Aggregations

Margin (com.github.bordertech.wcomponents.Margin)26 Test (org.junit.Test)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)6 WHeading (com.github.bordertech.wcomponents.WHeading)6 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)5 WTextField (com.github.bordertech.wcomponents.WTextField)5 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WText (com.github.bordertech.wcomponents.WText)4 Action (com.github.bordertech.wcomponents.Action)3 WButton (com.github.bordertech.wcomponents.WButton)3 WPanel (com.github.bordertech.wcomponents.WPanel)3 WLabel (com.github.bordertech.wcomponents.WLabel)2 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)2 FlowLayout (com.github.bordertech.wcomponents.layout.FlowLayout)2 Equal (com.github.bordertech.wcomponents.subordinate.Equal)2 Hide (com.github.bordertech.wcomponents.subordinate.Hide)2 Rule (com.github.bordertech.wcomponents.subordinate.Rule)2 Show (com.github.bordertech.wcomponents.subordinate.Show)2 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)2