Search in sources :

Example 16 with WCheckBoxSelect

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

the class WListOptionsExample method getBeanFieldsCheckBoxSelect.

/**
 * This builds and returns a WCheckbox group containing the list of fields on the {@link SimpleTableBean}.
 *
 * @return a WCheckBoxSelect
 */
private WCheckBoxSelect getBeanFieldsCheckBoxSelect() {
    List<String> options = new ArrayList<>();
    options.add("Name");
    options.add("Type");
    options.add("Thing");
    List<String> defaults = new ArrayList<>();
    defaults.add("Name");
    WCheckBoxSelect cgproperties = new WCheckBoxSelect(options);
    cgproperties.setSelected(defaults);
    return cgproperties;
}
Also used : ArrayList(java.util.ArrayList) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 17 with WCheckBoxSelect

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

the class WDropdownSpaceHandlingExample_Test method testCheckbox.

@Test
public void testCheckbox() {
    WDropdownSpaceHandlingExample example = (WDropdownSpaceHandlingExample) getUi();
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    try {
        WCheckBoxSelect group = (WCheckBoxSelect) TreeUtil.findWComponent(example, new String[] { "WCheckBoxSelect" }).getComponent();
        List<?> options = group.getOptions();
        for (Object option : options) {
            driver.findElement(byWComponent(group, option)).click();
            driver.findElement(byWComponentPath("WButton")).click();
            Assert.assertEquals("Incorrect option selected", option, group.getSelected().get(0));
            // De-select option
            driver.findElement(byWComponent(group, option)).click();
        }
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) UIContext(com.github.bordertech.wcomponents.UIContext) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) Test(org.junit.Test)

Example 18 with WCheckBoxSelect

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

the class WCheckBoxSelectRenderer method doRender.

/**
 * Paints the given WCheckBoxSelect.
 *
 * @param component the WCheckBoxSelect to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WCheckBoxSelect select = (WCheckBoxSelect) component;
    XmlStringBuilder xml = renderContext.getWriter();
    int cols = select.getButtonColumns();
    boolean readOnly = select.isReadOnly();
    xml.appendTagOpen("ui:checkboxselect");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", select.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int min = select.getMinSelect();
        int max = select.getMaxSelect();
        xml.appendOptionalAttribute("disabled", select.isDisabled(), "true");
        xml.appendOptionalAttribute("required", select.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", select.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", component.getToolTip());
        xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
        xml.appendOptionalAttribute("min", min > 0, min);
        xml.appendOptionalAttribute("max", max > 0, max);
    }
    xml.appendOptionalAttribute("frameless", select.isFrameless(), "true");
    switch(select.getButtonLayout()) {
        case COLUMNS:
            xml.appendAttribute("layout", "column");
            xml.appendOptionalAttribute("layoutColumnCount", cols > 0, cols);
            break;
        case FLAT:
            xml.appendAttribute("layout", "flat");
            break;
        case STACKED:
            xml.appendAttribute("layout", "stacked");
            break;
        default:
            throw new SystemException("Unknown layout type: " + select.getButtonLayout());
    }
    xml.appendClose();
    // Options
    List<?> options = select.getOptions();
    boolean renderSelectionsOnly = readOnly;
    if (options != null) {
        int optionIndex = 0;
        List<?> selections = select.getSelected();
        for (Object option : options) {
            if (option instanceof OptionGroup) {
                throw new SystemException("Option groups not supported in WCheckBoxSelect.");
            } else {
                renderOption(select, option, optionIndex++, xml, selections, renderSelectionsOnly);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(select, renderContext);
    }
    xml.appendEndTag("ui:checkboxselect");
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 19 with WCheckBoxSelect

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

the class WLabelRenderer_Test method testWhatForGroup1.

@Test
public void testWhatForGroup1() throws IOException, SAXException, XpathException {
    WCheckBoxSelect comp = new WCheckBoxSelect();
    WLabel label = new WLabel("label", comp);
    assertSchemaMatch(label);
    assertXpathEvaluatesTo("group", "//ui:label/@what", label);
}
Also used : WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 20 with WCheckBoxSelect

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

the class WCheckBoxSelectRenderer_Test method testDoPaintAllOptions.

@Test
public void testDoPaintAllOptions() throws IOException, SAXException, XpathException {
    WCheckBoxSelect wcbTest = new WCheckBoxSelect(new String[] { "a", "b", "c" });
    assertSchemaMatch(wcbTest);
    wcbTest.setDisabled(true);
    setFlag(wcbTest, ComponentModel.HIDE_FLAG, true);
    wcbTest.setMandatory(true);
    wcbTest.setSubmitOnChange(true);
    wcbTest.setToolTip("tool tip");
    wcbTest.setAccessibleText("accessible text");
    wcbTest.setFrameless(true);
    wcbTest.setMinSelect(1);
    wcbTest.setMaxSelect(2);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(wcbTest.getId(), "//ui:checkboxselect/@id", wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkboxselect/@disabled", wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkboxselect/@hidden", wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkboxselect/@required", wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkboxselect/@submitOnChange", wcbTest);
    assertXpathEvaluatesTo("tool tip", "//ui:checkboxselect/@toolTip", wcbTest);
    assertXpathEvaluatesTo("accessible text", "//ui:checkboxselect/@accessibleText", wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkboxselect/@frameless", wcbTest);
    assertXpathEvaluatesTo("1", "//ui:checkboxselect/@min", wcbTest);
    assertXpathEvaluatesTo("2", "//ui:checkboxselect/@max", wcbTest);
    // Button Layouts
    wcbTest.setButtonLayout(WCheckBoxSelect.LAYOUT_COLUMNS);
    wcbTest.setButtonColumns(3);
    assertXpathEvaluatesTo("column", "//ui:checkboxselect/@layout", wcbTest);
    assertXpathEvaluatesTo("3", "//ui:checkboxselect/@layoutColumnCount", wcbTest);
    wcbTest.setButtonLayout(WCheckBoxSelect.LAYOUT_FLAT);
    assertXpathEvaluatesTo("flat", "//ui:checkboxselect/@layout", wcbTest);
    assertXpathNotExists("//ui:checkboxselect/@layoutColumnCount", wcbTest);
    wcbTest.setButtonLayout(WCheckBoxSelect.LAYOUT_STACKED);
    assertXpathEvaluatesTo("stacked", "//ui:checkboxselect/@layout", wcbTest);
    assertXpathNotExists("//ui:checkboxselect/@layoutColumnCount", wcbTest);
}
Also used : WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) Test(org.junit.Test)

Aggregations

WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)23 WHeading (com.github.bordertech.wcomponents.WHeading)12 Test (org.junit.Test)8 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)7 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)6 WLabel (com.github.bordertech.wcomponents.WLabel)6 WTextField (com.github.bordertech.wcomponents.WTextField)6 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WButton (com.github.bordertech.wcomponents.WButton)4 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 WDateField (com.github.bordertech.wcomponents.WDateField)2 WText (com.github.bordertech.wcomponents.WText)2 WTextArea (com.github.bordertech.wcomponents.WTextArea)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 ArrayList (java.util.ArrayList)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 UIContext (com.github.bordertech.wcomponents.UIContext)1