Search in sources :

Example 16 with Margin

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

the class WRadioButtonTriggerActionExample method setup.

/**
 * Add controls to the UI.
 */
private void setup() {
    setLayout(new FlowLayout(FlowLayout.VERTICAL));
    WFieldSet fset = new WFieldSet("Select a meal");
    add(fset);
    fset.setMargin(new Margin(null, null, Size.LARGE, null));
    WFieldLayout flay = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    fset.add(flay);
    flay.setLabelWidth(0);
    flay.addField("Breakfast", rb1);
    flay.addField("Lunch", rb2);
    flay.addField("Dinner", rb3);
    /*
		 * NOTE: you should never use submitOnChange with a WRadioButton
		 */
    fset.add(new WAjaxControl(mealSelections, textBox));
    mealSelections.setActionOnChange(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String selection = null;
            if (rb1.isSelected()) {
                selection = "Breakfast selected";
            }
            if (rb2.isSelected()) {
                selection = "Lunch selected";
            }
            if (rb3.isSelected()) {
                selection = "Dinner selected";
            }
            text1.setText(selection + " : " + (new Date()).toString());
        }
    });
    textBox.add(text1);
    add(textBox);
    add(mealSelections);
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) Action(com.github.bordertech.wcomponents.Action) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Date(java.util.Date) Margin(com.github.bordertech.wcomponents.Margin)

Example 17 with Margin

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

the class GridLayoutOptionsExample method getLayoutControls.

/**
 * build the list controls field set.
 *
 * @param errors the error box to be linked to the apply button.
 * @return a field set for the controls.
 */
private WFieldSet getLayoutControls(final WValidationErrors errors) {
    // Options Layout
    WFieldSet fieldSet = new WFieldSet("List configuration");
    WFieldLayout layout = new ControlFieldLayout();
    fieldSet.add(layout);
    // options.
    columnCount.setDecimalPlaces(0);
    columnCount.setMinValue(0);
    columnCount.setNumber(DEFAULT_COLUMN_COUNT);
    columnCount.setMandatory(true);
    layout.addField("Number of Columns", columnCount);
    rowCount.setDecimalPlaces(0);
    rowCount.setMinValue(0);
    rowCount.setNumber(DEFAULT_ROW_COUNT);
    rowCount.setMandatory(true);
    layout.addField("Number of Rows", rowCount);
    hGap.setDecimalPlaces(0);
    hGap.setMinValue(0);
    hGap.setNumber(0);
    hGap.setMandatory(true);
    layout.addField("Horizontal Gap", hGap);
    vGap.setDecimalPlaces(0);
    vGap.setMinValue(0);
    vGap.setNumber(0);
    vGap.setMandatory(true);
    layout.addField("Vertical Gap", vGap);
    boxCount.setDecimalPlaces(0);
    boxCount.setMinValue(0);
    boxCount.setNumber(DEFAULT_BOX_COUNT);
    boxCount.setMandatory(true);
    layout.addField("Number of Boxes", boxCount);
    layout.addField("Visible", cbVisible);
    layout.addField("Allow responsive design", cbResponsive);
    // Apply Button
    WButton apply = new WButton("Apply");
    apply.setAction(new ValidatingAction(errors, this) {

        @Override
        public void executeOnValid(final ActionEvent event) {
            applySettings();
        }
    });
    layout.addField(apply);
    fieldSet.add(new WAjaxControl(apply, container));
    fieldSet.setMargin(new Margin(null, null, Size.LARGE, null));
    return fieldSet;
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton) Margin(com.github.bordertech.wcomponents.Margin)

Example 18 with Margin

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

the class RepeaterExampleWithStaticIDs method createButtonBar.

/**
 * Create the UI artefacts for the update and reset buttons.
 */
private void createButtonBar() {
    // Update and reset controls for the repeater.
    WPanel buttonPanel = new WPanel(WPanel.Type.FEATURE);
    buttonPanel.setMargin(new Margin(Size.MEDIUM, null, Size.LARGE, null));
    buttonPanel.setLayout(new BorderLayout());
    WButton updateButton = new WButton("Update");
    updateButton.setImage("/image/document-save-5.png");
    updateButton.setImagePosition(WButton.ImagePosition.EAST);
    buttonPanel.add(updateButton, BorderLayout.EAST);
    WButton resetButton = new WButton("Reset");
    resetButton.setImage("/image/edit-undo-8.png");
    resetButton.setImagePosition(WButton.ImagePosition.WEST);
    resetButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            repeater.setData(fetchDataList());
        }
    });
    buttonPanel.add(resetButton, BorderLayout.WEST);
    add(buttonPanel);
    add(new WAjaxControl(updateButton, repeater));
    add(new WAjaxControl(resetButton, repeater));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) Margin(com.github.bordertech.wcomponents.Margin)

Example 19 with Margin

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

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

the class MarginRendererUtil method renderMargin.

/**
 * @param component the marginable component to paint a margin
 * @param renderContext the RenderContext to paint to.
 */
public static void renderMargin(final Marginable component, final WebXmlRenderContext renderContext) {
    Margin margin = component.getMargin();
    if (margin == null) {
        return;
    }
    XmlStringBuilder xml = renderContext.getWriter();
    if (margin.getMargin() != null) {
        xml.appendTagOpen("ui:margin");
        xml.appendAttribute("all", margin.getMargin().toString());
        xml.appendEnd();
    } else if (margin.getTop() != null || margin.getRight() != null || margin.getBottom() != null || margin.getLeft() != null) {
        xml.appendTagOpen("ui:margin");
        Size size = margin.getTop();
        if (size != null) {
            xml.appendAttribute("north", size.toString());
        }
        size = margin.getRight();
        if (size != null) {
            xml.appendAttribute("east", size.toString());
        }
        size = margin.getBottom();
        if (size != null) {
            xml.appendAttribute("south", size.toString());
        }
        size = margin.getLeft();
        if (size != null) {
            xml.appendAttribute("west", size.toString());
        }
        xml.appendEnd();
    }
}
Also used : Size(com.github.bordertech.wcomponents.Size) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Margin(com.github.bordertech.wcomponents.Margin)

Aggregations

Margin (com.github.bordertech.wcomponents.Margin)25 Test (org.junit.Test)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)10 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)6 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)4 WHeading (com.github.bordertech.wcomponents.WHeading)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)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 Disable (com.github.bordertech.wcomponents.subordinate.Disable)2 Enable (com.github.bordertech.wcomponents.subordinate.Enable)2 Equal (com.github.bordertech.wcomponents.subordinate.Equal)2 Rule (com.github.bordertech.wcomponents.subordinate.Rule)2 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)2