Search in sources :

Example 1 with Hide

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

the class WDropdownOptionsExample method applySettings.

/**
 * Apply the settings from the control table to the drop down.
 */
private void applySettings() {
    container.reset();
    infoPanel.reset();
    // create the list of options.
    List<String> options = new ArrayList<>(Arrays.asList(OPTIONS_ARRAY));
    if (cbNullOption.isSelected()) {
        options.add(0, "");
    }
    // create the dropdown.
    final WDropdown dropdown = new WDropdown(options);
    // set the dropdown type.
    dropdown.setType((DropdownType) rbsDDType.getSelected());
    // set the selected option if applicable.
    String selected = (String) rgDefaultOption.getSelected();
    if (selected != null && !NONE.equals(selected)) {
        dropdown.setSelected(selected);
    }
    // set the width.
    if (nfWidth.getValue() != null) {
        dropdown.setOptionWidth(nfWidth.getValue().intValue());
    }
    // set the tool tip.
    if (tfToolTip.getText() != null && tfToolTip.getText().length() > 0) {
        dropdown.setToolTip(tfToolTip.getText());
    }
    // set misc options.
    dropdown.setVisible(cbVisible.isSelected());
    dropdown.setDisabled(cbDisabled.isSelected());
    // add the action for action on change, ajax and subordinate.
    if (cbActionOnChange.isSelected() || cbAjax.isSelected() || cbSubmitOnChange.isSelected()) {
        final WStyledText info = new WStyledText();
        info.setWhitespaceMode(WhitespaceMode.PRESERVE);
        infoPanel.add(info);
        dropdown.setActionOnChange(new Action() {

            @Override
            public void execute(final ActionEvent event) {
                String selectedOption = (String) dropdown.getSelected();
                info.setText(selectedOption);
            }
        });
    }
    // this has to be below the set action on change so it is
    // not over written.
    dropdown.setSubmitOnChange(cbSubmitOnChange.isSelected());
    // add the ajax target.
    if (cbAjax.isSelected()) {
        WAjaxControl update = new WAjaxControl(dropdown);
        update.addTarget(infoPanel);
        container.add(update);
    }
    // add the subordinate stuff.
    if (rbsDDType.getValue() == WDropdown.DropdownType.COMBO) {
        // This is to work around a WComponent Subordinate logic flaw.
        cbSubordinate.setSelected(false);
    }
    if (cbSubordinate.isSelected()) {
        WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
        container.add(group);
        WSubordinateControl control = new WSubordinateControl();
        container.add(control);
        for (String option : OPTIONS_ARRAY) {
            buildSubordinatePanel(dropdown, option, group, control);
        }
        // add a rule for none selected.
        Rule rule = new Rule();
        control.addRule(rule);
        rule.setCondition(new Equal(dropdown, ""));
        rule.addActionOnTrue(new Hide(group));
    }
    WFieldLayout flay = new WFieldLayout();
    flay.setLabelWidth(25);
    container.add(flay);
    flay.addField("Configured dropdown", dropdown);
    flay.addField((WLabel) null, new WButton("Submit"));
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ArrayList(java.util.ArrayList) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WStyledText(com.github.bordertech.wcomponents.WStyledText) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WButton(com.github.bordertech.wcomponents.WButton) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WDropdown(com.github.bordertech.wcomponents.WDropdown) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 2 with Hide

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

the class WSubordinateControlRenderer_Test method testMultipleControlsAndGroups.

@Test
public void testMultipleControlsAndGroups() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Setup Groups
    SubordinateTarget actionTarget1 = new WTextField();
    SubordinateTarget actionTarget2 = new WTextField();
    SubordinateTarget actionTarget3 = new WTextField();
    SubordinateTarget actionTarget4 = new WTextField();
    // Multiple Groups
    WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
    group1.addToGroup(actionTarget1);
    group1.addToGroup(actionTarget2);
    WComponentGroup<SubordinateTarget> group2 = new WComponentGroup<>();
    group2.addToGroup(actionTarget3);
    group2.addToGroup(actionTarget4);
    // Multiple Rules
    Rule rule1 = new Rule();
    rule1.setCondition(new Equal(condTrigger, Boolean.TRUE));
    rule1.addActionOnTrue(new Show(group1));
    rule1.addActionOnFalse(new Hide(group1));
    Rule rule2 = new Rule();
    rule2.setCondition(new Equal(condTrigger, Boolean.FALSE));
    rule2.addActionOnTrue(new Show(group2));
    rule2.addActionOnFalse(new Hide(group2));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule1);
    control.addRule(rule2);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(actionTarget4);
    root.add(control);
    root.add(group1);
    root.add(group2);
    setActiveContext(createUIContext());
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check for basic elements
    assertXpathEvaluatesTo("2", "count(//ui:subordinate)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:condition)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
    assertXpathEvaluatesTo("2", "count(//ui:componentGroup)", root);
    assertXpathEvaluatesTo("2", "count(//ui:componentGroup[position()=1]/ui:component)", root);
    assertXpathEvaluatesTo("2", "count(//ui:componentGroup[position()=2]/ui:component)", root);
    // Check ids
    assertXpathEvaluatesTo(control.getId() + "-c0", "//ui:subordinate[position()=1]/@id", root);
    assertXpathEvaluatesTo(control.getId() + "-c1", "//ui:subordinate[position()=2]/@id", 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) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 3 with Hide

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

the class WSubordinateControlRenderer_Test method testAndCondition.

@Test
public void testAndCondition() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger1 = new WCheckBox();
    SubordinateTrigger condTrigger2 = new WCheckBox();
    SubordinateTrigger condTrigger3 = new WCheckBox();
    // Create AND condition
    Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
    Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
    Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
    Condition and = new And(cond1, cond2, cond3);
    SubordinateTarget actionTarget = new WTextField();
    // Setup Rule with AND Condition
    Rule rule = new Rule();
    rule.setCondition(and);
    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 AND
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
    assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:and/ui:condition)", root);
    assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:and/ui:condition[position()=1]/@controller", root);
    assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:and/ui:condition[position()=2]/@controller", root);
    assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:and/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) 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) 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 4 with Hide

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

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

the class WSubordinateControlRenderer_Test method testShowHideActions.

@Test
public void testShowHideActions() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Setup Group
    SubordinateTarget actionTarget = new WTextField();
    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 Show/Hide actions
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    // Single Component Target
    rule.addActionOnTrue(new Show(actionTarget));
    rule.addActionOnFalse(new Hide(actionTarget));
    // Group Target
    rule.addActionOnTrue(new Show(group1));
    rule.addActionOnFalse(new Hide(group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check onTrue
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    // Check onTrue - Component
    assertXpathEvaluatesTo("show", "//ui:subordinate/ui:onTrue[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@groupId", root);
    // Check onTrue - Group
    assertXpathEvaluatesTo("show", "//ui:subordinate/ui:onTrue[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
    // Check onFalse - Component
    assertXpathEvaluatesTo("hide", "//ui:subordinate/ui:onFalse[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@groupId", root);
    // Check onFalse - Group
    assertXpathEvaluatesTo("hide", "//ui:subordinate/ui:onFalse[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@id", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@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) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

Equal (com.github.bordertech.wcomponents.subordinate.Equal)13 Hide (com.github.bordertech.wcomponents.subordinate.Hide)13 Rule (com.github.bordertech.wcomponents.subordinate.Rule)13 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)13 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)12 Show (com.github.bordertech.wcomponents.subordinate.Show)12 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)4 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)3 And (com.github.bordertech.wcomponents.subordinate.And)3 Or (com.github.bordertech.wcomponents.subordinate.Or)3 WDropdown (com.github.bordertech.wcomponents.WDropdown)2