/** * Updates the recent list with the new selection. * * @param newSelection the new selection. */ private void updateRecent(final String newSelection) { List recentList = recentDropdown.getOptions(); if (recentList.contains(newSelection)) { recentList.remove(newSelection); } recentList.add(0, newSelection); recentDropdown.setOptions(recentList); recentDropdown.setSelected(newSelection); }
/** * Retrieves the example which has been selected by the user. * * @return the selected example. */ public String getSelected() { return (String) recentDropdown.getSelected(); }
@Override public String getDesc(final Object option, final int index) { if (option == null) { return "Select one"; } else { return super.getDesc(option, index); } } };
@Override public void execute(final ActionEvent event) { String regionSelected = (String) region.getSelected(); suburb.setOptions(getSuburbs(regionSelected)); suburb.resetData(); } });
/** * Updates the options present in the region selector, depending on the state selector's value. */ private void updateRegion() { actMessage.setVisible(false); String state = (String) stateSelector.getSelected(); if (STATE_ACT.equals(state)) { actMessage.setVisible(true); regionSelector.setOptions(new String[]{null, "Belconnen", "City", "Woden"}); } else if (STATE_NSW.equals(state)) { regionSelector.setOptions( new String[]{null, "Hunter", "Riverina", "Southern Tablelands"}); } else if (STATE_VIC.equals(state)) { regionSelector.setOptions( new String[]{null, "Gippsland", "Melbourne", "Mornington Peninsula"}); } else { regionSelector.setOptions(new Object[]{null}); } }
@Test public void testDoPaintOptions() throws IOException, SAXException, XpathException { WDropdown drop = new WDropdown(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE); assertXpathEvaluatesTo(drop.getId(), "//ui:dropdown/@id", drop); assertXpathEvaluatesTo(drop.getListCacheKey(), "//ui:dropdown/@data", drop); drop.setDisabled(true); assertSchemaMatch(drop); assertXpathEvaluatesTo("true", "//ui:dropdown/@disabled", drop); drop.setMandatory(true); assertSchemaMatch(drop); assertXpathEvaluatesTo("true", "//ui:dropdown/@required", drop); drop.setSubmitOnChange(true); assertSchemaMatch(drop); assertXpathEvaluatesTo("true", "//ui:dropdown/@submitOnChange", drop); drop.setToolTip("tooltip"); assertSchemaMatch(drop); assertXpathEvaluatesTo(drop.getToolTip(), "//ui:dropdown/@toolTip", drop); drop.setAccessibleText("accessible"); assertSchemaMatch(drop); assertXpathEvaluatesTo(drop.getAccessibleText(), "//ui:dropdown/@accessibleText", drop); drop.setOptionWidth(20); assertSchemaMatch(drop); assertXpathEvaluatesTo("20", "//ui:dropdown/@optionWidth", drop);
@Test public void testSetAutocompleteNullSegment() { WDropdown field = new WDropdown(); field.setAutocomplete(Person.GIVEN); Assert.assertNotNull(field.getAutocomplete()); field.setAutocomplete((AutocompleteSegment) null); Assert.assertNull(field.getAutocomplete()); }
WDropdown dropdown = (WDropdown) component; XmlStringBuilder xml = renderContext.getWriter(); boolean readOnly = dropdown.isReadOnly(); String dataKey = dropdown.getListCacheKey(); xml.appendOptionalAttribute("class", component.getHtmlClass()); xml.appendOptionalAttribute("track", component.isTracking(), "true"); xml.appendOptionalAttribute("hidden", dropdown.isHidden(), "true"); if (readOnly) { xml.appendAttribute("readOnly", "true"); } else { xml.appendOptionalAttribute("data", dataKey != null, dataKey); xml.appendOptionalAttribute("disabled", dropdown.isDisabled(), "true"); xml.appendOptionalAttribute("required", dropdown.isMandatory(), "true"); xml.appendOptionalAttribute("submitOnChange", dropdown.isSubmitOnChange(), "true"); xml.appendOptionalAttribute("toolTip", dropdown.getToolTip()); xml.appendOptionalAttribute("accessibleText", dropdown.getAccessibleText()); int optionWidth = dropdown.getOptionWidth(); xml.appendOptionalAttribute("optionWidth", optionWidth > 0, optionWidth); String autocomplete = dropdown.getAutocomplete(); xml.appendOptionalAttribute("autocomplete", !Util.empty(autocomplete), autocomplete); xml.appendOptionalAttribute("type", getTypeAsString(dropdown.getType())); List<?> options = dropdown.getOptions(); Object selectedOption = dropdown.getSelected(); if (dropdown.getType() == WDropdown.DropdownType.COMBO && selectedOption != null && (options == null || !options.contains(selectedOption))) {
final WDropdown dropdown = new WDropdown(options); dropdown.setType((DropdownType) rbsDDType.getSelected()); dropdown.setSelected(selected); dropdown.setOptionWidth(nfWidth.getValue().intValue()); dropdown.setToolTip(tfToolTip.getText()); dropdown.setVisible(cbVisible.isSelected()); dropdown.setDisabled(cbDisabled.isSelected()); infoPanel.add(info); dropdown.setActionOnChange(new Action() { @Override public void execute(final ActionEvent event) { dropdown.setSubmitOnChange(cbSubmitOnChange.isSelected());
@Test public void testDropdown() { WDropdownSpaceHandlingExample example = (WDropdownSpaceHandlingExample) getUi(); // Launch the web browser to the LDE SeleniumWComponentsWebDriver driver = getDriver(); 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(); driver.findWButtonByText("Submit").click(); Assert.assertEquals("Incorrect option selected", option, dropdown.getSelected()); } } finally { UIContextHolder.popContext(); } } }
@Test public void testDataList() throws IOException, SAXException, XpathException { WDropdown drop = new WDropdown(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE); assertSchemaMatch(drop); String code = drop.getCode(drop.getOptions().get(0), 0); String desc = drop.getDesc(drop.getOptions().get(0), 0); assertXpathEvaluatesTo("1", "count(//ui:dropdown/ui:option)", drop); assertXpathEvaluatesTo(desc, "//ui:dropdown/ui:option[@value='" + code + "']/text()", drop); assertXpathEvaluatesTo(drop.getListCacheKey(), "//ui:dropdown/@data", drop); }
@Test public void testConstructorDefault() { WDropdown dropdown = new WDropdown(); Assert.assertNull("Incorrect options returned", dropdown.getOptions()); Assert.assertFalse("allowNoSelection should be false", dropdown.isAllowNoSelection()); }
WDropdown dropdown = new WDropdown(OPTIONS_ARRAY); addFieldToLayout(dropdown, "Simple drop-down", null); dropdown = new WDropdown(OPTIONS_ARRAY); dropdown.setSelected(OPTIONS_ARRAY[1]); addFieldToLayout(dropdown, "Simple drop-down with default selection", null); dropdown = new WDropdown(OPTIONS_NULL_ARRAY); addFieldToLayout(dropdown, "Simple drop-down, with \"null\" option", null); dropdown = new WDropdown(OPTIONS_NULL_ARRAY) { @Override public String getDesc(final Object option, final int index) { dropdown = new WDropdown(people); addFieldToLayout(dropdown, "Drop-down with a list of beans", "This is an example dropdown with data from a non-textual source."); dropdown = new WDropdown(peopleOptions); addFieldToLayout(dropdown, "Drop-down with a list of options", null); dropdown = new WDropdown(new Object[]{stringGroup, peopleGroup, "Ungrouped option"}); addFieldToLayout(dropdown, "Drop-down with option groups", null); dropdown = new WDropdown(OPTIONS_ARRAY); dropdown.setType(WDropdown.DropdownType.COMBO); addFieldToLayout(dropdown, "Combo drop-down", "This is an example dropdown which allows user input");
/** * Setup the default values for the configuration options. */ private void setPresets() { TriggerType selectedTrigger = (TriggerType) drpTriggerType.getSelected(); comboField.setVisible( selectedTrigger != TriggerType.DateField && selectedTrigger != TriggerType.NumberField); dateField.setVisible(selectedTrigger == TriggerType.DateField); numberField.setVisible(selectedTrigger == TriggerType.NumberField); // If a group action selected, then target can only be the field (as it is defined in a group) switch ((ControlActionType) drpActionType.getSelected()) { case ENABLEIN_DISABLEIN: case SHOWIN_HIDEIN: drpTargetType.setSelected(TargetType.WFIELD); drpTargetType.setDisabled(true); break; default: drpTargetType.setDisabled(false); } }
@Test public void testAddAutocompleteSectionAfterSettingWithSection() { WDropdown field = new WDropdown(); String sectionName = "foo"; String otherSectionName = "bar"; field.setAutocomplete(Person.FAMILY); field.addAutocompleteSection(otherSectionName); String expected = AutocompleteUtil.getCombinedForSection(sectionName, AutocompleteUtil.getNamedSection(otherSectionName), Person.FAMILY.getValue()); field.addAutocompleteSection(sectionName); Assert.assertEquals(expected, field.getAutocomplete()); }
@Test public void testSetAutocompleteOffAfterSetting() { WDropdown field = new WDropdown(); field.setAutocomplete(Person.FAMILY); field.addAutocompleteSection("foo"); field.setAutocompleteOff(); Assert.assertTrue(field.isAutocompleteOff()); }
@Test public void testSetLocalPhoneAutocomplete() { WDropdown field = new WDropdown(); String expected = Telephone.LOCAL.getValue(); field.setLocalPhoneAutocomplete(); Assert.assertEquals(expected, field.getAutocomplete()); }
@Test public void testSetFullPhoneAutocompleteWithNullType() { WDropdown field = new WDropdown(); field.setFullPhoneAutocomplete(null); Assert.assertEquals(Telephone.FULL.getValue(), field.getAutocomplete()); }
@Test public void testSetPhoneSegmentAutocompleteNull() { WDropdown field = new WDropdown(); field.setAutocomplete(Person.GIVEN); Assert.assertNotNull(field.getAutocomplete()); field.setPhoneSegmentAutocomplete(null, null); Assert.assertNull(field.getAutocomplete()); }
@Test public void testClearAutocomplete() { WDropdown field = new WDropdown(); field.setAutocomplete(Person.FAMILY); Assert.assertNotNull(field.getAutocomplete()); field.clearAutocomplete(); Assert.assertNull(field.getAutocomplete()); }