Search in sources :

Example 16 with SubordinateTarget

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

the class WSubordinateControl_Test method testToString.

@Test
public void testToString() {
    WCheckBox box = new WCheckBox();
    SubordinateTarget target = new WTextField();
    Rule rule = new Rule();
    rule.setCondition(new Equal(box, Boolean.TRUE));
    rule.addActionOnTrue(new Hide(target));
    rule.addActionOnFalse(new Show(target));
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    Assert.assertEquals("Incorrect toString for control", "RULE: if (WCheckBox=\"true\")\nthen\n   [hide WTextField]\nelse\n   [show WTextField]\n", control.toString());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 17 with SubordinateTarget

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

the class WSubordinateControl_Test method testApplyControls.

@Test
public void testApplyControls() {
    WCheckBox box = new WCheckBox();
    SubordinateTarget target = new WTextField();
    // Create Rule
    Rule rule = new Rule();
    rule.setCondition(new Equal(box, Boolean.TRUE));
    rule.addActionOnTrue(new Hide(target));
    rule.addActionOnFalse(new Show(target));
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(control);
    root.add(box);
    root.add(target);
    setActiveContext(createUIContext());
    // Setup true condition - Selected
    box.setSelected(true);
    // Apply the controls
    setFlag(box, ComponentModel.HIDE_FLAG, false);
    control.applyTheControls();
    Assert.assertTrue("After applyControls target should be hidden", target.isHidden());
    setFlag(box, ComponentModel.HIDE_FLAG, false);
    // Setup true condition - CheckBox selected in Request
    MockRequest request = new MockRequest();
    setupCheckBoxRequest(box, request, true);
    // ApplyControls with Request
    control.applyTheControls(request);
    Assert.assertTrue("Request - After applyControls target should be hidden", target.isHidden());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 18 with SubordinateTarget

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

the class Action_Test method testConstructor2.

@Test
public void testConstructor2() {
    SubordinateTarget target = new MyTarget();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    Action action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.DISABLE, target, group);
    Assert.assertEquals("Incorrect type returned", com.github.bordertech.wcomponents.subordinate.Action.ActionType.DISABLE, action.getType());
    Assert.assertEquals("Incorrect target returned", target, action.getTarget());
    Assert.assertEquals("Incorrect group returned", group, action.getGroup());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Test(org.junit.Test)

Example 19 with SubordinateTarget

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

the class SubordinateBuilder_Test method testHideIn.

@Test
public void testHideIn() {
    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");
    // HideIn Action
    builder.whenTrue().hideIn(input2, group);
    setActiveContext(createUIContext());
    // Set initial states (opposite to end state)
    setFlag(input1, ComponentModel.HIDE_FLAG, true);
    setFlag(input2, ComponentModel.HIDE_FLAG, false);
    setFlag(input3, ComponentModel.HIDE_FLAG, true);
    Assert.assertTrue("hideIn - Input1 Component should be hidden", input1.isHidden());
    Assert.assertFalse("hideIn - Input2 Component should not be hidden", input2.isHidden());
    Assert.assertTrue("hideIn - Input3 Component should be hidden", input3.isHidden());
    builder.build().applyTheControls();
    Assert.assertFalse("hideIn - Input1 Component should not be hidden", input1.isHidden());
    Assert.assertTrue("hideIn - Input2 Component should be hidden", input2.isHidden());
    Assert.assertFalse("hideIn - Input3 Component should not be hidden", input3.isHidden());
}
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 20 with SubordinateTarget

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

the class WSubordinateControlRenderer method paintStandardAction.

/**
 * Paint a standard action - where a single item or single group is targeted.
 *
 * @param action the action to paint
 * @param elementName the enclosing element name ("ui:onFalse" or "ui:onTrue").
 * @param xml the output response
 */
private void paintStandardAction(final Action action, final String elementName, final XmlStringBuilder xml) {
    xml.appendTagOpen(elementName);
    xml.appendAttribute("action", getActionTypeName(action.getActionType()));
    xml.appendClose();
    xml.appendTagOpen("ui:target");
    SubordinateTarget target = action.getTarget();
    if (target instanceof WComponentGroup<?>) {
        xml.appendAttribute("groupId", target.getId());
    } else {
        xml.appendAttribute("id", target.getId());
    }
    xml.appendEnd();
    xml.appendEndTag(elementName);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup)

Aggregations

SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)57 Test (org.junit.Test)53 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)30 WTextField (com.github.bordertech.wcomponents.WTextField)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)18 Equal (com.github.bordertech.wcomponents.subordinate.Equal)17 Rule (com.github.bordertech.wcomponents.subordinate.Rule)17 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)17 WContainer (com.github.bordertech.wcomponents.WContainer)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 Hide (com.github.bordertech.wcomponents.subordinate.Hide)12 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 Show (com.github.bordertech.wcomponents.subordinate.Show)11 WLabel (com.github.bordertech.wcomponents.WLabel)5 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)3 And (com.github.bordertech.wcomponents.subordinate.And)3 Disable (com.github.bordertech.wcomponents.subordinate.Disable)3