Example usage for com.google.gwt.dom.client SelectElement getLength

List of usage examples for com.google.gwt.dom.client SelectElement getLength

Introduction

In this page you can find the example usage for com.google.gwt.dom.client SelectElement getLength.

Prototype

public final int getLength() 

Source Link

Document

The number of options in this SELECT.

Usage

From source file:org.pentaho.mantle.client.ui.custom.ListBoxTitle.java

License:Open Source License

@Override
public void insertItem(String item, HasDirection.Direction dir, String value, int index) {
    SelectElement select = (SelectElement) this.getElement().cast();
    OptionElement option = Document.get().createOptionElement();
    this.setOptionText(option, item, dir);
    option.setValue(value);/*  w  w  w.j a v a  2 s  .  c  o m*/
    option.setTitle(value);
    int itemCount = select.getLength();
    if (index < 0 || index > itemCount) {
        index = itemCount;
    }

    if (index == itemCount) {
        select.add(option, (OptionElement) null);
    } else {
        OptionElement before = (OptionElement) select.getOptions().getItem(index);
        select.add(option, before);
    }
}

From source file:org.swellrt.webclient.WebClientMod.java

License:Apache License

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);/*from  w  w  w. j a v  a2 s  .c o m*/
            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;
        }
    });
}