use of com.github.bordertech.wcomponents.subordinate.DisableInGroup 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.DisableInGroup in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testGroupEnableInDisableInAction.
@Test
public void testGroupEnableInDisableInAction() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WCheckBox();
// Setup Group
SubordinateTarget actionTarget1 = new WTextField();
SubordinateTarget actionTarget2 = new WTextField();
SubordinateTarget actionTarget3 = new WTextField();
WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
group1.addToGroup(actionTarget1);
group1.addToGroup(actionTarget2);
group1.addToGroup(actionTarget3);
// Setup Rule with ShowInGroup/HideInGroup actions
Rule rule = new Rule();
rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
// OnTrue - EnableInGroup
rule.addActionOnTrue(new EnableInGroup(actionTarget1, group1));
// OnFalse - DisableInGroup
rule.addActionOnFalse(new DisableInGroup(actionTarget1, group1));
// Setup Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
WContainer root = new WContainer();
root.add(condTrigger);
root.add(actionTarget1);
root.add(actionTarget2);
root.add(actionTarget3);
root.add(control);
root.add(group1);
setActiveContext(createUIContext());
// Apply the controls (False conditions)
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check onTrue
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onTrue)", root);
assertXpathEvaluatesTo("enableIn", "//ui:subordinate/ui:onTrue/@action", root);
assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@groupId", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@id", root);
// Check onFalse
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onFalse)", root);
assertXpathEvaluatesTo("disableIn", "//ui:subordinate/ui:onFalse/@action", root);
assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@groupId", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@id", root);
// Check action target (Target 1 should be disabled)
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@disabled", root);
assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@disabled", root);
assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@disabled", root);
}
Aggregations