use of com.github.bordertech.wcomponents.subordinate.Disable in project wcomponents by BorderTech.
the class WDropdownOptionsExample method getDropDownControls.
/**
* build the drop down controls.
*
* @return a field set containing the dropdown controls.
*/
private WFieldSet getDropDownControls() {
WFieldSet fieldSet = new WFieldSet("Drop down configuration");
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(25);
fieldSet.add(layout);
rbsDDType.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
rbsDDType.setSelected(WDropdown.DropdownType.NATIVE);
rbsDDType.setFrameless(true);
layout.addField("Dropdown Type", rbsDDType);
nfWidth.setMinValue(0);
nfWidth.setDecimalPlaces(0);
layout.addField("Width", nfWidth);
layout.addField("ToolTip", tfToolTip);
layout.addField("Include null option", cbNullOption);
rgDefaultOption.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
rgDefaultOption.setButtonColumns(2);
rgDefaultOption.setSelected(NONE);
rgDefaultOption.setFrameless(true);
layout.addField("Default Option", rgDefaultOption);
layout.addField("Action on change", cbActionOnChange);
layout.addField("Ajax", cbAjax);
WField subField = layout.addField("Subordinate", cbSubordinate);
// .getLabel().setHint("Does not work with Dropdown Type COMBO");
layout.addField("Submit on change", cbSubmitOnChange);
layout.addField("Visible", cbVisible);
layout.addField("Disabled", cbDisabled);
// Apply Button
WButton apply = new WButton("Apply");
fieldSet.add(apply);
WSubordinateControl subSubControl = new WSubordinateControl();
Rule rule = new Rule();
subSubControl.addRule(rule);
rule.setCondition(new Equal(rbsDDType, WDropdown.DropdownType.COMBO));
rule.addActionOnTrue(new Disable(subField));
rule.addActionOnFalse(new Enable(subField));
fieldSet.add(subSubControl);
apply.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
applySettings();
}
});
return fieldSet;
}
use of com.github.bordertech.wcomponents.subordinate.Disable in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testEnableDisableActions.
@Test
public void testEnableDisableActions() 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 Enable/Disable actions
Rule rule = new Rule();
rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
// Single Component Target
rule.addActionOnTrue(new Enable(actionTarget));
rule.addActionOnFalse(new Disable(actionTarget));
// Group Target
rule.addActionOnTrue(new Enable(group1));
rule.addActionOnFalse(new Disable(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("enable", "//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("enable", "//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("disable", "//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("disable", "//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() + "']/@disabled", root);
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@disabled", root);
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@disabled", root);
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@disabled", root);
}
use of com.github.bordertech.wcomponents.subordinate.Disable in project wcomponents by BorderTech.
the class SubordinateControlInterceptor_Test method testServiceRequestApplyControls.
@Test
public void testServiceRequestApplyControls() {
ButtonState state = new ButtonState();
// Create Target
WButton target = new WButton();
target.setAction((final ActionEvent event) -> {
state.setClicked(true);
});
// Create Control - Enable/Disable Button
WCheckBox box = new WCheckBox();
Rule rule = new Rule();
rule.setCondition(new Equal(box, Boolean.TRUE));
rule.addActionOnTrue(new Enable(target));
rule.addActionOnFalse(new Disable(target));
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
// Create component tree
WContainer root = new WContainer();
root.add(control);
root.add(box);
root.add(target);
// Setup Intercepter
SubordinateControlInterceptor interceptor = new SubordinateControlInterceptor();
interceptor.setBackingComponent(root);
UIContext uic = createUIContext();
uic.setUI(root);
setActiveContext(uic);
state.setClicked(false);
// Test Service Request - Empty Request and no control registered, so the control should not be applied
MockRequest request = new MockRequest();
interceptor.serviceRequest(request);
// Target should still be enabled (control not applied)
Assert.assertFalse("After service request target should be enabled", target.isDisabled());
// Button not clicked
Assert.assertFalse("Button should not have been clicked", state.isClicked());
// Test Service Request - Try to click button while it is disabled and should not be clicked
target.setDisabled(true);
request.setParameter(target.getId(), "x");
interceptor.serviceRequest(request);
// Target should still be disabled (control not applied, as still not registered)
Assert.assertTrue("After service request target should be disabled", target.isDisabled());
// Button not clicked
Assert.assertFalse("Button should not have been clicked while disabled", state.isClicked());
// Test Prepare Paint - Should register and apply the subordinate control
target.setDisabled(false);
request = new MockRequest();
interceptor.preparePaint(request);
// Target should be disabled (Disabled by control as box is not selected)
Assert.assertTrue("After service request target should be disabled", target.isDisabled());
// Test Service Request - Simulate button click as it was enabled on the client by the check box being selected.
// As the controls have been registered from the Prepare Paint, they will be applied in the Service Request and
// this will enable the button and allow it to be clicked.
state.setClicked(false);
request.setParameter(target.getId(), "x");
setupCheckBoxRequest(box, request, true);
interceptor.serviceRequest(request);
// Target should be enabled (enabled by control as box is selected)
Assert.assertFalse("After service request target should be enabled", target.isDisabled());
// Button should have been clicked
Assert.assertTrue("Button should have been clicked", state.isClicked());
}
use of com.github.bordertech.wcomponents.subordinate.Disable 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.subordinate.Disable in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method buildControl.
/**
* Build the subordinate control.
*/
private void buildControl() {
buildControlPanel.reset();
buildTargetPanel.reset();
// Setup Trigger
setupTrigger();
// Create target
SubordinateTarget target = setupTarget();
// Create Actions
com.github.bordertech.wcomponents.subordinate.Action trueAction;
com.github.bordertech.wcomponents.subordinate.Action falseAction;
switch((ControlActionType) drpActionType.getSelected()) {
case ENABLE_DISABLE:
trueAction = new Enable(target);
falseAction = new Disable(target);
break;
case SHOW_HIDE:
trueAction = new Show(target);
falseAction = new Hide(target);
break;
case MAN_OPT:
trueAction = new Mandatory(target);
falseAction = new Optional(target);
break;
case SHOWIN_HIDEIN:
trueAction = new ShowInGroup(target, targetGroup);
falseAction = new HideInGroup(target, targetGroup);
break;
case ENABLEIN_DISABLEIN:
trueAction = new EnableInGroup(target, targetGroup);
falseAction = new DisableInGroup(target, targetGroup);
break;
default:
throw new SystemException("ControlAction type not valid");
}
// Create Condition
Condition condition = createCondition();
if (cbNot.isSelected()) {
condition = new Not(condition);
}
// Create Rule
Rule rule = new Rule(condition, trueAction, falseAction);
// Create Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
buildControlPanel.add(control);
if (targetCollapsible.getDecoratedLabel() != null) {
targetCollapsible.getDecoratedLabel().setTail(new WText(control.toString()));
}
control = new WSubordinateControl();
rule = new Rule(new Equal(cbClientDisableTrigger, true), new Disable((SubordinateTarget) trigger), new Enable((SubordinateTarget) trigger));
control.addRule(rule);
buildControlPanel.add(control);
}
Aggregations