Search in sources :

Example 26 with WDropdown

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

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

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

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

the class WDropdownRenderer method doRender.

/**
 * Paints the given WDropdown.
 *
 * @param component the WDropdown to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDropdown dropdown = (WDropdown) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = dropdown.isReadOnly();
    String dataKey = dropdown.getListCacheKey();
    // Start tag
    xml.appendTagOpen("ui:dropdown");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", dropdown.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("data", dataKey != null, dataKey);
        xml.appendOptionalAttribute("disabled", dropdown.isDisabled(), "true");
        xml.appendOptionalAttribute("required", dropdown.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", dropdown.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", dropdown.getToolTip());
        xml.appendOptionalAttribute("accessibleText", dropdown.getAccessibleText());
        int optionWidth = dropdown.getOptionWidth();
        xml.appendOptionalAttribute("optionWidth", optionWidth > 0, optionWidth);
        xml.appendOptionalAttribute("type", getTypeAsString(dropdown.getType()));
    }
    xml.appendClose();
    // Options
    List<?> options = dropdown.getOptions();
    Object selectedOption = dropdown.getSelected();
    // For an editable dropdown (combo box), the selected option may not be in the list.
    if (dropdown.getType() == WDropdown.DropdownType.COMBO && selectedOption != null && (options == null || !options.contains(selectedOption))) {
        xml.appendTagOpen("ui:option");
        xml.appendAttribute("value", selectedOption.toString());
        xml.appendAttribute("selected", "true");
        xml.appendClose();
        xml.appendEscaped(selectedOption.toString());
        xml.appendEndTag("ui:option");
    }
    if (options != null) {
        int optionIndex = 0;
        boolean renderSelectionsOnly = readOnly || dataKey != null;
        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(dropdown, nestedOption, optionIndex++, xml, selectedOption, renderSelectionsOnly);
                }
                xml.appendEndTag("ui:optgroup");
            } else {
                renderOption(dropdown, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(dropdown, renderContext);
    }
    // End tag
    xml.appendEndTag("ui:dropdown");
}
Also used : WDropdown(com.github.bordertech.wcomponents.WDropdown) OptionGroup(com.github.bordertech.wcomponents.OptionGroup) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 30 with WDropdown

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

the class WSubordinateControlRenderer_Test method testConditionWithListTrigger.

@Test
public void testConditionWithListTrigger() throws IOException, SAXException, XpathException {
    WDropdown condTrigger = new WDropdown();
    SubordinateTarget actionTarget = new WTextField();
    // Setup a rule with a condition using a dropdown
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, "b"));
    rule.addActionOnTrue(new Show(actionTarget));
    rule.addActionOnFalse(new Hide(actionTarget));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget);
    root.add(control);
    condTrigger.setOptions(Arrays.asList(new String[] { "a", "b", "c", "d", "e" }));
    condTrigger.setSelected("e");
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check Condition Value is the "Code Value"
    assertXpathEvaluatesTo("2", "//ui:subordinate/ui:condition/@value", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) WDropdown(com.github.bordertech.wcomponents.WDropdown) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

WDropdown (com.github.bordertech.wcomponents.WDropdown)33 Test (org.junit.Test)28 WTextField (com.github.bordertech.wcomponents.WTextField)12 WTextArea (com.github.bordertech.wcomponents.WTextArea)10 UIContext (com.github.bordertech.wcomponents.UIContext)7 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)6 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)6 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)3 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)3 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2 Equal (com.github.bordertech.wcomponents.subordinate.Equal)2 Hide (com.github.bordertech.wcomponents.subordinate.Hide)2 Rule (com.github.bordertech.wcomponents.subordinate.Rule)2 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)2 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 TestLookupTable (com.github.bordertech.wcomponents.TestLookupTable)1