Search in sources :

Example 1 with Or

use of com.github.bordertech.wcomponents.subordinate.Or 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 2 with Or

use of com.github.bordertech.wcomponents.subordinate.Or 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 3 with Or

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

the class WPanelTypeExample method buildSubordinates.

/**
 * The subordinate controls used to show/hide parts of the configuration options based on the selected WPanel Type.
 */
private void buildSubordinates() {
    WSubordinateControl control = new WSubordinateControl();
    Rule rule = new Rule();
    rule.setCondition(new Equal(panelType, WPanel.Type.HEADER));
    rule.addActionOnTrue(new Show(showUtilBarField));
    rule.addActionOnTrue(new Show(showMenuField));
    rule.addActionOnTrue(new Hide(contentField));
    rule.addActionOnFalse(new Hide(showUtilBarField));
    rule.addActionOnFalse(new Hide(showMenuField));
    rule.addActionOnFalse(new Show(contentField));
    control.addRule(rule);
    rule = new Rule();
    rule.setCondition(new Or(new Equal(panelType, WPanel.Type.CHROME), new Equal(panelType, WPanel.Type.ACTION), new Equal(panelType, WPanel.Type.HEADER)));
    rule.addActionOnTrue(new Show(headingField));
    rule.addActionOnFalse(new Hide(headingField));
    control.addRule(rule);
    add(control);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Or(com.github.bordertech.wcomponents.subordinate.Or) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 4 with Or

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

the class GroupExpression_Test method testBuildOr.

@Test
public void testBuildOr() {
    GroupExpression expr = new GroupExpression(GroupExpression.Type.OR);
    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);
    Or condition = (Or) expr.build();
    Assert.assertEquals("Incorrect 1st operand for OR", operand1.build().toString(), condition.getConditions().get(0).toString());
    Assert.assertEquals("Incorrect 2nd operand for OR", operand2.build().toString(), condition.getConditions().get(1).toString());
    Assert.assertEquals("Incorrect 3rd operand for OR", operand3.build().toString(), condition.getConditions().get(2).toString());
}
Also used : Or(com.github.bordertech.wcomponents.subordinate.Or) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 5 with Or

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

Or (com.github.bordertech.wcomponents.subordinate.Or)5 WTextField (com.github.bordertech.wcomponents.WTextField)3 Condition (com.github.bordertech.wcomponents.subordinate.Condition)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 Hide (com.github.bordertech.wcomponents.subordinate.Hide)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 Test (org.junit.Test)3 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)2 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 WContainer (com.github.bordertech.wcomponents.WContainer)2 And (com.github.bordertech.wcomponents.subordinate.And)2 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)2 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)2 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)2 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)1 AbstractCompare (com.github.bordertech.wcomponents.subordinate.AbstractCompare)1 Not (com.github.bordertech.wcomponents.subordinate.Not)1