Search in sources :

Example 6 with Condition

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

the class SubordinateControlOptionsExample method buildControl.

/**
 * Build the subordinate control.
 */
private void buildControl() {
    buildControlPanel.reset();
    buildTargetPanel.reset();
    // Setup Trigger
    setupTrigger();
    // Create target
    SubordinateTarget target = setupTarget();
    // Create Actions
    com.github.bordertech.wcomponents.subordinate.Action trueAction;
    com.github.bordertech.wcomponents.subordinate.Action falseAction;
    switch((ControlActionType) drpActionType.getSelected()) {
        case ENABLE_DISABLE:
            trueAction = new Enable(target);
            falseAction = new Disable(target);
            break;
        case SHOW_HIDE:
            trueAction = new Show(target);
            falseAction = new Hide(target);
            break;
        case MAN_OPT:
            trueAction = new Mandatory(target);
            falseAction = new Optional(target);
            break;
        case SHOWIN_HIDEIN:
            trueAction = new ShowInGroup(target, targetGroup);
            falseAction = new HideInGroup(target, targetGroup);
            break;
        case ENABLEIN_DISABLEIN:
            trueAction = new EnableInGroup(target, targetGroup);
            falseAction = new DisableInGroup(target, targetGroup);
            break;
        default:
            throw new SystemException("ControlAction type not valid");
    }
    // Create Condition
    Condition condition = createCondition();
    if (cbNot.isSelected()) {
        condition = new Not(condition);
    }
    // Create Rule
    Rule rule = new Rule(condition, trueAction, falseAction);
    // Create Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    buildControlPanel.add(control);
    if (targetCollapsible.getDecoratedLabel() != null) {
        targetCollapsible.getDecoratedLabel().setTail(new WText(control.toString()));
    }
    control = new WSubordinateControl();
    rule = new Rule(new Equal(cbClientDisableTrigger, true), new Disable((SubordinateTarget) trigger), new Enable((SubordinateTarget) trigger));
    control.addRule(rule);
    buildControlPanel.add(control);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Condition(com.github.bordertech.wcomponents.subordinate.Condition) Optional(com.github.bordertech.wcomponents.subordinate.Optional) HideInGroup(com.github.bordertech.wcomponents.subordinate.HideInGroup) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) EnableInGroup(com.github.bordertech.wcomponents.subordinate.EnableInGroup) ShowInGroup(com.github.bordertech.wcomponents.subordinate.ShowInGroup) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Not(com.github.bordertech.wcomponents.subordinate.Not) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) 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) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Show(com.github.bordertech.wcomponents.subordinate.Show) DisableInGroup(com.github.bordertech.wcomponents.subordinate.DisableInGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) Disable(com.github.bordertech.wcomponents.subordinate.Disable) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 7 with Condition

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

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