use of com.github.bordertech.wcomponents.subordinate.Condition in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method buildControl.
/**
* Build the subordinate control.
*/
private void buildControl() {
buildControlPanel.reset();
buildTargetPanel.reset();
// Setup Trigger
setupTrigger();
// Create target
SubordinateTarget target = setupTarget();
// Create Actions
com.github.bordertech.wcomponents.subordinate.Action trueAction;
com.github.bordertech.wcomponents.subordinate.Action falseAction;
switch((ControlActionType) drpActionType.getSelected()) {
case ENABLE_DISABLE:
trueAction = new Enable(target);
falseAction = new Disable(target);
break;
case SHOW_HIDE:
trueAction = new Show(target);
falseAction = new Hide(target);
break;
case MAN_OPT:
trueAction = new Mandatory(target);
falseAction = new Optional(target);
break;
case SHOWIN_HIDEIN:
trueAction = new ShowInGroup(target, targetGroup);
falseAction = new HideInGroup(target, targetGroup);
break;
case ENABLEIN_DISABLEIN:
trueAction = new EnableInGroup(target, targetGroup);
falseAction = new DisableInGroup(target, targetGroup);
break;
default:
throw new SystemException("ControlAction type not valid");
}
// Create Condition
Condition condition = createCondition();
if (cbNot.isSelected()) {
condition = new Not(condition);
}
// Create Rule
Rule rule = new Rule(condition, trueAction, falseAction);
// Create Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
buildControlPanel.add(control);
if (targetCollapsible.getDecoratedLabel() != null) {
targetCollapsible.getDecoratedLabel().setTail(new WText(control.toString()));
}
control = new WSubordinateControl();
rule = new Rule(new Equal(cbClientDisableTrigger, true), new Disable((SubordinateTarget) trigger), new Enable((SubordinateTarget) trigger));
control.addRule(rule);
buildControlPanel.add(control);
}
use of com.github.bordertech.wcomponents.subordinate.Condition 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