Java Code Examples for com.google.gwt.dom.client.Node#getNodeType()

The following examples show how to use com.google.gwt.dom.client.Node#getNodeType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMMutationExtractor.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Handles DOM mutation events.
 * @param event
 * @param contentRange  last known selection
 */
public void handleDOMMutation(SignalEvent event, ContentRange contentRange) {
  // Early exit if non-safari or non-mac
  if (!(UserAgent.isSafari() && UserAgent.isMac())) {
    return;
  }

  // We don't care about DOMMutations that we generate while we are reverting.
  if (isReverting) {
    return;
  }

  previousContentRange = contentRange;

  Node n = event.getTarget();
  if (n.getNodeType() == Node.ELEMENT_NODE) {
    Element e = Element.as(event.getTarget());
    if (DOM_EVENTS_IGNORE.contains(event.getType())) {
      // ignore
      return;
    } else if (event.getType().equals("DOMNodeInserted") && handleDOMNodeInserted(e)) {
      return;
    } else if (event.getType().equals("DOMNodeRemoved") && handleDOMNodeRemoved(e)) {
      return;
    }
  }
  return;
}
 
Example 2
Source File: DOMMutationExtractor.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Handles DOM mutation events.
 * @param event
 * @param contentRange  last known selection
 */
public void handleDOMMutation(SignalEvent event, ContentRange contentRange) {
  // Early exit if non-safari or non-mac
  if (!(UserAgent.isSafari() && UserAgent.isMac())) {
    return;
  }

  // We don't care about DOMMutations that we generate while we are reverting.
  if (isReverting) {
    return;
  }

  previousContentRange = contentRange;

  Node n = event.getTarget();
  if (n.getNodeType() == Node.ELEMENT_NODE) {
    Element e = Element.as(event.getTarget());
    if (DOM_EVENTS_IGNORE.contains(event.getType())) {
      // ignore
      return;
    } else if (event.getType().equals("DOMNodeInserted") && handleDOMNodeInserted(e)) {
      return;
    } else if (event.getType().equals("DOMNodeRemoved") && handleDOMNodeRemoved(e)) {
      return;
    }
  }
  return;
}
 
Example 3
Source File: Header.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void highlight(String name)
{
    toggleSubnavigation(name);

    com.google.gwt.user.client.Element target = linksPane.getElementById("header-links-ref");
    if(target!=null) // TODO: i think this cannot happen, does it?
    {
        NodeList<Node> childNodes = target.getChildNodes();
        for(int i=0; i<childNodes.getLength(); i++)
        {
            Node n = childNodes.getItem(i);
            if(Node.ELEMENT_NODE == n.getNodeType())
            {
                Element element = (Element) n;
                if(element.getId().equals("header-"+name))
                {
                    element.addClassName("header-link-selected");
                    element.setAttribute("aria-selected", "true");
                }
                else {
                    element.removeClassName("header-link-selected");
                    element.setAttribute("aria-selected", "false");
                }
            }
        }
    }
}
 
Example 4
Source File: DomHelper.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if it is an element
 */
public static boolean isElement(Node n) {
  return n.getNodeType() == Node.ELEMENT_NODE;
}
 
Example 5
Source File: DomHelper.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if it is a text node
 */
public static boolean isTextNode(Node n) {
  return n.getNodeType() == Node.TEXT_NODE;
}
 
Example 6
Source File: HtmlViewImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Element asElement(Node node) {
  return node.getNodeType() == Node.ELEMENT_NODE ? node.<Element>cast() : null;
}
 
Example 7
Source File: HtmlViewImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public short getNodeType(Node node) {
  return node.getNodeType();
}
 
Example 8
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if it is an element
 */
public static boolean isElement(Node n) {
  return n.getNodeType() == Node.ELEMENT_NODE;
}
 
Example 9
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if it is a text node
 */
public static boolean isTextNode(Node n) {
  return n.getNodeType() == Node.TEXT_NODE;
}
 
Example 10
Source File: HtmlViewImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Element asElement(Node node) {
  return node.getNodeType() == Node.ELEMENT_NODE ? node.<Element>cast() : null;
}
 
Example 11
Source File: HtmlViewImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public short getNodeType(Node node) {
  return node.getNodeType();
}
 
Example 12
Source File: DomHelper.java    From swellrt with Apache License 2.0 3 votes vote down vote up
/**
 * Checks whether the properties of given node cannot be accessed (by testing the nodeType).
 *
 * It is sometimes the case where we need to access properties of a Node, but the properties
 * on that node are not readable (for example, a shadow node like a div created to hold the
 * selection within an input field).
 *
 * In these cases, when the javascript cannot access the node's properties, any attempt to do
 * so may cause an internal permissions exception. This method swallows the exception and uses
 * its existence to indicate whether or not the node is actually readable.
 *
 * @param n Node to check
 * @return Whether or not the node can have properties read.
 */
public static boolean isUnreadable(Node n) {
  try {
    n.getNodeType();
    return false;
  } catch (RuntimeException e) {
    return true;
  }
}
 
Example 13
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 3 votes vote down vote up
/**
 * Checks whether the properties of given node cannot be accessed (by testing the nodeType).
 *
 * It is sometimes the case where we need to access properties of a Node, but the properties
 * on that node are not readable (for example, a shadow node like a div created to hold the
 * selection within an input field).
 *
 * In these cases, when the javascript cannot access the node's properties, any attempt to do
 * so may cause an internal permissions exception. This method swallows the exception and uses
 * its existence to indicate whether or not the node is actually readable.
 *
 * @param n Node to check
 * @return Whether or not the node can have properties read.
 */
public static boolean isUnreadable(Node n) {
  try {
    n.getNodeType();
    return false;
  } catch (RuntimeException e) {
    return true;
  }
}