Example usage for com.google.gwt.dom.client OptionElement setText

List of usage examples for com.google.gwt.dom.client OptionElement setText

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

The text contained within the option element.

Usage

From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java

License:Apache License

/**
 * Appends an item to the end of the list, adding the supplied class name to its class attribute. Specifying a
 * non-zero {@code indentLevel} will pad the item from the left by a fixed distance applied {@code indentLevel}
 * times./*  ww w.j  a  va 2s.  c o m*/
 * <p/>
 * For example, a call:
 * <p/>
 * {@code
 * addStyledItem("My Item", "item1", "highlighted", 1);
 * }
 * <p/>
 * will result in the addition to the end of the {@code <select>} element of:
 * <p/>
 * {@code
 * <option value="item1" class="highlighted" style="padding-left: 15px;" >My Item</option>
 * }
 *
 * @param label       the item label to display to the user
 * @param value       the value of the item, meaningful in the context of an HTML form
 * @param className   the class name to add to this item (pass {@code null} to add no class name)
 * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation)
 */
public void addStyledItem(String label, String value, String className, int indentLevel) {
    if (indentLevel < 0) {
        throw new IllegalArgumentException("[indentLevel] must be non-negative.");
    }
    GQuery $selectElem = $(getElement());
    OptionElement option = Document.get().createOptionElement();
    option.setValue(value);
    option.setText(label);
    if (!(className == null || className.trim().isEmpty())) {
        option.addClassName(className);
    }
    if (indentLevel > 0) {
        int leftPadding = options.getResources().css().indent() * indentLevel;
        option.setAttribute("style", "padding-left: " + leftPadding + "px;");
    }
    $selectElem.append(option);
}

From source file:com.horaz.client.widgets.SelectMenu.java

License:Open Source License

/**
 * generates a new option element. see {@link #setOptions(OptionElement[])}
 * how to add options to a select element
 * @param text//www  .  j ava  2  s.c o m
 * @param value
 * @return
 */
public static OptionElement createOption(String text, String value) {
    OptionElement o = OptionElement.as(DOM.createOption());
    o.setText(text);
    o.setValue(value);
    return o;
}

From source file:com.tractionsoftware.gwt.user.client.ui.GroupedListBox.java

License:Apache License

@Override
public void setItemText(int index, String text) {
    if (text == null) {
        throw new NullPointerException("Cannot set an option to have null text");
    }/*w  w  w.ja  va2  s.c om*/
    OptionElement option = getOption(index);
    option.setText(text);
}

From source file:com.tractionsoftware.gwt.user.client.ui.GroupedListBox.java

License:Apache License

protected OptionElement createOption(String item, String value) {
    OptionElement option = Document.get().createOptionElement();
    option.setText(item);
    option.setInnerText(item);//  ww w .j a  v a 2s.  c  o m
    option.setValue(value);
    return option;
}

From source file:net.sf.mmm.client.ui.gwt.widgets.DataList.java

License:Apache License

/**
 * @param options the textual options.// ww w .ja  v a 2  s . c om
 */
public void setOptions(List<String> options) {

    // clear potential previous options
    @SuppressWarnings("deprecation")
    com.google.gwt.user.client.Element element = getElement();
    Element childElement = element.getFirstChildElement();
    while (childElement != null) {
        childElement.removeFromParent();
        childElement = element.getFirstChildElement();
    }

    // create new options
    for (String opt : options) {
        OptionElement option = Document.get().createOptionElement();
        // TODO use DirectionEstimator...
        option.setText(opt);
        element.appendChild(option);
    }
    this.options = options;
}

From source file:net.urlgrey.mythpodcaster.client.StyledListBox.java

License:Open Source License

public void addItemWithStyle(String item, String value) {
    final SelectElement select = getElement().cast();
    final OptionElement option = Document.get().createOptionElement();
    option.setText(item);
    option.setValue(value);//from  w w  w. ja  v a2s. c o m
    option.setClassName(styleName);

    select.add(option, null);
}

From source file:org.kaaproject.avro.ui.gwt.client.widget.ExtendedValueListBox.java

License:Apache License

private void updateOptionsStyle() {
    if (Utils.isNotBlank(promptText)) {
        SelectElement select = getSelectElement();
        int index = select.getSelectedIndex();
        if (index > -1) {
            OptionElement selectedOption = getOptionElement(index);
            if (Utils.isBlank(selectedOption.getValue())) {
                selectedOption.setClassName(style.prompt());
                selectedOption.setText(promptText);
                addStyleName(style.prompt());
                NodeList<OptionElement> options = getSelectElement().getOptions();
                for (int i = 0; i < options.getLength(); i++) {
                    if (index != i) {
                        OptionElement option = options.getItem(i);
                        option.setClassName(style.noPrompt());
                    }// ww  w.ja va  2s. c  o  m
                }
            } else {
                NodeList<OptionElement> options = getSelectElement().getOptions();
                for (int i = 0; i < options.getLength(); i++) {
                    OptionElement option = options.getItem(i);
                    if (Utils.isBlank(option.getValue())) {
                        option.setClassName("");
                        option.setText("");
                    }
                }
                removeStyleName(style.prompt());
            }
        }
    }
}

From source file:org.otalo.ao.client.widget.chlist.client.ChosenImpl.java

License:Apache License

public void insertItemInSelect(String item, String value, int index) {
    OptionElement option = Document.get().createOptionElement();
    option.setText(item);
    option.setValue(value);// w w w .j a  va  2s.  c  om
    option.setSelected(true);

    int itemCount = selectElement.getLength();
    if (index < 0 || index > itemCount) {
        index = itemCount;
    }
    if (index == itemCount) {
        selectElement.add(option, null);
    } else {
        OptionElement before = selectElement.getOptions().getItem(index);
        selectElement.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);//www.  jav a 2 s .c  om
            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;
        }
    });
}