Java Code Examples for elemental.dom.Node#equals()

The following examples show how to use elemental.dom.Node#equals() . 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: SimpleElementBindingStrategy.java    From flow with Apache License 2.0 5 votes vote down vote up
private static Node getFirstNodeMappedAsStateNode(
        NodeList mappedNodeChildren, Node htmlNode) {

    JsArray<Node> clientList = DomApi.wrap(htmlNode).getChildNodes();
    for (int i = 0; i < clientList.length(); i++) {
        Node clientNode = clientList.get(i);
        for (int j = 0; j < mappedNodeChildren.length(); j++) {
            StateNode stateNode = (StateNode) mappedNodeChildren.get(j);
            if (clientNode.equals(stateNode.getDomNode())) {
                return clientNode;
            }
        }
    }
    return null;
}
 
Example 2
Source File: SimpleElementBindingStrategy.java    From flow with Apache License 2.0 4 votes vote down vote up
private boolean verifyAttachedElement(Element element, StateNode attachNode,
        String id, String address, BindingContext context) {
    StateNode node = context.node;
    String tag = getTag(attachNode);

    boolean failure = false;
    if (element == null) {
        failure = true;
        Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address
                + " is not found. The requested tag name is '" + tag + "'");
    } else if (!ElementUtil.hasTag(element, tag)) {
        failure = true;
        Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address
                + " has the wrong tag name '" + element.getTagName()
                + "', the requested tag name is '" + tag + "'");
    }

    if (failure) {
        node.getTree().sendExistingElementWithIdAttachToServer(node,
                attachNode.getId(), -1, id);
        return false;
    }

    if (!node.hasFeature(NodeFeatures.SHADOW_ROOT_DATA)) {
        return true;
    }
    NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
    StateNode shadowRootNode = (StateNode) map
            .getProperty(NodeProperties.SHADOW_ROOT).getValue();
    if (shadowRootNode == null) {
        return true;
    }

    NodeList list = shadowRootNode.getList(NodeFeatures.ELEMENT_CHILDREN);
    Integer existingId = null;

    for (int i = 0; i < list.length(); i++) {
        StateNode stateNode = (StateNode) list.get(i);
        Node domNode = stateNode.getDomNode();

        if (domNode.equals(element)) {
            existingId = stateNode.getId();
            break;
        }
    }

    if (existingId != null) {
        Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address
                + " has been already attached previously via the node id='"
                + existingId + "'");
        node.getTree().sendExistingElementWithIdAttachToServer(node,
                attachNode.getId(), existingId, id);
        return false;
    }
    return true;
}