use of com.github.bordertech.wcomponents.subordinate.WSubordinateControl 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.WSubordinateControl in project wcomponents by BorderTech.
the class WAudioExample method buildUI.
/**
* Build the UI for this example.
*/
private void buildUI() {
// build the configuration options UI.
WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
layout.setMargin(new Margin(null, null, Size.LARGE, null));
add(layout);
layout.addField("Autoplay", cbAutoPlay);
layout.addField("Loop", cbLoop);
layout.addField("Disable", cbDisable);
layout.addField("Show only play/pause", cbControls);
layout.addField((WLabel) null, btnApply);
// enable disable option only when control PLAY_PAUSE is used.
WSubordinateControl control = new WSubordinateControl();
add(control);
Rule rule = new Rule();
rule.setCondition(new Equal(cbControls, Boolean.TRUE.toString()));
rule.addActionOnTrue(new Enable(cbDisable));
rule.addActionOnFalse(new Disable(cbDisable));
control.addRule(rule);
// allow config to change without reloading the whole page.
add(new WAjaxControl(btnApply, audio));
// add the audio to the UI
add(audio);
}
use of com.github.bordertech.wcomponents.subordinate.WSubordinateControl in project wcomponents by BorderTech.
the class SubordinateControlMandatoryExample method build.
/**
* Creates the component to be added to the validation container. This is doen in a static method because the
* component is passed into the superclass constructor.
*
* @return the component to be added to the validation container.
*/
private static WComponent build() {
WContainer root = new WContainer();
WSubordinateControl control = new WSubordinateControl();
root.add(control);
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(25);
layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
WCheckBox checkBox = new WCheckBox();
layout.addField("Set Mandatory", checkBox);
WTextField text = new WTextField();
layout.addField("Might need this field", text);
WTextField mandatoryField = new WTextField();
layout.addField("Another field always mandatory", mandatoryField);
mandatoryField.setMandatory(true);
final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
layout.addField("Select a state", rbSelect);
root.add(layout);
Rule rule = new Rule();
rule.setCondition(new Equal(checkBox, Boolean.TRUE.toString()));
rule.addActionOnTrue(new Mandatory(text));
rule.addActionOnFalse(new Optional(text));
rule.addActionOnTrue(new Mandatory(rbSelect));
rule.addActionOnFalse(new Optional(rbSelect));
control.addRule(rule);
return root;
}
use of com.github.bordertech.wcomponents.subordinate.WSubordinateControl 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);
}
use of com.github.bordertech.wcomponents.subordinate.WSubordinateControl in project wcomponents by BorderTech.
the class WDateFieldExample method addDateRangeExample.
/**
* Add date range example.
*/
private void addDateRangeExample() {
add(new WHeading(WHeading.MAJOR, "Example of a date range component"));
WFieldSet dateRange = new WFieldSet("Enter the expected arrival and departure dates.");
add(dateRange);
WPanel dateRangePanel = new WPanel();
dateRangePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0));
dateRange.add(dateRangePanel);
final WDateField arrivalDate = new WDateField();
final WDateField departureDate = new WDateField();
// One could add some validation rules around this so that "arrival" was always earlier than or equal to "departure"
WLabel arrivalLabel = new WLabel("Arrival", arrivalDate);
arrivalLabel.setHint("dd MMM yyyy");
WLabel departureLabel = new WLabel("Departure", departureDate);
departureLabel.setHint("dd MMM yyyy");
dateRangePanel.add(arrivalLabel);
dateRangePanel.add(arrivalDate);
dateRangePanel.add(departureLabel);
dateRangePanel.add(departureDate);
// subordinate control to ensure that the departure date is only enabled if the arrival date is populated
WSubordinateControl control = new WSubordinateControl();
add(control);
Rule rule = new Rule(new Equal(arrivalDate, null));
control.addRule(rule);
rule.addActionOnTrue(new Disable(departureDate));
rule.addActionOnFalse(new Enable(departureDate));
control.addRule(rule);
}
Aggregations