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