Search in sources :

Example 36 with NodeMap

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

the class GwtTemplateBinderTest method testServerEventHandlerInNgFor.

public void testServerEventHandlerInNgFor() {
    TestElementTemplateNode parent = TestElementTemplateNode.create("div");
    String operation = "operation";
    // ============= create <li *ngFor> ===============================
    String collectionVar = "items";
    TestForTemplateNode templateNode = TestTemplateNode.create(ForTemplateNode.TYPE);
    int templateId = 42;
    registry.getTemplateRegistry().register(templateId, templateNode);
    TestElementTemplateNode forChild = TestElementTemplateNode.create("li");
    templateNode.setCollectionVariable(collectionVar);
    forChild.addEventHandler("click", "$server." + operation + "()");
    int forChildId = 11;
    registry.getTemplateRegistry().register(forChildId, forChild);
    templateNode.setChildrenIds(new double[] { forChildId });
    parent.setChildrenIds(new double[] { templateId });
    NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    MapProperty property = model.getProperty(collectionVar);
    StateNode modelNode = new StateNode(1, tree);
    property.setValue(modelNode);
    // ================== now modelNode is NG FOR model node ==========
    StateNode varNode = new StateNode(2, tree);
    com.vaadin.client.flow.nodefeature.NodeList modelList = modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST);
    // add one item to the "collection" model
    modelList.add(0, varNode);
    stateNode.getList(NodeFeatures.CLIENT_DELEGATE_HANDLERS).set(0, operation);
    Element element = createElement(parent);
    Reactive.flush();
    MouseEvent event = (MouseEvent) Browser.getDocument().createEvent(Events.MOUSE);
    event.initMouseEvent("click", true, true, Browser.getWindow(), 0, 0, 0, 0, 0, false, false, false, false, 0, element);
    Browser.getDocument().getBody().appendChild(element);
    element.getElementsByTagName("li").item(0).dispatchEvent(event);
    assertEquals(1, serverMethods.size());
    assertNotNull(serverMethods.get(operation));
    assertEquals(stateNode.getId(), serverRpcNodes.get(operation).getId());
}
Also used : MouseEvent(elemental.events.MouseEvent) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 37 with NodeMap

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

the class GwtTemplateBinderTest method testBindOverrideNode_properties_beforeBind.

public void testBindOverrideNode_properties_beforeBind() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    int id = 83;
    StateNode overrideNode = createSimpleOverrideNode(id);
    NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    props.getProperty("foo").setValue("bar");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    assertEquals("bar", WidgetUtil.getJsProperty(element, "foo"));
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 38 with NodeMap

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

the class GwtTemplateBinderTest method testUpdateTextValueTemplate.

public void testUpdateTextValueTemplate() {
    TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY));
    NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    map.getProperty(MODEL_KEY).setValue("foo");
    Node domNode = createText(templateNode);
    Reactive.flush();
    map.getProperty(MODEL_KEY).setValue("bar");
    Reactive.flush();
    assertEquals("bar", domNode.getTextContent());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) ChildSlotNode(com.vaadin.flow.template.angular.ChildSlotNode) Node(elemental.dom.Node) ForTemplateNode(com.vaadin.flow.template.angular.ForTemplateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 39 with NodeMap

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

the class GwtTemplateBinderTest method testBindOverrideNode_attributes_beforeBind.

public void testBindOverrideNode_attributes_beforeBind() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    int id = 48;
    StateNode overrideNode = createSimpleOverrideNode(id);
    NodeMap attrs = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
    attrs.getProperty("foo").setValue("bar");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    assertEquals("bar", element.getAttribute("foo"));
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 40 with NodeMap

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

the class GwtTemplateBinderTest method testTextValueTemplate.

public void testTextValueTemplate() {
    TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY));
    NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    map.getProperty(MODEL_KEY).setValue("foo");
    Node domNode = createText(templateNode);
    Reactive.flush();
    assertEquals("foo", domNode.getTextContent());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) ChildSlotNode(com.vaadin.flow.template.angular.ChildSlotNode) Node(elemental.dom.Node) ForTemplateNode(com.vaadin.flow.template.angular.ForTemplateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Aggregations

NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)68 StateNode (com.vaadin.client.flow.StateNode)30 Element (elemental.dom.Element)21 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)20 Node (elemental.dom.Node)14 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)10 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)10 JsonObject (elemental.json.JsonObject)8 Test (org.junit.Test)6 DomElement (com.vaadin.client.flow.dom.DomElement)5 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)4 NodeList (com.vaadin.client.flow.nodefeature.NodeList)4 DomNode (com.vaadin.client.flow.dom.DomNode)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 Computation (com.vaadin.client.flow.reactive.Computation)3 NativeFunction (com.vaadin.client.flow.util.NativeFunction)3 JsonValue (elemental.json.JsonValue)3 Command (com.vaadin.client.Command)2 ConstantPool (com.vaadin.client.flow.ConstantPool)2 JsArray (com.vaadin.client.flow.collection.JsArray)2