Search in sources :

Example 26 with WHeading

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

the class WRadioButtonSelectExample method addInsideAFieldLayoutExample.

/**
 * When a WRadioButtonSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame,
 * the second doesn't
 */
private void addInsideAFieldLayoutExample() {
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect inside a WFieldLayout"));
    add(new ExplanatoryText("When a WRadioButtonSelect is inside a WField its label is exposed in a way which appears and behaves like a regular HTML label." + " This allows WRadioButtonSelects to be used in a layout with simple form controls (such as WTextField) and produce a consistent" + " and predicatable interface.\n" + "The third example in this set uses a null label and a toolTip to hide the labelling element. This can lead to user confusion and" + " is not recommended."));
    // Note: the wrapper WPanel here is to work around a bug in validation. See https://github.com/BorderTech/wcomponents/issues/1370
    final WPanel wrapper = new WPanel();
    add(wrapper);
    final WMessages messages = new WMessages();
    wrapper.add(messages);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    wrapper.add(layout);
    WButton resetThisBit = new WButton("Reset this bit");
    resetThisBit.setCancel(true);
    resetThisBit.setAjaxTarget(wrapper);
    resetThisBit.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            wrapper.reset();
        }
    });
    layout.addField(resetThisBit);
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    WRadioButtonSelect select = new WRadioButtonSelect(options);
    layout.addField("Select an animal", select);
    String[] options2 = new String[] { "Parrot", "Galah", "Cockatoo", "Lyre" };
    select = new WRadioButtonSelect(options2);
    select.setMandatory(true);
    layout.addField("You must select a bird", select);
    select.setFrameless(true);
    // a tooltip can be used as a label stand-in even in a WField
    String[] options3 = new String[] { "Carrot", "Beet", "Brocolli", "Bacon - the perfect vegetable" };
    select = new WRadioButtonSelect(options3);
    // if you absolutely do not want a WLabel in a WField then it has to be added using null cast to a WLabel.
    layout.addField((WLabel) null, select);
    select.setToolTip("Veggies");
    WButton btnValidate = new WButton("validate");
    btnValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // do nothing
        }
    });
    layout.addField(btnValidate);
    wrapper.add(new WAjaxControl(btnValidate, wrapper));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WMessages(com.github.bordertech.wcomponents.WMessages) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect)

Example 27 with WHeading

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

the class WRadioButtonSelectExample method addReadOnlyExamples.

/**
 * Examples of readonly states. When in a read only state only the selected option is output. Since a
 * WRadioButtonSeelct can only have 0 or 1 selected option the LAYOUT and FRAME are ignored.
 */
private void addReadOnlyExamples() {
    add(new WHeading(HeadingLevel.H3, "Read-only WRadioButtonSelect examples"));
    add(new ExplanatoryText("These examples all use the same list of options: the states and territories list from the editable examples above. " + "When the readOnly state is specified only that option which is selected is output.\n" + "Since no more than one option is able to be selected the layout and frame settings are ignored in the read only state."));
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    WRadioButtonSelect select = new WRadioButtonSelect("australian_state");
    select.setReadOnly(true);
    layout.addField("Read only with no selection", select);
    select = new SelectWithSelection("australian_state");
    select.setReadOnly(true);
    layout.addField("Read only with selection", select);
}
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)

Example 28 with WHeading

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

the class WRadioButtonSelectExample method addFlatSelectExample.

/*
	 * WRadioButtonSelect layout options
	 * These examples show the various ways to lay out the options in a WRadioButtonSelect
	 * NOTE: the default (if no buttonLayout is set) is LAYOUT_STACKED
	 */
/**
 * adds a WRadioButtonSelect with LAYOUT_FLAT.
 */
private void addFlatSelectExample() {
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with flat layout"));
    add(new ExplanatoryText("Setting the layout to FLAT will make the radio buttons be rendered in a horizontal line. They will wrap when they" + " reach the edge of the parent container."));
    final WRadioButtonSelect select = new WRadioButtonSelect("australian_state");
    select.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    add(new WLabel("Flat selection", select));
    add(select);
}
Also used : 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)

Example 29 with WHeading

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

the class WHeadingRenderer method doRender.

/**
 * Paints the given WHeading.
 *
 * @param component the WHeading to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WHeading heading = (WHeading) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:heading");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendAttribute("level", heading.getHeadingLevel().getLevel());
    xml.appendOptionalAttribute("accessibleText", heading.getAccessibleText());
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(heading, renderContext);
    if (heading.getDecoratedLabel() == null) {
        // Constructed with a String
        xml.append(heading.getText(), heading.isEncodeText());
    } else {
        heading.getDecoratedLabel().paint(renderContext);
    }
    xml.appendEndTag("ui:heading");
}
Also used : XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 30 with WHeading

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

the class WHeadingRenderer_Test method testPaint.

@Test
public void testPaint() throws IOException, SAXException, XpathException {
    final String text = "WHeading_Test.testPaint.heading";
    WHeading heading = new WHeading(WHeading.TITLE, text);
    assertSchemaMatch(heading);
    assertXpathEvaluatesTo(text, "//ui:heading[@level=1]", heading);
    heading = new WHeading(WHeading.MAJOR, text);
    assertSchemaMatch(heading);
    assertXpathEvaluatesTo(text, "//ui:heading[@level=2]", heading);
    heading = new WHeading(WHeading.SECTION, text);
    assertSchemaMatch(heading);
    assertXpathEvaluatesTo(text, "//ui:heading[@level=3]", heading);
    heading = new WHeading(WHeading.MINOR, text);
    assertSchemaMatch(heading);
    assertXpathEvaluatesTo(text, "//ui:heading[@level=4]", heading);
    heading = new WHeading(WHeading.SUB_HEADING, text);
    assertSchemaMatch(heading);
    assertXpathEvaluatesTo(text, "//ui:heading[@level=5]", heading);
    heading = new WHeading(WHeading.SUB_SUB_HEADING, text);
    assertSchemaMatch(heading);
    assertXpathEvaluatesTo(text, "//ui:heading[@level=6]", heading);
    try {
        heading = new WHeading(123456, text);
        Assert.fail("Should have thrown a SystemException");
    } catch (IllegalArgumentException expected) {
        Assert.assertNotNull("Thrown exception should contain a message", expected.getMessage());
    }
}
Also used : WHeading(com.github.bordertech.wcomponents.WHeading) Test(org.junit.Test)

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