use of com.github.bordertech.wcomponents.WDropdown in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method setupTrigger.
/**
* Setup the trigger for the subordinate control.
*/
private void setupTrigger() {
String label = drpTriggerType.getSelected() + " Trigger";
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(LABEL_WIDTH);
buildControlPanel.add(layout);
switch((TriggerType) drpTriggerType.getSelected()) {
case RadioButtonGroup:
trigger = new RadioButtonGroup();
WFieldSet rbSet = new WFieldSet("Select an option");
RadioButtonGroup group = (RadioButtonGroup) trigger;
WRadioButton rb1 = group.addRadioButton("A");
WRadioButton rb2 = group.addRadioButton("B");
WRadioButton rb3 = group.addRadioButton("C");
rbSet.add(group);
rbSet.add(rb1);
rbSet.add(new WLabel("A", rb1));
rbSet.add(new WText("\u00a0"));
rbSet.add(rb2);
rbSet.add(new WLabel("B", rb2));
rbSet.add(new WText("\u00a0"));
rbSet.add(rb3);
rbSet.add(new WLabel("C", rb3));
layout.addField(label, rbSet);
return;
case CheckBox:
trigger = new WCheckBox();
break;
case CheckBoxSelect:
trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
break;
case DateField:
trigger = new WDateField();
break;
case Dropdown:
trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
break;
case EmailField:
trigger = new WEmailField();
break;
case MultiSelect:
trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
break;
case MultiSelectPair:
trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
break;
case NumberField:
trigger = new WNumberField();
break;
case PartialDateField:
trigger = new WPartialDateField();
break;
case PasswordField:
trigger = new WPasswordField();
break;
case PhoneNumberField:
trigger = new WPhoneNumberField();
break;
case RadioButtonSelect:
trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
break;
case SingleSelect:
trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
break;
case TextArea:
trigger = new WTextArea();
((WTextArea) trigger).setMaxLength(1000);
break;
case TextField:
trigger = new WTextField();
break;
default:
throw new SystemException("Trigger type not valid");
}
layout.addField(label, trigger);
}
use of com.github.bordertech.wcomponents.WDropdown in project wcomponents by BorderTech.
the class WFieldSetExample method addFieldSet.
/**
* Creates a WFieldSet with content and a given FrameType.
*
* @param title The title to give to the WFieldSet.
* @param type The decorative model of the WFieldSet
* @return a WFieldSet with form control content.
*/
private WFieldSet addFieldSet(final String title, final WFieldSet.FrameType type) {
final WFieldSet fieldset = new WFieldSet(title);
fieldset.setFrameType(type);
fieldset.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
final WFieldLayout layout = new WFieldLayout();
fieldset.add(layout);
layout.setLabelWidth(25);
layout.addField("Street address", new WTextField());
final WField add2Field = layout.addField("Street address line 2", new WTextField());
add2Field.getLabel().setHidden(true);
layout.addField("Suburb", new WTextField());
layout.addField("State/Territory", new WDropdown(new String[] { "", "ACT", "NSW", "NT", "QLD", "SA", "TAS", "VIC", "WA" }));
// NOTE: this is an Australia-specific post code field. An Australian post code is not a number as they may contain a leading zero.
final WTextField postcode = new WTextField();
postcode.setMaxLength(4);
postcode.setColumns(4);
postcode.setMinLength(3);
layout.addField("Postcode", postcode);
add(fieldset);
return fieldset;
}
use of com.github.bordertech.wcomponents.WDropdown in project wcomponents by BorderTech.
the class LoadAjaxControlsExample method createFields.
/**
* @param layout the layout to add the fields to
* @param table the lookupTable to use on the fields
*/
private void createFields(final WFieldLayout layout, final Object table) {
WDropdown down = new WDropdown(table);
down.setType(DropdownType.COMBO);
layout.addField("Combo Dropdown", down);
WMultiDropdown multi = new WMultiDropdown(table);
layout.addField("Multi Dropdown", multi);
WMultiSelect select = new WMultiSelect(table);
layout.addField("Multi Select", select);
}
use of com.github.bordertech.wcomponents.WDropdown 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.WDropdown in project wcomponents by BorderTech.
the class WDropdownOptionsExample_Test method testExampleSubmitOnChange.
/**
* submit on change test.
*/
@Test
public void testExampleSubmitOnChange() {
WDropdownOptionsExample example = (WDropdownOptionsExample) getUi();
// Launch the web browser to the LDE
SeleniumWComponentsWebDriver driver = getDriver();
WDropdown.DropdownType type = WDropdown.DropdownType.NATIVE;
configureDropDown(driver, type, 4);
UIContext uic = getUserContextForSession();
UIContextHolder.pushContext(uic);
try {
WDropdown dropdown = (WDropdown) TreeUtil.findWComponent(example, new String[] { "WDropdown" }).getComponent();
List<?> options = dropdown.getOptions();
for (Object option : options) {
driver.findElement(byWComponent(dropdown, option)).click();
Assert.assertEquals("Incorrect option selected", option, dropdown.getSelected());
Assert.assertEquals("Incorrect text field text", option, driver.findElement(byWComponentPath("WDropdownOptionsExample/WPanel[1]")).getText());
}
} finally {
UIContextHolder.popContext();
}
}
Aggregations