Search in sources :

Example 11 with Hide

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

the class WSubordinateControlRenderer_Test method testConditionWithRadioButtonGroupTarget.

@Test
public void testConditionWithRadioButtonGroupTarget() throws IOException, SAXException, XpathException {
    RadioButtonGroup rbg = new RadioButtonGroup();
    WRadioButton button1 = rbg.addRadioButton("B1");
    WRadioButton button2 = rbg.addRadioButton("B2");
    SubordinateTarget actionTarget = new WTextField();
    // Setup a rule with a condition using a Radio Button Group
    Rule rule = new Rule();
    rule.setCondition(new Equal(rbg, button2));
    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(rbg);
    root.add(button1);
    root.add(button2);
    root.add(actionTarget);
    root.add(control);
    setActiveContext(createUIContext());
    rbg.setSelectedValue("B1");
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check Condition Value is the Radio Button Value
    assertXpathEvaluatesTo(button2.getValue(), "//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) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) 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) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) 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 12 with Hide

use of com.github.bordertech.wcomponents.subordinate.Hide 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);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Or(com.github.bordertech.wcomponents.subordinate.Or) 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) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 13 with Hide

use of com.github.bordertech.wcomponents.subordinate.Hide 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)

Aggregations

Equal (com.github.bordertech.wcomponents.subordinate.Equal)13 Hide (com.github.bordertech.wcomponents.subordinate.Hide)13 Rule (com.github.bordertech.wcomponents.subordinate.Rule)13 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)13 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)12 Show (com.github.bordertech.wcomponents.subordinate.Show)12 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)11 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)11 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)11 WContainer (com.github.bordertech.wcomponents.WContainer)10 WTextField (com.github.bordertech.wcomponents.WTextField)10 Test (org.junit.Test)10 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)8 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)7 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)4 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)3 And (com.github.bordertech.wcomponents.subordinate.And)3 Or (com.github.bordertech.wcomponents.subordinate.Or)3 WDropdown (com.github.bordertech.wcomponents.WDropdown)2