Search in sources :

Example 21 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class GwtPropertyElementBinderTest method gwtSetUp.

@Override
protected void gwtSetUp() throws Exception {
    super.gwtSetUp();
    Reactive.reset();
    constantPool = new ConstantPool();
    tree = new CollectingStateTree(constantPool, new ExistingElementMap());
    node = createNode();
    properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    synchronizedPropertyList = new NodeList(0, node);
    element = Browser.getDocument().createElement("div");
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList) ExistingElementMap(com.vaadin.client.ExistingElementMap)

Example 22 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class PolymerUtils method getListNotificationPath.

private static String getListNotificationPath(StateNode currentNode) {
    int indexInTheList = -1;
    NodeList children = currentNode.getParent().getList(NodeFeatures.TEMPLATE_MODELLIST);
    for (int i = 0; i < children.length(); i++) {
        Object object = children.get(i);
        if (currentNode.equals(object)) {
            indexInTheList = i;
            break;
        }
    }
    if (indexInTheList < 0) {
        return null;
    }
    return String.valueOf(indexInTheList);
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList) JsonObject(elemental.json.JsonObject)

Example 23 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class TreeChangeProcessor method processClearChange.

private static void processClearChange(JsonObject change, StateNode node) {
    int nsId = (int) change.getNumber(JsonConstants.CHANGE_FEATURE);
    NodeList list = node.getList(nsId);
    list.clear();
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Example 24 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class ServerEventHandlerBinder method bindServerEventHandlerNames.

/**
 * Registers all the server event handler names found in the feature with
 * the {@code featureId} in the {@link ServerEventObject} {@code object}.
 * Additionally listens to changes in the feature and updates server event
 * object accordingly.
 *
 * @param objectProvider
 *            the provider of the event object to update
 * @param node
 *            the state node containing the feature
 * @param featureId
 *            the feature id which contains event handler methods
 * @param returnValue
 *            <code>true</code> if the handler should return a promise that
 *            will reflect the server-side result; <code>false</code> to not
 *            return any value
 * @return a handle which can be used to remove the listener for the feature
 */
public static EventRemover bindServerEventHandlerNames(Supplier<ServerEventObject> objectProvider, StateNode node, int featureId, boolean returnValue) {
    NodeList serverEventHandlerNamesList = node.getList(featureId);
    if (serverEventHandlerNamesList.length() > 0) {
        ServerEventObject object = objectProvider.get();
        for (int i = 0; i < serverEventHandlerNamesList.length(); i++) {
            String serverEventHandlerName = (String) serverEventHandlerNamesList.get(i);
            object.defineMethod(serverEventHandlerName, node, returnValue);
        }
    }
    return serverEventHandlerNamesList.addSpliceListener(e -> {
        ServerEventObject serverObject = objectProvider.get();
        JsArray<?> remove = e.getRemove();
        for (int i = 0; i < remove.length(); i++) {
            serverObject.removeMethod((String) remove.get(i));
        }
        JsArray<?> add = e.getAdd();
        for (int i = 0; i < add.length(); i++) {
            serverObject.defineMethod((String) add.get(i), node, returnValue);
        }
    });
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Example 25 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class GwtBasicElementBinderTest method testVirtualChild.

public void testVirtualChild() {
    Binder.bind(node, element);
    StateNode childNode = createChildNode("child");
    NodeMap elementData = childNode.getMap(NodeFeatures.ELEMENT_DATA);
    JsonObject object = Json.createObject();
    object.put(NodeProperties.TYPE, NodeProperties.IN_MEMORY_CHILD);
    elementData.getProperty(NodeProperties.PAYLOAD).setValue(object);
    NodeList virtialChildren = node.getList(NodeFeatures.VIRTUAL_CHILDREN);
    virtialChildren.add(0, childNode);
    Reactive.flush();
    assertEquals(element.getChildElementCount(), 0);
    Element childElement = (Element) childNode.getDomNode();
    assertEquals("SPAN", childElement.getTagName());
    assertEquals("child", childElement.getId());
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList) Element(elemental.dom.Element) JsonObject(elemental.json.JsonObject) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Aggregations

NodeList (com.vaadin.client.flow.nodefeature.NodeList)25 JsonObject (elemental.json.JsonObject)9 StateNode (com.vaadin.client.flow.StateNode)7 Node (elemental.dom.Node)5 ExistingElementMap (com.vaadin.client.ExistingElementMap)3 DomNode (com.vaadin.client.flow.dom.DomNode)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)3 Element (elemental.dom.Element)3 JsonArray (elemental.json.JsonArray)3 Test (org.junit.Test)3 JsArray (com.vaadin.client.flow.collection.JsArray)2 EventRemover (elemental.events.EventRemover)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsCollections (com.vaadin.client.flow.collection.JsCollections)1 JsMap (com.vaadin.client.flow.collection.JsMap)1 JsSet (com.vaadin.client.flow.collection.JsSet)1 JsWeakMap (com.vaadin.client.flow.collection.JsWeakMap)1 DomApi (com.vaadin.client.flow.dom.DomApi)1 DomTokenList (com.vaadin.client.flow.dom.DomElement.DomTokenList)1