use of com.github.bordertech.wcomponents.subordinate.Condition 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.Condition in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testAndCondition.
@Test
public void testAndCondition() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger1 = new WCheckBox();
SubordinateTrigger condTrigger2 = new WCheckBox();
SubordinateTrigger condTrigger3 = new WCheckBox();
// Create AND condition
Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
Condition and = new And(cond1, cond2, cond3);
SubordinateTarget actionTarget = new WTextField();
// Setup Rule with AND Condition
Rule rule = new Rule();
rule.setCondition(and);
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 AND
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:and/ui:condition)", root);
assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:and/ui:condition[position()=1]/@controller", root);
assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:and/ui:condition[position()=2]/@controller", root);
assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:and/ui:condition[position()=3]/@controller", root);
// Check action target
assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
use of com.github.bordertech.wcomponents.subordinate.Condition 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.Condition in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testAllConditions.
@Test
public void testAllConditions() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WNumberField();
SubordinateTrigger condTrigger2 = new WTextField();
SubordinateTarget actionTarget = new WTextField();
BigDecimal value = BigDecimal.valueOf(2);
Condition cond1 = new Equal(condTrigger, value);
Condition cond2 = new NotEqual(condTrigger, value);
Condition cond3 = new LessThan(condTrigger, value);
Condition cond4 = new LessThanOrEqual(condTrigger, value);
Condition cond5 = new GreaterThan(condTrigger, value);
Condition cond6 = new GreaterThanOrEqual(condTrigger, value);
Condition cond7 = new Match(condTrigger2, "[abc]");
// Basic Condition
Rule rule = new Rule();
rule.setCondition(new And(cond1, cond2, cond3, cond4, cond5, cond6, cond7));
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(condTrigger2);
root.add(actionTarget);
root.add(control);
setActiveContext(createUIContext());
// Validate Schema
assertSchemaMatch(root);
assertXpathNotExists("//ui:subordinate/ui:and/ui:condition[1]/@operator", root);
assertXpathEvaluatesTo("ne", "//ui:subordinate/ui:and/ui:condition[2]/@operator", root);
assertXpathEvaluatesTo("lt", "//ui:subordinate/ui:and/ui:condition[3]/@operator", root);
assertXpathEvaluatesTo("le", "//ui:subordinate/ui:and/ui:condition[4]/@operator", root);
assertXpathEvaluatesTo("gt", "//ui:subordinate/ui:and/ui:condition[5]/@operator", root);
assertXpathEvaluatesTo("ge", "//ui:subordinate/ui:and/ui:condition[6]/@operator", root);
assertXpathEvaluatesTo("rx", "//ui:subordinate/ui:and/ui:condition[7]/@operator", root);
}
use of com.github.bordertech.wcomponents.subordinate.Condition in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method createCondition.
/**
* @return the condition for the subordinate control.
*/
private Condition createCondition() {
// Compare value
Object value;
switch((TriggerType) drpTriggerType.getSelected()) {
case DateField:
value = dateCompareValue.getValue();
break;
case NumberField:
value = numberCompareValue.getValue();
break;
default:
value = comboCompareValue.getValue();
break;
}
// Create condition
Condition condition;
switch((CompareType) drpCompareType.getSelected()) {
case EQUAL:
condition = new Equal(trigger, value);
break;
case NOT_EQUAL:
condition = new NotEqual(trigger, value);
break;
case LESS_THAN:
condition = new LessThan(trigger, value);
break;
case LESS_THAN_OR_EQUAL:
condition = new LessThanOrEqual(trigger, value);
break;
case GREATER_THAN:
condition = new GreaterThan(trigger, value);
break;
case GREATER_THAN_OR_EQUAL:
condition = new GreaterThanOrEqual(trigger, value);
break;
case MATCH:
condition = new Match(trigger, (String) value);
break;
default:
throw new SystemException("Compare type not valid");
}
return condition;
}
Aggregations