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

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

Introduction

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

Prototype

public boolean isSelected() 

Source Link

Document

Represents the current state of the corresponding form control, in an interactive user agent.

Usage

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

License:Apache License

/**
 * Return the values of all selected options in an array.
 * Usefull to know which options are selected in case of multiple ChosenListBox
 *
 * @return the values of all selected options in an array
 *///from   ww  w . j  a  v a  2  s  . co m
public String[] getValues() {
    ChosenImpl impl = getChosenImpl();

    if (impl != null) {
        List<String> selectedValues = impl.getSelectedValues();
        return selectedValues.toArray(new String[selectedValues.size()]);
    } else {
        JsArrayString values = JsArrayString.createArray().cast();
        NodeList<OptionElement> options = SelectElement.as(getElement()).getOptions();
        for (int i = 0; i < options.getLength(); i++) {
            OptionElement option = options.getItem(i);
            if (option.isSelected()) {
                values.push(option.getValue());
            }
        }

        String[] result = new String[values.length()];
        for (int i = 0; i < values.length(); i++) {
            result[i] = values.get(i);
        }

        return result;
    }
}

From source file:com.arcbees.chosen.client.SelectParser.java

License:Apache License

private void addOption(OptionElement option, int groupPosition, boolean groupDisabled) {
    String optionText = option.getText();

    OptionItem item = new OptionItem();
    item.arrayIndex = parsed.size();/*from   w ww.j  a  va2  s . c  om*/
    item.optionsIndex = optionsIndex;

    if (optionText != null && optionText.length() > 0) {

        if (groupPosition != -1) {
            ((GroupItem) parsed.get(groupPosition)).children++;
        }

        item.value = option.getValue();

        item.text = option.getLabel();
        if (isNullOrEmpty(item.text)) {
            item.text = option.getText();
        }

        item.html = option.getInnerHTML();
        item.selected = option.isSelected();
        item.disabled = groupDisabled ? groupDisabled : option.isDisabled();
        item.groupArrayIndex = groupPosition;
        item.classes = option.getClassName();
        item.style = getCssText(option.getStyle());
        item.empty = false;

    } else {
        item.empty = true;
        item.groupArrayIndex = -1;
    }

    parsed.add(item);
    optionsIndex++;
}

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

License:Apache License

@Override
public boolean isItemSelected(int index) {
    OptionElement option = getOption(index);
    return (option != null) ? option.isSelected() : false;
}

From source file:com.watopi.chosen.client.SelectParser.java

License:Open Source License

private void addOption(OptionElement option, int groupPosition, boolean groupDisabled) {
    String optionText = option.getText();

    OptionItem item = new OptionItem();
    item.arrayIndex = parsed.length();/*from  www . j  a  va 2 s.  com*/
    item.optionsIndex = optionsIndex;

    if (optionText != null && optionText.length() > 0) {

        if (groupPosition != -1) {
            ((GroupItem) parsed.get(groupPosition)).children++;
        }

        item.value = option.getValue();
        item.text = option.getText();
        item.html = option.getInnerHTML();
        item.selected = option.isSelected();
        item.disabled = groupDisabled ? groupDisabled : option.isDisabled();
        item.groupArrayIndex = groupPosition;
        item.classes = option.getClassName();
        item.style = getCssText(option.getStyle());
        item.empty = false;

    } else {
        item.empty = true;
        item.groupArrayIndex = -1;

    }

    parsed.add(item);
    optionsIndex++;
}

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

License:Apache License

/**
 * Return the values of all selected options in an array.
 * Usefull to know which options are selected in case of multiple ChosenListBox
 * @return//from   w  w w .j a  v a2 s.c  o m
 */
public String[] getValues() {
    if (!isMultipleSelect()) {
        return new String[] { getValue() };
    }

    JsArrayString values = JsArrayString.createArray().cast();
    NodeList<OptionElement> options = SelectElement.as(getElement()).getOptions();
    for (int i = 0; i < options.getLength(); i++) {
        OptionElement option = options.getItem(i);
        if (option.isSelected()) {
            values.push(option.getValue());
        }
    }

    String[] result = new String[values.length()];
    for (int i = 0; i < values.length(); i++) {
        result[i] = values.get(i);
    }

    return result;
}