Search in sources :

Example 21 with SubordinateTrigger

use of com.github.bordertech.wcomponents.SubordinateTrigger in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testBasicCondition.

@Test
public void testBasicCondition() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    SubordinateTarget actionTarget = new WTextField();
    // Basic Condition
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    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);
    setActiveContext(createUIContext());
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check for basic elements
    assertXpathEvaluatesTo("1", "count(//ui:subordinate)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:condition)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onTrue)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onFalse)", root);
    // Check id
    assertXpathEvaluatesTo(control.getId() + "-c0", "//ui:subordinate/@id", root);
    // Check condition
    assertXpathEvaluatesTo(condTrigger.getId(), "//ui:subordinate/ui:condition/@controller", root);
    assertXpathEvaluatesTo("true", "//ui:subordinate/ui:condition/@value", root);
    // Check onTrue
    assertXpathEvaluatesTo("show", "//ui:subordinate/ui:onTrue/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onTrue/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("hide", "//ui:subordinate/ui:onFalse/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onFalse/ui:target/@id", 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) 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 22 with SubordinateTrigger

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

Example 23 with SubordinateTrigger

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

Aggregations

SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)23 Test (org.junit.Test)23 WTextField (com.github.bordertech.wcomponents.WTextField)14 Equal (com.github.bordertech.wcomponents.subordinate.Equal)12 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)12 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)12 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)12 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)11 WContainer (com.github.bordertech.wcomponents.WContainer)11 Rule (com.github.bordertech.wcomponents.subordinate.Rule)11 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)11 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)8 Show (com.github.bordertech.wcomponents.subordinate.Show)8 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)6 Condition (com.github.bordertech.wcomponents.subordinate.Condition)4 And (com.github.bordertech.wcomponents.subordinate.And)3 WNumberField (com.github.bordertech.wcomponents.WNumberField)2 GreaterThan (com.github.bordertech.wcomponents.subordinate.GreaterThan)2 LessThan (com.github.bordertech.wcomponents.subordinate.LessThan)2