Search in sources :

Example 6 with Show

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

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

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

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

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

the class WSubordinateControlRenderer_Test method testConditionWithRadioButtonGroupTarget.

@Test
public void testConditionWithRadioButtonGroupTarget() throws IOException, SAXException, XpathException {
    RadioButtonGroup rbg = new RadioButtonGroup();
    WRadioButton button1 = rbg.addRadioButton("B1");
    WRadioButton button2 = rbg.addRadioButton("B2");
    SubordinateTarget actionTarget = new WTextField();
    // Setup a rule with a condition using a Radio Button Group
    Rule rule = new Rule();
    rule.setCondition(new Equal(rbg, button2));
    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(rbg);
    root.add(button1);
    root.add(button2);
    root.add(actionTarget);
    root.add(control);
    setActiveContext(createUIContext());
    rbg.setSelectedValue("B1");
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check Condition Value is the Radio Button Value
    assertXpathEvaluatesTo(button2.getValue(), "//ui:subordinate/ui:condition/@value", 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) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) 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) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) 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

Equal (com.github.bordertech.wcomponents.subordinate.Equal)12 Hide (com.github.bordertech.wcomponents.subordinate.Hide)12 Rule (com.github.bordertech.wcomponents.subordinate.Rule)12 Show (com.github.bordertech.wcomponents.subordinate.Show)12 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)12 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)11 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)11 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)11 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)11 WContainer (com.github.bordertech.wcomponents.WContainer)10 WTextField (com.github.bordertech.wcomponents.WTextField)10 Test (org.junit.Test)10 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)8 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)7 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)3 And (com.github.bordertech.wcomponents.subordinate.And)3 Or (com.github.bordertech.wcomponents.subordinate.Or)3 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1