Search in sources :

Example 1 with And

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

the class GroupExpression_Test method testBuildAnd.

@Test
public void testBuildAnd() {
    GroupExpression expr = new GroupExpression(GroupExpression.Type.AND);
    BooleanExpression operand1 = new CompareExpression(CompareType.EQUAL, new WTextField(), "1");
    BooleanExpression operand2 = new CompareExpression(CompareType.EQUAL, new WTextField(), "2");
    BooleanExpression operand3 = new CompareExpression(CompareType.EQUAL, new WTextField(), "3");
    expr.add(operand1);
    expr.add(operand2);
    expr.add(operand3);
    And condition = (And) expr.build();
    Assert.assertEquals("Incorrect number of conditions for AND", 3, condition.getConditions().size());
    Assert.assertEquals("Incorrect 1st operand for AND", operand1.build().toString(), condition.getConditions().get(0).toString());
    Assert.assertEquals("Incorrect 2nd operand for AND", operand2.build().toString(), condition.getConditions().get(1).toString());
    Assert.assertEquals("Incorrect 3rd operand for AND", operand3.build().toString(), condition.getConditions().get(2).toString());
}
Also used : And(com.github.bordertech.wcomponents.subordinate.And) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 2 with And

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

the class WSubordinateControlRenderer method paintCondition.

/**
 * Paints a condition.
 *
 * @param condition the condition to paint.
 * @param xml the writer to send the output to
 */
private void paintCondition(final Condition condition, final XmlStringBuilder xml) {
    if (condition instanceof And) {
        xml.appendTag("ui:and");
        for (Condition operand : ((And) condition).getConditions()) {
            paintCondition(operand, xml);
        }
        xml.appendEndTag("ui:and");
    } else if (condition instanceof Or) {
        xml.appendTag("ui:or");
        for (Condition operand : ((Or) condition).getConditions()) {
            paintCondition(operand, xml);
        }
        xml.appendEndTag("ui:or");
    } else if (condition instanceof Not) {
        xml.appendTag("ui:not");
        paintCondition(((Not) condition).getCondition(), xml);
        xml.appendEndTag("ui:not");
    } else if (condition instanceof AbstractCompare) {
        AbstractCompare compare = (AbstractCompare) condition;
        xml.appendTagOpen("ui:condition");
        xml.appendAttribute("controller", compare.getTrigger().getId());
        xml.appendAttribute("value", compare.getComparePaintValue());
        xml.appendOptionalAttribute("operator", getCompareTypeName(compare.getCompareType()));
        xml.appendEnd();
    } else {
        throw new SystemException("Unknown condition: " + condition);
    }
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) AbstractCompare(com.github.bordertech.wcomponents.subordinate.AbstractCompare) Not(com.github.bordertech.wcomponents.subordinate.Not) Or(com.github.bordertech.wcomponents.subordinate.Or) SystemException(com.github.bordertech.wcomponents.util.SystemException) And(com.github.bordertech.wcomponents.subordinate.And)

Example 3 with And

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

the class WSubordinateControlRenderer_Test method testAndCondition.

@Test
public void testAndCondition() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger1 = new WCheckBox();
    SubordinateTrigger condTrigger2 = new WCheckBox();
    SubordinateTrigger condTrigger3 = new WCheckBox();
    // Create AND condition
    Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
    Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
    Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
    Condition and = new And(cond1, cond2, cond3);
    SubordinateTarget actionTarget = new WTextField();
    // Setup Rule with AND Condition
    Rule rule = new Rule();
    rule.setCondition(and);
    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 AND
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
    assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:and/ui:condition)", root);
    assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:and/ui:condition[position()=1]/@controller", root);
    assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:and/ui:condition[position()=2]/@controller", root);
    assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:and/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) 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) And(com.github.bordertech.wcomponents.subordinate.And) 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 4 with And

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

the class WSubordinateControlRenderer_Test method testNestedConditions.

