use of com.github.bordertech.wcomponents.subordinate.ShowInGroup in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testGroupShowInHideInAction.
@Test
public void testGroupShowInHideInAction() 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 - ShowInGroup
rule.addActionOnTrue(new ShowInGroup(actionTarget1, group1));
// OnFalse - HideInGroup
rule.addActionOnFalse(new HideInGroup(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("showIn", "//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("hideIn", "//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 hidden)
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@hidden", root);
assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@hidden", root);
assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@hidden", root);
}
use of com.github.bordertech.wcomponents.subordinate.ShowInGroup 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.ShowInGroup in project wcomponents by BorderTech.
the class WDropdownOptionsExample method buildSubordinatePanel.
/**
* Builds a panel for the subordinate control, including the rule for that particular option.
*
* @param dropdown the subordinate trigger.
* @param value the dropdown option to be added
* @param group the group
* @param control the subordinate control
*/
private void buildSubordinatePanel(final WDropdown dropdown, final String value, final WComponentGroup<SubordinateTarget> group, final WSubordinateControl control) {
// create the panel.
WPanel panel = new WPanel();
WStyledText subordinateInfo = new WStyledText();
subordinateInfo.setWhitespaceMode(WhitespaceMode.PRESERVE);
subordinateInfo.setText(value + " - Subordinate");
panel.add(subordinateInfo);
// add the panel to the screen and group.
infoPanel.add(panel);
group.addToGroup(panel);
// create the rule
Rule rule = new Rule();
control.addRule(rule);
rule.setCondition(new Equal(dropdown, value));
rule.addActionOnTrue(new ShowInGroup(panel, group));
}
Aggregations