Search in sources :

Example 21 with WSubordinateControl

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

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

the class SubordinateBuilder method build.

/**
 * This builds the SubordinateControl. This method will throw a SystemException if the condition is invalid, or
 * there are no actions specified.
 *
 * @return a SubordinateControl built using this builder.
 */
public WSubordinateControl build() {
    if (!condition().validate()) {
        throw new SystemException("Invalid condition: " + condition);
    }
    if (getActionsWhenTrue().isEmpty() && getActionsWhenFalse().isEmpty()) {
        throw new SystemException("No actions to execute");
    }
    WSubordinateControl subordinate = new WSubordinateControl();
    Rule rule = new Rule();
    BooleanExpression expression = getCondition();
    rule.setCondition(expression.build());
    for (Action action : getActionsWhenTrue()) {
        rule.addActionOnTrue(action.build());
    }
    for (Action action : getActionsWhenFalse()) {
        rule.addActionOnFalse(action.build());
    }
    subordinate.addRule(rule);
    return subordinate;
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Rule(com.github.bordertech.wcomponents.subordinate.Rule)

Example 23 with WSubordinateControl

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

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

the class WSubordinateControlRenderer_Test method testGroupEnableInDisableInAction.

@Test
public void testGroupEnableInDisableInAction() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Setup Group
    SubordinateTarget actionTarget1 = new WTextField();
    SubordinateTarget actionTarget2 = new WTextField();
    SubordinateTarget actionTarget3 = new WTextField();
    WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
    group1.addToGroup(actionTarget1);
    group1.addToGroup(actionTarget2);
    group1.addToGroup(actionTarget3);
    // Setup Rule with ShowInGroup/HideInGroup actions
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    // OnTrue - EnableInGroup
    rule.addActionOnTrue(new EnableInGroup(actionTarget1, group1));
    // OnFalse - DisableInGroup
    rule.addActionOnFalse(new DisableInGroup(actionTarget1, group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    // Apply the controls (False conditions)
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check onTrue
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onTrue)", root);
    assertXpathEvaluatesTo("enableIn", "//ui:subordinate/ui:onTrue/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@groupId", root);
    assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onFalse)", root);
    assertXpathEvaluatesTo("disableIn", "//ui:subordinate/ui:onFalse/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@groupId", root);
    assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@id", root);
    // Check action target (Target 1 should be disabled)
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@disabled", root);
    assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@disabled", root);
    assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@disabled", root);
}
Also used : 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) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) DisableInGroup(com.github.bordertech.wcomponents.subordinate.DisableInGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) EnableInGroup(com.github.bordertech.wcomponents.subordinate.EnableInGroup) Test(org.junit.Test)

Example 25 with WSubordinateControl

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

WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)28 Rule (com.github.bordertech.wcomponents.subordinate.Rule)26 Equal (com.github.bordertech.wcomponents.subordinate.Equal)24 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)17 WContainer (com.github.bordertech.wcomponents.WContainer)16 Test (org.junit.Test)16 WTextField (com.github.bordertech.wcomponents.WTextField)15 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)13 Hide (com.github.bordertech.wcomponents.subordinate.Hide)13 Show (com.github.bordertech.wcomponents.subordinate.Show)12 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)9 Disable (com.github.bordertech.wcomponents.subordinate.Disable)8 Enable (com.github.bordertech.wcomponents.subordinate.Enable)8 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)5 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5