Java Code Examples for com.google.gwt.dom.client.SelectElement#setSelectedIndex()
The following examples show how to use
com.google.gwt.dom.client.SelectElement#setSelectedIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebClient.java From swellrt with Apache License 2.0 | 5 votes |
private void setupLocaleSelect() { final SelectElement select = (SelectElement) Document.get().getElementById("lang"); String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName(); String[] localeNames = LocaleInfo.getAvailableLocaleNames(); for (String locale : localeNames) { if (!DEFAULT_LOCALE.equals(locale)) { String displayName = LocaleInfo.getLocaleNativeDisplayName(locale); OptionElement option = Document.get().createOptionElement(); option.setValue(locale); option.setText(displayName); select.add(option, null); if (locale.equals(currentLocale)) { select.setSelectedIndex(select.getLength() - 1); } } } EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() { @Override public boolean onChange(ChangeEvent event, Element context) { UrlBuilder builder = Location.createUrlBuilder().setParameter( "locale", select.getValue()); Window.Location.replace(builder.buildString()); localeService.storeLocale(select.getValue()); return true; } }); }
Example 2
Source File: WebClient.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
private void setupLocaleSelect() { final SelectElement select = (SelectElement) Document.get().getElementById("lang"); String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName(); String[] localeNames = LocaleInfo.getAvailableLocaleNames(); for (String locale : localeNames) { if (!DEFAULT_LOCALE.equals(locale)) { String displayName = LocaleInfo.getLocaleNativeDisplayName(locale); OptionElement option = Document.get().createOptionElement(); option.setValue(locale); option.setText(displayName); select.add(option, null); if (locale.equals(currentLocale)) { select.setSelectedIndex(select.getLength() - 1); } } } EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() { @Override public boolean onChange(ChangeEvent event, Element context) { UrlBuilder builder = Location.createUrlBuilder().setParameter( "locale", select.getValue()); Window.Location.replace(builder.buildString()); localeService.storeLocale(select.getValue()); return true; } }); }