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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations