Example usage for com.google.gwt.dom.client Element getNodeName

List of usage examples for com.google.gwt.dom.client Element getNodeName

Introduction

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

Prototype

@Override
    public String getNodeName() 

Source Link

Usage

From source file:asquare.gwt.tk.client.util.impl.DomUtilImplIE6.java

License:Apache License

@Override
public void clean(Element element) {
    String elementName = element.getNodeName();
    if ("TR".equals(elementName) || "TABLE".equalsIgnoreCase(elementName)
            || "TBODY".equalsIgnoreCase(elementName)) {
        Node firstChild;/*from  ww  w.  j  a  v  a2 s . com*/
        while ((firstChild = element.getFirstChild()) != null) {
            element.removeChild(firstChild);
        }
    } else {
        super.clean(element);
    }
}

From source file:com.allen_sauer.gwt.dnd.client.util.DOMUtil.java

License:Apache License

/**
 * Determine an element's node name via the <code>nodeName</code> property.
 * /*from  ww w  .  j ava  2s  . com*/
 * @param elem the element whose node name is to be determined
 * @return the element's node name
 */
public static String getNodeName(Element elem) {
    return elem.getNodeName();
}

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

License:Apache License

private void addNode(Node child) {
    if (!Element.is(child)) {
        return;/*  w  w w .  j a va2  s.  c o m*/
    }

    Element e = Element.as(child);

    if ("OPTGROUP".equalsIgnoreCase(e.getNodeName())) {
        addGroup(OptGroupElement.as(e));
    } else if ("OPTION".equalsIgnoreCase(e.getNodeName())) {
        addOption(OptionElement.as(e), -1, false);
    }
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private JsNodeArray getNotPseudo(JsNodeArray previousMatch, String pseudoValue, JsNodeArray matchingElms) {
    if (new JsRegexp("(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
        matchingElms = subtractArray(previousMatch,
                getElementsByPseudo(previousMatch, pseudoValue.substring(1), ""));
    } else {/* w ww. java  2 s .  c  o m*/
        pseudoValue = pseudoValue.replace("^\\[#([\\w\\u00C0-\\uFFFF\\-\\_]+)\\]$", "[id=$1]");
        JsObjectArray<String> notTag = new JsRegexp("^(\\w+)").exec(pseudoValue);
        JsObjectArray<String> notClass = new JsRegexp("^\\.([\\w\u00C0-\uFFFF\\-_]+)").exec(pseudoValue);
        JsObjectArray<String> notAttr = new JsRegexp(
                "\\[(\\w+)(\\^|\\$|\\*|\\||~)?=?([\\w\\u00C0-\\uFFFF\\s\\-_\\.]+)?\\]").exec(pseudoValue);
        JsRegexp notRegExp = new JsRegexp("(^|\\s)"
                + (JsUtils.truth(notTag) ? notTag.get(1) : JsUtils.truth(notClass) ? notClass.get(1) : "")
                + "(\\s|$)", "i");
        if (JsUtils.truth(notAttr)) {
            String notAttribute = JsUtils.truth(notAttr.get(3)) ? notAttr.get(3).replace("\\.", "\\.") : null;
            String notMatchingAttrVal = attrToRegExp(notAttribute, notAttr.get(2));
            notRegExp = new JsRegexp(notMatchingAttrVal, "i");
        }
        for (int v = 0, vlen = previousMatch.size(); v < vlen; v++) {
            Element notElm = previousMatch.getElement(v);
            Element addElm = null;
            if (JsUtils.truth(notTag) && !notRegExp.test(notElm.getNodeName())) {
                addElm = notElm;
            } else if (JsUtils.truth(notClass) && !notRegExp.test(notElm.getClassName())) {
                addElm = notElm;
            } else if (JsUtils.truth(notAttr)) {
                String att = getAttr(notElm, notAttr.get(1));
                if (!JsUtils.truth(att) || !notRegExp.test(att)) {
                    addElm = notElm;
                }
            }
            if (JsUtils.truth(addElm) && !isAdded(addElm)) {
                setAdded(addElm, true);
                matchingElms.addNode(addElm);
            }
        }
    }
    return matchingElms;
}

From source file:com.gwtm.ui.client.widgets.CheckBoxGroup.java

License:Apache License

@Override
public void onClick(ClickEvent e) {
    final EventTarget target = e.getNativeEvent().getEventTarget();
    String targetTagName = ((Element) target.cast()).getTagName().toUpperCase();
    Utils.Console("onClick target " + targetTagName);
    if (targetTagName.equals("LABEL")) {
        return; // if check box label is click, another (simulated) click event with
        // check box INPUT as target will fire after this one. So this click event
        // can be safely ignored.
    }/* w ww . j  ava  2 s .  com*/
    Element div = Element.as(target);
    while (!div.getNodeName().toUpperCase().equals("SPAN") || div.getParentElement() != this.getElement()) {
        div = div.getParentElement();
        if (div == null) {
            Utils.Console("CheckBoxGroup onClick: span not found");
            return;
        }
    }
    final int index = DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) div);
    com.google.gwt.user.client.ui.CheckBox checkbox = (com.google.gwt.user.client.ui.CheckBox) getWidget(index);
    Utils.Console("onClick " + checkbox.getValue());
    if (targetTagName.equals("INPUT")) {
        Utils.Console("onClick value changed");
        checkbox.setValue(checkbox.getValue()); // if target is check box INPUT, check box value is 
        // already changed when click event is fired.
        // just need to set its current value back to the check box
        // to update style.
    } else {
        checkbox.setValue(!checkbox.getValue());
    }

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            //            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(index, target);
            //            fireEvent(selectionChangedEvent);
            ValueChangeEvent.fire(CheckBoxGroup.this, index);
        }
    });
}

