use of com.github.bordertech.wcomponents.WComponentGroup 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);
}
use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testBasicConditionWithGroup.
@Test
public void testBasicConditionWithGroup() 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);
// Basic Condition
Rule rule = new Rule();
rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
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(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 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);
assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", 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(group1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@groupId", root);
assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue/ui:target/@id", root);
// Check onFalse
assertXpathEvaluatesTo("hide", "//ui:subordinate/ui:onFalse/@action", root);
assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@groupId", root);
assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse/ui:target/@id", root);
// Check group
assertXpathEvaluatesTo(group1.getId(), "//ui:componentGroup/@id", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
// Check action target
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);
}
use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class WComponentGroupRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
// Setup Group
WComponent actionTarget1 = new WTextField();
WComponent actionTarget2 = new WTextField();
WComponent actionTarget3 = new WTextField();
WComponentGroup<WComponent> group = new WComponentGroup<>();
group.addToGroup(actionTarget1);
group.addToGroup(actionTarget2);
group.addToGroup(actionTarget3);
WContainer root = new WContainer();
root.add(actionTarget1);
root.add(actionTarget2);
root.add(actionTarget3);
root.add(group);
setActiveContext(createUIContext());
// Validate Schema
assertSchemaMatch(root);
// Check group
assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", root);
assertXpathEvaluatesTo(group.getId(), "//ui:componentGroup/@id", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
}
use of com.github.bordertech.wcomponents.WComponentGroup 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);
}
use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class AbstractAction_Test method testRecursiveWithWComponentGroup.
@Test
public void testRecursiveWithWComponentGroup() {
SubordinateTarget target1 = new MyTarget();
SubordinateTarget target2 = new MyTarget();
SubordinateTarget target3 = new MyTarget();
WComponentGroup<SubordinateTarget> compGroup = new WComponentGroup<>();
compGroup.addToGroup(target1);
compGroup.addToGroup(target2);
compGroup.addToGroup(target3);
String value = "TEST_COMP";
MyAction action = new MyAction(compGroup, value);
// Execute Action
setActiveContext(createUIContext());
action.execute();
Assert.assertEquals("Incorrect value set on target1", value, ((MyTarget) target1).getValue());
Assert.assertEquals("Incorrect value set on target2", value, ((MyTarget) target2).getValue());
Assert.assertEquals("Incorrect value set on target3", value, ((MyTarget) target3).getValue());
}
Aggregations