Search in sources :

Example 1 with Mandatory

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

the class WSubordinateControlRenderer_Test method testMandatoryOptionalActions.

@Test
public void testMandatoryOptionalActions() throws IOException, SAXException, XpathException {
    WCheckBox 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 Mandatory/Optional actions
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    // Single Component Target
    rule.addActionOnTrue(new Mandatory(actionTarget));
    rule.addActionOnFalse(new Optional(actionTarget));
    // Group Target
    rule.addActionOnTrue(new Mandatory(group1));
    rule.addActionOnFalse(new Optional(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());
    condTrigger.setSelected(true);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check onTrue
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    // Check onTrue - Component
    assertXpathEvaluatesTo("mandatory", "//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("mandatory", "//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("optional", "//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("optional", "//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() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@required", root);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) 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) 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) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory) Test(org.junit.Test)

Example 2 with Mandatory

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

the class InputBeanBindingExample method addSubordinate.

/**
 * Setup the subordinate control.
 */
private void addSubordinate() {
    // Set up subordinate (to make mandatory/optional)
    WComponentGroup<SubordinateTarget> inputs = new WComponentGroup<>();
    add(inputs);
    inputs.addToGroup(checkBoxSelect);
    inputs.addToGroup(multiDropdown);
    inputs.addToGroup(multiSelect);
    inputs.addToGroup(multiSelectPair);
    inputs.addToGroup(dropdown);
    inputs.addToGroup(radioButtonSelect);
    inputs.addToGroup(singleSelect);
    inputs.addToGroup(checkBox);
    inputs.addToGroup(dateField);
    inputs.addToGroup(emailField);
    inputs.addToGroup(fileWidget);
    inputs.addToGroup(multiFileWidget);
    inputs.addToGroup(multiTextField);
    inputs.addToGroup(numberField);
    inputs.addToGroup(partialDateField);
    inputs.addToGroup(phoneNumberField);
    inputs.addToGroup(radioButton);
    inputs.addToGroup(shuffler);
    inputs.addToGroup(textField);
    inputs.addToGroup(textArea);
    inputs.addToGroup(radioButton1);
    inputs.addToGroup(radioButton2);
    inputs.addToGroup(radioButton3);
    WSubordinateControl control = new WSubordinateControl();
    add(control);
    // Mandatory
    Rule rule = new Rule();
    rule.setCondition(new Equal(mandatory, "true"));
    rule.addActionOnTrue(new Mandatory(inputs));
    rule.addActionOnFalse(new Optional(inputs));
    control.addRule(rule);
    // Disabled
    rule = new Rule();
    rule.setCondition(new Equal(disabled, "true"));
    rule.addActionOnTrue(new Disable(inputs));
    rule.addActionOnFalse(new Enable(inputs));
    control.addRule(rule);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Optional(com.github.bordertech.wcomponents.subordinate.Optional) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Enable(com.github.bordertech.wcomponents.subordinate.Enable) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) 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 3 with Mandatory

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

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

the class SubordinateControlMandatoryExample method build.

/**
 * Creates the component to be added to the validation container. This is doen in a static method because the
 * component is passed into the superclass constructor.
 *
 * @return the component to be added to the validation container.
 */
private static WComponent build() {
    WContainer root = new WContainer();
    WSubordinateControl control = new WSubordinateControl();
    root.add(control);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    layout.setMargin(new com.github.bordertech.wcomponents.Margin(Size.ZERO, Size.ZERO, Size.LARGE, Size.ZERO));
    WCheckBox checkBox = new WCheckBox();
    layout.addField("Set Mandatory", checkBox);
    WTextField text = new WTextField();
    layout.addField("Might need this field", text);
    WTextField mandatoryField = new WTextField();
    layout.addField("Another field always mandatory", mandatoryField);
    mandatoryField.setMandatory(true);
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    layout.addField("Select a state", rbSelect);
    root.add(layout);
    Rule rule = new Rule();
    rule.setCondition(new Equal(checkBox, Boolean.TRUE.toString()));
    rule.addActionOnTrue(new Mandatory(text));
    rule.addActionOnFalse(new Optional(text));
    rule.addActionOnTrue(new Mandatory(rbSelect));
    rule.addActionOnFalse(new Optional(rbSelect));
    control.addRule(rule);
    return root;
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Aggregations

Equal (com.github.bordertech.wcomponents.subordinate.Equal)4 Mandatory (com.github.bordertech.wcomponents.subordinate.Mandatory)4 Optional (com.github.bordertech.wcomponents.subordinate.Optional)4 Rule (com.github.bordertech.wcomponents.subordinate.Rule)4 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)4 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)3 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)2 WContainer (com.github.bordertech.wcomponents.WContainer)2 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 Disable (com.github.bordertech.wcomponents.subordinate.Disable)2 Enable (com.github.bordertech.wcomponents.subordinate.Enable)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 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)1 WText (com.github.bordertech.wcomponents.WText)1 Condition (com.github.bordertech.wcomponents.subordinate.Condition)1