Search in sources :

Example 1 with LessThanOrEqual

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

the class CompareExpression_Test method testBuild.

@Test
public void testBuild() {
    SubordinateTrigger trigger = new WTextField();
    String value = "test";
    // Build Equal
    CompareExpression expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    Equal equal = (Equal) expr.build();
    Assert.assertEquals("Equal condition returned invalid trigger", trigger, equal.getTrigger());
    Assert.assertEquals("Equal condition returned invalid value", value, equal.getValue());
    // Build NotEqual
    expr = new CompareExpression(CompareType.NOT_EQUAL, trigger, value);
    NotEqual notEqual = (NotEqual) expr.build();
    Assert.assertEquals("NotEqual condition returned invalid trigger", trigger, notEqual.getTrigger());
    Assert.assertEquals("NotEqual condition returned invalid value", value, notEqual.getValue());
    // Build LessThan
    expr = new CompareExpression(CompareType.LESS_THAN, trigger, value);
    LessThan lessThan = (LessThan) expr.build();
    Assert.assertEquals("LessThan condition returned invalid trigger", trigger, lessThan.getTrigger());
    Assert.assertEquals("LessThan condition returned invalid value", value, lessThan.getValue());
    // Build LessThanOrEqual
    expr = new CompareExpression(CompareType.LESS_THAN_OR_EQUAL, trigger, value);
    LessThanOrEqual lessThanOrEqual = (LessThanOrEqual) expr.build();
    Assert.assertEquals("LessThanOrEqual condition returned invalid trigger", trigger, lessThanOrEqual.getTrigger());
    Assert.assertEquals("LessThanOrEqual condition returned invalid value", value, lessThanOrEqual.getValue());
    // Build GreaterThan
    expr = new CompareExpression(CompareType.GREATER_THAN, trigger, value);
    GreaterThan greaterThan = (GreaterThan) expr.build();
    Assert.assertEquals("GreaterThan condition returned invalid trigger", trigger, greaterThan.getTrigger());
    Assert.assertEquals("GreaterThan condition returned invalid value", value, greaterThan.getValue());
    // Build GreaterThanOrEqual
    expr = new CompareExpression(CompareType.GREATER_THAN_OR_EQUAL, trigger, value);
    GreaterThanOrEqual greaterThanOrEqual = (GreaterThanOrEqual) expr.build();
    Assert.assertEquals("GreaterThanOrEqual condition returned invalid trigger", trigger, greaterThanOrEqual.getTrigger());
    Assert.assertEquals("GreaterThanOrEqual condition returned invalid value", value, greaterThanOrEqual.getValue());
    // Build Match
    expr = new CompareExpression(CompareType.MATCH, trigger, value);
    Match match = (Match) expr.build();
    Assert.assertEquals("Match condition returned invalid trigger", trigger, match.getTrigger());
    Assert.assertEquals("Match condition returned invalid value", value, match.getValue());
}
Also used : LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WTextField(com.github.bordertech.wcomponents.WTextField) Match(com.github.bordertech.wcomponents.subordinate.Match) Test(org.junit.Test)

Example 2 with LessThanOrEqual

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

Example 3 with LessThanOrEqual

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

the class SubordinateControlOptionsExample method createCondition.

/**
 * @return the condition for the subordinate control.
 */
private Condition createCondition() {
    // Compare value
    Object value;
    switch((TriggerType) drpTriggerType.getSelected()) {
        case DateField:
            value = dateCompareValue.getValue();
            break;
        case NumberField:
            value = numberCompareValue.getValue();
            break;
        default:
            value = comboCompareValue.getValue();
            break;
    }
    // Create condition
    Condition condition;
    switch((CompareType) drpCompareType.getSelected()) {
        case EQUAL:
            condition = new Equal(trigger, value);
            break;
        case NOT_EQUAL:
            condition = new NotEqual(trigger, value);
            break;
        case LESS_THAN:
            condition = new LessThan(trigger, value);
            break;
        case LESS_THAN_OR_EQUAL:
            condition = new LessThanOrEqual(trigger, value);
            break;
        case GREATER_THAN:
            condition = new GreaterThan(trigger, value);
            break;
        case GREATER_THAN_OR_EQUAL:
            condition = new GreaterThanOrEqual(trigger, value);
            break;
        case MATCH:
            condition = new Match(trigger, (String) value);
            break;
        default:
            throw new SystemException("Compare type not valid");
    }
    return condition;
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) CompareType(com.github.bordertech.wcomponents.subordinate.AbstractCompare.CompareType) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) Match(com.github.bordertech.wcomponents.subordinate.Match) LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) SystemException(com.github.bordertech.wcomponents.util.SystemException) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan)

Aggregations

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