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

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

Introduction

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

Prototype

@Override
    public NodeList<Element> getElementsByTagName(String name) 

Source Link

Usage

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

License:Apache License

/**
 * Adds a new OPTGROUP item to the ListBox. If the name of the group already exists, the group
 * item will <strong>not</strong> be created.
 * /*from  w ww. j  a v  a2 s .  c om*/
 * @param groupName The name of the group.
 * @return {@code true}, if the name does not already exist, otherwise {@code false}.
 */
public boolean addGroup(final String groupName) {
    // check if this group 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.GROUP.getItemNodeName().equals(item.getNodeName())) {
            OptGroupElement castedElement = (OptGroupElement) item;
            if (castedElement.getLabel().equals(groupName)) {
                return false;
            }
        }
    }

    // okay, it does not already exist... create it
    OptGroupElement groupElement = Document.get().createOptGroupElement();
    groupElement.setLabel(groupName);
    SelectElement select = this.getElement().cast();
    select.appendChild(groupElement);
    latestOptGroupElement = groupElement;
    return true;
}

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.
 * //  w w  w .ja  v a  2s  .  co m
 * @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.uni.hs13.visupoll.client.OptGroupListBox.java

License:Apache License

/**
 * Removes an item at the given index from the ListBox. The index starts at 0.
 * /*  w  w w.j  a  v a2  s  .c  o m*/
 * @param index See description.
 * @return {@code true}, if an item with the given index was found (and removed), otherwise
 *         {@code false}.
 */
public boolean removeItemAtIndex(int index) {
    SelectElement selectElement = this.getElement().cast();
    NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*");
    Element item = elementsByTagName.getItem(index);

    if (item == null) {
        return false;
    }
    item.removeFromParent();

    return true;
}

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

License:Apache License

/**
 * Removes an item with the given key from the ListBox.
 * /*from   www  .  j a  v a 2 s . c o  m*/
 * @param type One of the two types defined in {@link OptGroupListBoxItemType}, namely a
 *          <em>group</em> or a <em>group item</em>.
 * @param key If <em>type</em> is a <em>group item</em>, then <em>key</em> has to be the unique
 *          key of the ListBox element. If <em>type</em> is a <em>group</em>, then <em>key</em>
 *          has to be the label of this group. Pay attention here, as group labels may be present
 *          multiple times (non-unique). This methods only deletes the first occurrence of the
 *          <em>group item</em>.
 * @return {@code true}, if an item with the given key was found (and removed), otherwise
 *         {@code false}.
 */
public boolean removeItemWithKey(OptGroupListBoxItemType type, String key) {
    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.equals(type)
                && OptGroupListBoxItemType.OPTION.getItemNodeName().equals(item.getNodeName())
                && ((OptionElement) item).getValue().equals(key))
                || (OptGroupListBoxItemType.GROUP.equals(type)
                        && OptGroupListBoxItemType.GROUP.getItemNodeName().equals(item.getNodeName())
                        && ((OptGroupElement) item).getLabel().equals(key))) {
            item.removeFromParent();
            return true;
        }
    }

    return false;
}

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

License:Apache License

/**
 * Returns the size of this ListBox, namely the count of elements, including group-elements.
 * /* w w w  .j  a  va 2  s  . com*/
 * @return See description.
 */
public int getSize() {
    SelectElement selectElement = this.getElement().cast();
    NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*");

    return elementsByTagName.getLength();
}