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);
}
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));
}
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;
}
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;
}
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;
}
Aggregations