Search in sources :

Example 31 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class SubordinateBuilder_Test method testDisableIn.

@Test
public void testDisableIn() {
    SubordinateBuilder builder = new SubordinateBuilder();
    WCheckBox input1 = new WCheckBox();
    WCheckBox input2 = new WCheckBox();
    WCheckBox input3 = new WCheckBox();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(input1);
    group.addToGroup(input2);
    group.addToGroup(input3);
    // True Condition
    builder.condition().equals(new WCheckBox(), "false");
    // DisableIn Action
    builder.whenTrue().disableIn(input2, group);
    setActiveContext(createUIContext());
    // Set initial states (opposite to end state)
    input1.setDisabled(true);
    input2.setDisabled(false);
    input3.setDisabled(true);
    Assert.assertTrue("disableIn - Input1 Component should be disabled", input1.isDisabled());
    Assert.assertFalse("disableIn - Input2 Component should be enabled", input2.isDisabled());
    Assert.assertTrue("disableIn - Input3 Component should be disabled", input3.isDisabled());
    builder.build().applyTheControls();
    Assert.assertFalse("disableIn - Input1 Component should be enabled", input1.isDisabled());
    Assert.assertTrue("disableIn - Input2 Component should be disabled", input2.isDisabled());
    Assert.assertFalse("disableIn - Input3 Component should be enabled", input3.isDisabled());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Example 32 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class SubordinateBuilder_Test method testMandatory.

@Test
public void testMandatory() {
    SubordinateBuilder builder = new SubordinateBuilder();
    WCheckBox input = new WCheckBox();
    builder.condition().equals(input, "false");
    builder.whenTrue().setMandatory(input);
    setActiveContext(createUIContext());
    Assert.assertFalse("Component should be initially optional", input.isMandatory());
    builder.build().applyTheControls();
    Assert.assertTrue("Component should be required", input.isMandatory());
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Example 33 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class WToggleButtonRenderer method doRender.

/**
 * Paints the given WCheckBox.
 *
 * @param component the WCheckBox to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WToggleButton toggle = (WToggleButton) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = toggle.isReadOnly();
    xml.appendTagOpen("ui:togglebutton");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", toggle.isHidden(), "true");
    xml.appendOptionalAttribute("selected", toggle.isSelected(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        WComponentGroup<WCheckBox> group = toggle.getGroup();
        String groupName = group == null ? null : group.getId();
        xml.appendOptionalAttribute("groupName", groupName);
        xml.appendOptionalAttribute("disabled", toggle.isDisabled(), "true");
        xml.appendOptionalAttribute("submitOnChange", toggle.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", toggle.getToolTip());
        xml.appendOptionalAttribute("accessibleText", toggle.getAccessibleText());
    }
    xml.appendClose();
    String text = toggle.getText();
    if (text != null) {
        xml.appendEscaped(text);
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(toggle, renderContext);
    }
    xml.appendEndTag("ui:togglebutton");
}
Also used : WToggleButton(com.github.bordertech.wcomponents.WToggleButton) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WCheckBox(com.github.bordertech.wcomponents.WCheckBox)

Example 34 with WCheckBox

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

use of com.github.bordertech.wcomponents.WCheckBox 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)

Aggregations

WCheckBox (com.github.bordertech.wcomponents.WCheckBox)42 Test (org.junit.Test)35 WTextField (com.github.bordertech.wcomponents.WTextField)21 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)18 WContainer (com.github.bordertech.wcomponents.WContainer)17 Equal (com.github.bordertech.wcomponents.subordinate.Equal)13 Rule (com.github.bordertech.wcomponents.subordinate.Rule)13 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)13 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)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 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)7 Show (com.github.bordertech.wcomponents.subordinate.Show)7 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLabel (com.github.bordertech.wcomponents.WLabel)3 Condition (com.github.bordertech.wcomponents.subordinate.Condition)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3