From source file:com.gwtmobile.ui.client.utils.Utils.java

License:Apache License

public static boolean isHtmlFormControl(com.google.gwt.dom.client.Element ele) {
    if (ele == null) {
        return false;
    }/* ww w  .j ava  2  s  . com*/
    String FromControls = "BUTTON INPUT SELECT TEXTAREA";
    String nodeName = ele.getNodeName().toUpperCase();
    String roleName = ele.getAttribute("role").toUpperCase();
    return FromControls.contains(nodeName) || roleName.length() > 0 && FromControls.contains(roleName)
            || isHtmlFormControl(ele.getParentElement());
}

From source file:com.gwtmobile.ui.client.widgets.CheckBoxGroup.java

License:Apache License

@Override
public void onClick(ClickEvent e) {
    final EventTarget target = e.getNativeEvent().getEventTarget();
    String targetTagName = ((Element) target.cast()).getTagName().toUpperCase();
    Utils.Console("onClick target " + targetTagName);
    if (targetTagName.equals("LABEL")) {
        return; // if check box label is click, another (simulated) click event with
        // check box INPUT as target will fire after this one. So this click event
        // can be safely ignored.
    }//from   w  w  w . j  ava  2s.  c o  m
    Element div = Element.as(target);
    while (!div.getNodeName().toUpperCase().equals("SPAN") || div.getParentElement() != this.getElement()) {
        div = div.getParentElement();
        if (div == null) {
            Utils.Console("CheckBoxGroup onClick: span not found");
            return;
        }
    }
    final int index = DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) div);
    com.google.gwt.user.client.ui.CheckBox checkbox = (com.google.gwt.user.client.ui.CheckBox) getWidget(index);
    Utils.Console("onClick " + checkbox.getValue());
    if (targetTagName.equals("INPUT")) {
        Utils.Console("onClick value changed");
        checkbox.setValue(checkbox.getValue()); // if target is check box INPUT, check box value is 
        // already changed when click event is fired.
        // just need to set its current value back to the check box
        // to update style.
    } else {
        checkbox.setValue(!checkbox.getValue());
    }

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(index, target);
            fireEvent(selectionChangedEvent);
        }
    });
}

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.
 * //  w ww  . ja  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.
 * //from w  w w .  j  av a2s .  c  o  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 with the given key from the ListBox.
 * /*from  w w  w  .j a va2 s  .com*/
 * @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;
}