use of com.github.bordertech.wcomponents.subordinate.Or in project wcomponents by BorderTech.
the class WSubordinateControlRenderer method paintCondition.
/**
* Paints a condition.
*
* @param condition the condition to paint.
* @param xml the writer to send the output to
*/
private void paintCondition(final Condition condition, final XmlStringBuilder xml) {
if (condition instanceof And) {
xml.appendTag("ui:and");
for (Condition operand : ((And) condition).getConditions()) {
paintCondition(operand, xml);
}
xml.appendEndTag("ui:and");
} else if (condition instanceof Or) {
xml.appendTag("ui:or");
for (Condition operand : ((Or) condition).getConditions()) {
paintCondition(operand, xml);
}
xml.appendEndTag("ui:or");
} else if (condition instanceof Not) {
xml.appendTag("ui:not");
paintCondition(((Not) condition).getCondition(), xml);
xml.appendEndTag("ui:not");
} else if (condition instanceof AbstractCompare) {
AbstractCompare compare = (AbstractCompare) condition;
xml.appendTagOpen("ui:condition");
xml.appendAttribute("controller", compare.getTrigger().getId());
xml.appendAttribute("value", compare.getComparePaintValue());
xml.appendOptionalAttribute("operator", getCompareTypeName(compare.getCompareType()));
xml.appendEnd();
} else {
throw new SystemException("Unknown condition: " + condition);
}
}
use of com.github.bordertech.wcomponents.subordinate.Or in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testNestedConditions.
@Test
public void testNestedConditions() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WCheckBox();
// Create Nested Condition
Condition cond1 = new Equal(condTrigger, Boolean.TRUE);
Condition cond2 = new Equal(condTrigger, Boolean.TRUE);
Condition cond3 = new Equal(condTrigger, Boolean.TRUE);
Condition cond4 = new Equal(condTrigger, Boolean.TRUE);
Condition orTest = new Or(cond1, cond2);
Condition and1 = new And(cond3, orTest);
Condition and2 = new And(cond4, and1);
SubordinateTarget actionTarget = new WTextField();
// Setup rule with Nested Condition
Rule rule = new Rule();
rule.setCondition(and2);
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);
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check Nested
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:condition)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:condition)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:or)", root);
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:and/ui:and/ui:or/ui:condition)", root);
// Check action target
assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
use of com.github.bordertech.wcomponents.subordinate.Or in project wcomponents by BorderTech.
the class WPanelTypeExample method buildSubordinates.
/**
* The subordinate controls used to show/hide parts of the configuration options based on the selected WPanel Type.
*/
private void buildSubordinates() {
WSubordinateControl control = new WSubordinateControl();
Rule rule = new Rule();
rule.setCondition(new Equal(panelType, WPanel.Type.HEADER));
rule.addActionOnTrue(new Show(showUtilBarField));
rule.addActionOnTrue(new Show(showMenuField));
rule.addActionOnTrue(new Hide(contentField));
rule.addActionOnFalse(new Hide(showUtilBarField));
rule.addActionOnFalse(new Hide(showMenuField));
rule.addActionOnFalse(new Show(contentField));
control.addRule(rule);
rule = new Rule();
rule.setCondition(new Or(new Equal(panelType, WPanel.Type.CHROME), new Equal(panelType, WPanel.Type.ACTION), new Equal(panelType, WPanel.Type.HEADER)));
rule.addActionOnTrue(new Show(headingField));
rule.addActionOnFalse(new Hide(headingField));
control.addRule(rule);
add(control);
}
use of com.github.bordertech.wcomponents.subordinate.Or in project wcomponents by BorderTech.
the class GroupExpression_Test method testBuildOr.
@Test
public void testBuildOr() {
GroupExpression expr = new GroupExpression(GroupExpression.Type.OR);
BooleanExpression operand1 = new CompareExpression(CompareType.EQUAL, new WTextField(), "1");
BooleanExpression operand2 = new CompareExpression(CompareType.EQUAL, new WTextField(), "2");
BooleanExpression operand3 = new CompareExpression(CompareType.EQUAL, new WTextField(), "3");
expr.add(operand1);
expr.add(operand2);
expr.add(operand3);
Or condition = (Or) expr.build();
Assert.assertEquals("Incorrect 1st operand for OR", operand1.build().toString(), condition.getConditions().get(0).toString());
Assert.assertEquals("Incorrect 2nd operand for OR", operand2.build().toString(), condition.getConditions().get(1).toString());
Assert.assertEquals("Incorrect 3rd operand for OR", operand3.build().toString(), condition.getConditions().get(2).toString());
}
use of com.github.bordertech.wcomponents.subordinate.Or in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testOrCondition.
@Test
public void testOrCondition() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger1 = new WCheckBox();
SubordinateTrigger condTrigger2 = new WCheckBox();
SubordinateTrigger condTrigger3 = new WCheckBox();
// Create OR condition
Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
Condition orTest = new Or(cond1, cond2, cond3);
SubordinateTarget actionTarget = new WTextField();
// Setup rule with OR condition
Rule rule = new Rule();
rule.setCondition(orTest);
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(condTrigger1);
root.add(condTrigger2);
root.add(condTrigger3);
root.add(actionTarget);
root.add(control);
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check OR
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:or)", root);
assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:or/ui:condition)", root);
assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:or/ui:condition[position()=1]/@controller", root);
assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:or/ui:condition[position()=2]/@controller", root);
assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:or/ui:condition[position()=3]/@controller", root);
// Check action target
assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
Aggregations