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

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

Introduction

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

Prototype

public void setValue(String value) 

Source Link

Document

The current form control value.

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./*w w w.j av  a2s .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.arcbees.chosen.client.gwt.ChosenListBox.java

License:Apache License

/**
 * Inserts an item into a group at the specified location. Additionally, the item can have an extra class name as
 * well as indent level assigned to it.//  w  ww  .j  av  a 2s  .c o m
 * <p/>
 * <b>NB!</b> It is important to set text into the option after the option has been appended to the DOM
 * <br/>that's known bug in IE  @see <a href="http://bugs.jquery.com/ticket/3041">jQuery bug tracker</a>
 * <p/>
 *
 * @param item        the item label to display
 * @param value       the value of the item in the HTML form context
 * @param className   the class name to append to the option (pass {@code null} to append no class name)
 * @param dir         allows specifying an RTL, LTR or inherited direction ({@code null} is LTR)
 * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation)
 * @param groupIndex  the index of the group to insert the item into (if out of bounds, the last group will be used)
 * @param itemIndex   the index of the item within a group (if out of bounds, item will be placed last in the group)
 */
public void insertStyledItemToGroup(String item, String value, String className, Direction dir, int indentLevel,
        int groupIndex, int itemIndex) {
    int pos = groupIndex;
    if (indentLevel < 0) {
        throw new IllegalArgumentException("[indentLevel] must be non-negative.");
    }
    GQuery optgroupList = $(OPTGROUP_TAG, getElement());

    int groupCount = optgroupList.size();

    if (groupCount == 0) {
        // simply insert the item to the listbox
        insertItem(item, dir, value, itemIndex);
        return;
    }

    if (pos < 0 || pos > groupCount - 1) {
        pos = groupCount - 1;
    }

    GQuery optgroup = optgroupList.eq(pos);

    OptionElement option = Document.get().createOptionElement();

    if (!(className == null || className.trim().isEmpty())) {
        option.addClassName(className);
    }
    if (indentLevel > 0) {
        // Calculate total indentation, not forgetting that being in a group is adding one extra indent step
        int leftPadding = options.getResources().css().indent() * (indentLevel + 1);
        option.setAttribute("style", "padding-left: " + leftPadding + "px;");
    }

    Element optGroupElement = optgroup.get(0);
    int itemCount = optGroupElement.getChildCount();

    if (itemIndex < 0 || itemIndex > itemCount - 1) {
        optgroup.append(option);
    } else {
        GQuery before = $(optGroupElement.getChild(itemIndex));
        before.before(option);
    }
    // setText must be after the element has been appended to the DOM - see javadoc
    setOptionText(option, item, dir);
    option.setValue(value);
}

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/*from w  ww.j  a va  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 setValue(int index, String value) {
    OptionElement option = getOption(index);
    option.setValue(value);
}

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);/*  w ww  . ja  v  a 2 s .c o  m*/
    option.setInnerText(item);
    option.setValue(value);
    return option;
}

From source file:com.uni.hs13.visupoll.client.OptGroupListBox.java

License:Apache License

/**
 * Adds a new OPTION item to the ListBox. If the <em>key</em> of this item already exists, the
 * item will <strong>not</strong> be created (existing <em>label</em> is fine, though). Otherwise
 * it will be added to the last created OPTGROUP item. If no OPTGROUP item exists, the OPTION item
 * will be created without a OPTGROUP parent item.
 * //from   ww  w.j  a v  a  2s .  com
 * @param key the key of the OPTION item
 * @param label the label of the OPTION item
 * @return {@code true}, if the key of the item does not already exist, otherwise {@code false}.
 */
public boolean addGroupItem(final String key, final String label) {
    // check if this item already exists
    SelectElement selectElement = this.getElement().cast();
    NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*");

    for (int i = 0; i < elementsByTagName.getLength(); i++) {
        Element item = elementsByTagName.getItem(i);

        if (OptGroupListBoxItemType.OPTION.getItemNodeName().equals(item.getNodeName())) {
            OptionElement castedElement = (OptionElement) item;
            if (castedElement.getValue().equals(key)) {
                return false;
            }
        }
    }

    // okay, it does not already exist... create it
    if (latestOptGroupElement == null) {
        this.addItem(label, key);
    } else {
        OptionElement optElement = Document.get().createOptionElement();
        optElement.setInnerText(label);
        optElement.setValue(key);
        latestOptGroupElement.appendChild(optElement);
    }
    return true;
}

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

License:Open Source License

/**
 * Adds an item to the an optgroup of the list box. If no optgroup exists,
 * the item will be add at the end ot the list box.
 * //from w  ww .j  av a 2  s .  c  om
 * @param item
 *            the text of the item to be added
 * @param value
 *            the value of the item to be added
 * @param itemIndex
 *            the index inside the optgroup at which to insert the item
 * @param groupIndex
 *            the index of the optGroup where the item will be inserted
 */
public void insertItemToGroup(String item, Direction dir, String value, int groupIndex, int itemIndex) {

    GQuery select = $(getElement());
    GQuery optgroupList = select.children("optgroup");

    int groupCount = optgroupList.size();

    if (groupCount == 0) {
        // simply insert the item to the listbox
        insertItem(item, dir, value, itemIndex);
        return;
    }

    if (groupIndex < 0 || groupIndex > groupCount - 1) {
        groupIndex = groupCount - 1;
    }

    GQuery optgroup = optgroupList.eq(groupIndex);

    OptionElement option = Document.get().createOptionElement();
    setOptionText(option, item, dir);
    option.setValue(value);

    int itemCount = optgroup.children().size();

    if (itemIndex < 0 || itemIndex > itemCount - 1) {
        optgroup.append(option);
    } else {
        GQuery before = optgroup.children().eq(itemIndex);
        before.before(option);
    }

}

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);//from w ww.  jav a2  s.c  om
    option.setValue(value);
    option.setClassName(styleName);

    select.add(option, null);
}

From source file:org.gwtbootstrap3.extras.tagsinput.client.ui.MVTagsInput.java

License:Apache License

@Override
public void add(String tag) {
    if (isAttached())
        super.add(tag);
    else {/* w  ww.  j  av  a 2 s  .  com*/
        OptionElement option = Document.get().createOptionElement();
        option.setValue(tag);
        option.setInnerText(tag);
        getElement().appendChild(option);
    }
}

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);// w  w w. ja  va2s . c om
    option.setValue(value);
    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);
    }
}