use of com.github.bordertech.wcomponents.subordinate.Hide in project wcomponents by BorderTech.
the class WDropdownOptionsExample method applySettings.
/**
* Apply the settings from the control table to the drop down.
*/
private void applySettings() {
container.reset();
infoPanel.reset();
// create the list of options.
List<String> options = new ArrayList<>(Arrays.asList(OPTIONS_ARRAY));
if (cbNullOption.isSelected()) {
options.add(0, "");
}
// create the dropdown.
final WDropdown dropdown = new WDropdown(options);
// set the dropdown type.
dropdown.setType((DropdownType) rbsDDType.getSelected());
// set the selected option if applicable.
String selected = (String) rgDefaultOption.getSelected();
if (selected != null && !NONE.equals(selected)) {
dropdown.setSelected(selected);
}
// set the width.
if (nfWidth.getValue() != null) {
dropdown.setOptionWidth(nfWidth.getValue().intValue());
}
// set the tool tip.
if (tfToolTip.getText() != null && tfToolTip.getText().length() > 0) {
dropdown.setToolTip(tfToolTip.getText());
}
// set misc options.
dropdown.setVisible(cbVisible.isSelected());
dropdown.setDisabled(cbDisabled.isSelected());
// add the action for action on change, ajax and subordinate.
if (cbActionOnChange.isSelected() || cbAjax.isSelected() || cbSubmitOnChange.isSelected()) {
final WStyledText info = new WStyledText();
info.setWhitespaceMode(WhitespaceMode.PRESERVE);
infoPanel.add(info);
dropdown.setActionOnChange(new Action() {
@Override
public void execute(final ActionEvent event) {
String selectedOption = (String) dropdown.getSelected();
info.setText(selectedOption);
}
});
}
// this has to be below the set action on change so it is
// not over written.
dropdown.setSubmitOnChange(cbSubmitOnChange.isSelected());
// add the ajax target.
if (cbAjax.isSelected()) {
WAjaxControl update = new WAjaxControl(dropdown);
update.addTarget(infoPanel);
container.add(update);
}
// add the subordinate stuff.
if (rbsDDType.getValue() == WDropdown.DropdownType.COMBO) {
// This is to work around a WComponent Subordinate logic flaw.
cbSubordinate.setSelected(false);
}
if (cbSubordinate.isSelected()) {
WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
container.add(group);
WSubordinateControl control = new WSubordinateControl();
container.add(control);
for (String option : OPTIONS_ARRAY) {
buildSubordinatePanel(dropdown, option, group, control);
}
// add a rule for none selected.
Rule rule = new Rule();
control.addRule(rule);
rule.setCondition(new Equal(dropdown, ""));
rule.addActionOnTrue(new Hide(group));
}
WFieldLayout flay = new WFieldLayout();
flay.setLabelWidth(25);
container.add(flay);
flay.addField("Configured dropdown", dropdown);
flay.addField((WLabel) null, new WButton("Submit"));
}
use of com.github.bordertech.wcomponents.subordinate.Hide in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testMultipleControlsAndGroups.
@Test
public void testMultipleControlsAndGroups() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WCheckBox();
// Setup Groups
SubordinateTarget actionTarget1 = new WTextField();
SubordinateTarget actionTarget2 = new WTextField();
SubordinateTarget actionTarget3 = new WTextField();
SubordinateTarget actionTarget4 = new WTextField();
// Multiple Groups
WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
group1.addToGroup(actionTarget1);
group1.addToGroup(actionTarget2);
WComponentGroup<SubordinateTarget> group2 = new WComponentGroup<>();
group2.addToGroup(actionTarget3);
group2.addToGroup(actionTarget4);
// Multiple Rules
Rule rule1 = new Rule();
rule1.setCondition(new Equal(condTrigger, Boolean.TRUE));
rule1.addActionOnTrue(new Show(group1));
rule1.addActionOnFalse(new Hide(group1));
Rule rule2 = new Rule();
rule2.setCondition(new Equal(condTrigger, Boolean.FALSE));
rule2.addActionOnTrue(new Show(group2));
rule2.addActionOnFalse(new Hide(group2));
// Setup Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule1);
control.addRule(rule2);
WContainer root = new WContainer();
root.add(condTrigger);
root.add(actionTarget1);
root.add(actionTarget2);
root.add(actionTarget3);
root.add(actionTarget4);
root.add(control);
root.add(group1);
root.add(group2);
setActiveContext(createUIContext());
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check for basic elements
assertXpathEvaluatesTo("2", "count(//ui:subordinate)", root);
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:condition)", root);
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
assertXpathEvaluatesTo("2", "count(//ui:componentGroup)", root);
assertXpathEvaluatesTo("2", "count(//ui:componentGroup[position()=1]/ui:component)", root);
assertXpathEvaluatesTo("2", "count(//ui:componentGroup[position()=2]/ui:component)", root);
// Check ids
assertXpathEvaluatesTo(control.getId() + "-c0", "//ui:subordinate[position()=1]/@id", root);
assertXpathEvaluatesTo(control.getId() + "-c1", "//ui:subordinate[position()=2]/@id", root);
}
use of com.github.bordertech.wcomponents.subordinate.Hide in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testAndCondition.
@Test
public void testAndCondition() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger1 = new WCheckBox();
SubordinateTrigger condTrigger2 = new WCheckBox();
SubordinateTrigger condTrigger3 = new WCheckBox();
// Create AND condition
Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
Condition and = new And(cond1, cond2, cond3);
SubordinateTarget actionTarget = new WTextField();
// Setup Rule with AND Condition
Rule rule = new Rule();
rule.setCondition(and);
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(condTrigger1);
root.add(condTrigger2);
root.add(condTrigger3);
root.add(actionTarget);
root.add(control);
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check AND
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:and/ui:condition)", root);
assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:and/ui:condition[position()=1]/@controller", root);
assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:and/ui:condition[position()=2]/@controller", root);
assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:and/ui:condition[position()=3]/@controller", root);
// Check action target
assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
use of com.github.bordertech.wcomponents.subordinate.Hide in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testNestedConditions.
@Test
public void testNestedConditions() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WCheckBox();
// Create Nested Condition
Condition cond1 = new Equal(condTrigger, Boolean.TRUE);
Condition cond2 = new Equal(condTrigger, Boolean.TRUE);
Condition cond3 = new Equal(condTrigger, Boolean.TRUE);
Condition cond4 = new Equal(condTrigger, Boolean.TRUE);
Condition orTest = new Or(cond1, cond2);
Condition and1 = new And(cond3, orTest);
Condition and2 = new And(cond4, and1);
SubordinateTarget actionTarget = new WTextField();
// Setup rule with Nested Condition
Rule rule = new Rule();
rule.setCondition(and2);
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);
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check Nested
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:condition)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:condition)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:or)", root);
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:and/ui:and/ui:or/ui:condition)", root);
// Check action target
assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
use of com.github.bordertech.wcomponents.subordinate.Hide 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);
}
Aggregations