@Test
public void testNestedConditions() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Create Nested Condition
    Condition cond1 = new Equal(condTrigger, Boolean.TRUE);
    Condition cond2 = new Equal(condTrigger, Boolean.TRUE);
    Condition cond3 = new Equal(condTrigger, Boolean.TRUE);
    Condition cond4 = new Equal(condTrigger, Boolean.TRUE);
    Condition orTest = new Or(cond1, cond2);
    Condition and1 = new And(cond3, orTest);
    Condition and2 = new And(cond4, and1);
    SubordinateTarget actionTarget = new WTextField();
    // Setup rule with Nested Condition
    Rule rule = new Rule();
    rule.setCondition(and2);
    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);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check Nested
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:condition)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:condition)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:or)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:and/ui:and/ui:or/ui:condition)", 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) WContainer(com.github.bordertech.wcomponents.WContainer) Or(com.github.bordertech.wcomponents.subordinate.Or) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) 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) And(com.github.bordertech.wcomponents.subordinate.And) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) 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 5 with And

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

the class WSubordinateControlRenderer_Test method testAllConditions.

@Test
public void testAllConditions() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WNumberField();
    SubordinateTrigger condTrigger2 = new WTextField();
    SubordinateTarget actionTarget = new WTextField();
    BigDecimal value = BigDecimal.valueOf(2);
    Condition cond1 = new Equal(condTrigger, value);
    Condition cond2 = new NotEqual(condTrigger, value);
    Condition cond3 = new LessThan(condTrigger, value);
    Condition cond4 = new LessThanOrEqual(condTrigger, value);
    Condition cond5 = new GreaterThan(condTrigger, value);
    Condition cond6 = new GreaterThanOrEqual(condTrigger, value);
    Condition cond7 = new Match(condTrigger2, "[abc]");
    // Basic Condition
    Rule rule = new Rule();
    rule.setCondition(new And(cond1, cond2, cond3, cond4, cond5, cond6, cond7));
    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(condTrigger2);
    root.add(actionTarget);
    root.add(control);
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(root);
    assertXpathNotExists("//ui:subordinate/ui:and/ui:condition[1]/@operator", root);
    assertXpathEvaluatesTo("ne", "//ui:subordinate/ui:and/ui:condition[2]/@operator", root);
    assertXpathEvaluatesTo("lt", "//ui:subordinate/ui:and/ui:condition[3]/@operator", root);
    assertXpathEvaluatesTo("le", "//ui:subordinate/ui:and/ui:condition[4]/@operator", root);
    assertXpathEvaluatesTo("gt", "//ui:subordinate/ui:and/ui:condition[5]/@operator", root);
    assertXpathEvaluatesTo("ge", "//ui:subordinate/ui:and/ui:condition[6]/@operator", root);
    assertXpathEvaluatesTo("rx", "//ui:subordinate/ui:and/ui:condition[7]/@operator", root);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) WContainer(com.github.bordertech.wcomponents.WContainer) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) WNumberField(com.github.bordertech.wcomponents.WNumberField) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) BigDecimal(java.math.BigDecimal) Match(com.github.bordertech.wcomponents.subordinate.Match) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) 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) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan) And(com.github.bordertech.wcomponents.subordinate.And) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) 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

And (com.github.bordertech.wcomponents.subordinate.And)5 WTextField (com.github.bordertech.wcomponents.WTextField)4 Condition (com.github.bordertech.wcomponents.subordinate.Condition)4 Test (org.junit.Test)4 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)3 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)3 WContainer (com.github.bordertech.wcomponents.WContainer)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)3 Hide (com.github.bordertech.wcomponents.subordinate.Hide)3 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)3 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)3 Rule (com.github.bordertech.wcomponents.subordinate.Rule)3 Show (com.github.bordertech.wcomponents.subordinate.Show)3 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)3 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 Or (com.github.bordertech.wcomponents.subordinate.Or)2 WNumberField (com.github.bordertech.wcomponents.WNumberField)1 AbstractCompare (com.github.bordertech.wcomponents.subordinate.AbstractCompare)1 GreaterThan (com.github.bordertech.wcomponents.subordinate.GreaterThan)1