Search in sources :

Example 26 with Rule

use of com.github.bordertech.wcomponents.subordinate.Rule in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testConditionWithListTrigger.

@Test
public void testConditionWithListTrigger() throws IOException, SAXException, XpathException {
    WDropdown condTrigger = new WDropdown();
    SubordinateTarget actionTarget = new WTextField();
    // Setup a rule with a condition using a dropdown
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, "b"));
    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);
    condTrigger.setOptions(Arrays.asList(new String[] { "a", "b", "c", "d", "e" }));
    condTrigger.setSelected("e");
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check Condition Value is the "Code Value"
    assertXpathEvaluatesTo("2", "//ui:subordinate/ui:condition/@value", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) WDropdown(com.github.bordertech.wcomponents.WDropdown) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 27 with Rule

use of com.github.bordertech.wcomponents.subordinate.Rule in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testMandatoryOptionalActions.

@Test
public void testMandatoryOptionalActions() throws IOException, SAXException, XpathException {
    WCheckBox condTrigger = new WCheckBox();
    // Setup Group
    SubordinateTarget actionTarget = new WTextField();
    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 Mandatory/Optional actions
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    // Single Component Target
    rule.addActionOnTrue(new Mandatory(actionTarget));
    rule.addActionOnFalse(new Optional(actionTarget));
    // Group Target
    rule.addActionOnTrue(new Mandatory(group1));
    rule.addActionOnFalse(new Optional(group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    condTrigger.setSelected(true);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check onTrue
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    // Check onTrue - Component
    assertXpathEvaluatesTo("mandatory", "//ui:subordinate/ui:onTrue[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@groupId", root);
    // Check onTrue - Group
    assertXpathEvaluatesTo("mandatory", "//ui:subordinate/ui:onTrue[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
    // Check onFalse - Component
    assertXpathEvaluatesTo("optional", "//ui:subordinate/ui:onFalse[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@groupId", root);
    // Check onFalse - Group
    assertXpathEvaluatesTo("optional", "//ui:subordinate/ui:onFalse[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@id", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@required", root);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory) Test(org.junit.Test)

Aggregations

Rule (com.github.bordertech.wcomponents.subordinate.Rule)27 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)26 Equal (com.github.bordertech.wcomponents.subordinate.Equal)25 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)17 WContainer (com.github.bordertech.wcomponents.WContainer)16 WTextField (com.github.bordertech.wcomponents.WTextField)15 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Test (org.junit.Test)15 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)13 Hide (com.github.bordertech.wcomponents.subordinate.Hide)13 Show (com.github.bordertech.wcomponents.subordinate.Show)12 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)9 Disable (com.github.bordertech.wcomponents.subordinate.Disable)8 Enable (com.github.bordertech.wcomponents.subordinate.Enable)8 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)6 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5