Search in sources :

Example 6 with WMultiSelect

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

the class ExpressionBuilder_Test method testAndOperatorPrecedenceBoth.

/**
 * Tests for correct operator precedence when there are ANDs on both sides of the OR: a {@literal &}{@literal &} b
 * || c {@literal &}{@literal &} d.
 */
@Test
public void testAndOperatorPrecedenceBoth() {
    builder.equals(new WTextField(), "1").and().equals(new WTextArea(), "2").or().equals(new WDropdown(), "3").and().equals(new WMultiSelect(), "4");
    Assert.assertEquals("Incorrect condition", "((WTextField=\"1\" and WTextArea=\"2\") or (WDropdown=\"3\" and WMultiSelect=\"4\"))", builder.build().toString());
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WDropdown(com.github.bordertech.wcomponents.WDropdown) WTextField(com.github.bordertech.wcomponents.WTextField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) Test(org.junit.Test)

Example 7 with WMultiSelect

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

the class ExpressionBuilder_Test method testAndandOrWithExpressions.

/**
 * Tests nesting of expression builders to change the order of operations: (a {@literal &}{@literal &} b) || (c
 * {@literal &}{@literal &} d).
 */
@Test
public void testAndandOrWithExpressions() {
    builder.equals(new WTextField(), "1").and(new ExpressionBuilder().equals(new WTextArea(), "2")).or(new ExpressionBuilder().equals(new WDropdown(), "3")).and().equals(new WMultiSelect(), "4");
    Assert.assertEquals("Incorrect condition", "((WTextField=\"1\" and WTextArea=\"2\") or (WDropdown=\"3\" and WMultiSelect=\"4\"))", builder.build().toString());
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WDropdown(com.github.bordertech.wcomponents.WDropdown) WTextField(com.github.bordertech.wcomponents.WTextField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) Test(org.junit.Test)

Example 8 with WMultiSelect

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

the class ExpressionBuilder_Test method testNesting.

/**
 * Tests nesting of expression builders to change the order of operations: (a {@literal &}{@literal &} (b || c)
 * {@literal &}{@literal &} d).
 */
@Test
public void testNesting() {
    builder.equals(new WTextField(), "1").and(new ExpressionBuilder().equals(new WTextArea(), "2").or().equals(new WDropdown(), "3")).and().equals(new WMultiSelect(), "4");
    Assert.assertEquals("Incorrect condition", "(WTextField=\"1\" and (WTextArea=\"2\" or WDropdown=\"3\") and WMultiSelect=\"4\")", builder.build().toString());
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WDropdown(com.github.bordertech.wcomponents.WDropdown) WTextField(com.github.bordertech.wcomponents.WTextField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) Test(org.junit.Test)

Example 9 with WMultiSelect

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

the class ExpressionBuilder_Test method testOrOperatorPrecedenceBoth.

/**
 * Tests for correct operator precedence when there are ANDs on both sides of the OR: a || b
 * {@literal &}{@literal &} c || d.
 */
@Test
public void testOrOperatorPrecedenceBoth() {
    builder.equals(new WTextField(), "1").or().equals(new WTextArea(), "2").and().equals(new WDropdown(), "3").or().equals(new WMultiSelect(), "4");
    Assert.assertEquals("Incorrect condition", "(WTextField=\"1\" or ((WTextArea=\"2\" and WDropdown=\"3\") or WMultiSelect=\"4\"))", builder.build().toString());
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WDropdown(com.github.bordertech.wcomponents.WDropdown) WTextField(com.github.bordertech.wcomponents.WTextField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) Test(org.junit.Test)

Example 10 with WMultiSelect

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

the class WMultiSelectRenderer method doRender.

/**
 * Paints the given WMultiSelect.
 *
 * @param component the WMultiSelect to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiSelect listBox = (WMultiSelect) component;
    XmlStringBuilder xml = renderContext.getWriter();
    String dataKey = listBox.getListCacheKey();
    boolean readOnly = listBox.isReadOnly();
    int rows = listBox.getRows();
    int min = listBox.getMinSelect();
    int max = listBox.getMaxSelect();
    xml.appendTagOpen("ui:listbox");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", listBox.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("data", dataKey != null && !readOnly, dataKey);
        xml.appendOptionalAttribute("disabled", listBox.isDisabled(), "true");
        xml.appendOptionalAttribute("required", listBox.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", listBox.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", component.getToolTip());
        xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
        xml.appendOptionalAttribute("rows", rows >= 2, rows);
        xml.appendOptionalAttribute("min", min > 0, min);
        xml.appendOptionalAttribute("max", max > 0, max);
    }
    xml.appendClose();
    // Options
    List<?> options = listBox.getOptions();
    boolean renderSelectionsOnly = readOnly || dataKey != null;
    if (options != null) {
        int optionIndex = 0;
        List<?> selections = listBox.getSelected();
        for (Object option : options) {
            if (option instanceof OptionGroup) {
                xml.appendTagOpen("ui:optgroup");
                xml.appendAttribute("label", ((OptionGroup) option).getDesc());
                xml.appendClose();
                for (Object nestedOption : ((OptionGroup) option).getOptions()) {
                    renderOption(listBox, nestedOption, optionIndex++, xml, selections, renderSelectionsOnly);
                }
                xml.appendEndTag("ui:optgroup");
            } else {
                renderOption(listBox, option, optionIndex++, xml, selections, renderSelectionsOnly);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(listBox, renderContext);
    }
    xml.appendEndTag("ui:listbox");
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect)

Aggregations

WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)14 Test (org.junit.Test)11 WDropdown (com.github.bordertech.wcomponents.WDropdown)6 WTextArea (com.github.bordertech.wcomponents.WTextArea)5 WTextField (com.github.bordertech.wcomponents.WTextField)5 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)3 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WDateField (com.github.bordertech.wcomponents.WDateField)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMultiDropdown (com.github.bordertech.wcomponents.WMultiDropdown)1 WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)1 WNumberField (com.github.bordertech.wcomponents.WNumberField)1 WPartialDateField (com.github.bordertech.wcomponents.WPartialDateField)1 WPasswordField (com.github.bordertech.wcomponents.WPasswordField)1 WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)1