Search in sources :

Example 6 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class PolymerTemplateTest method assertAnotherTemplateInitialization.

private void assertAnotherTemplateInitialization(AnotherTemplateInitialization template) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    assertEquals(2, feature.size());
    Optional<Component> child = com.vaadin.flow.dom.Element.get(feature.get(0)).getComponent();
    Assert.assertTrue(child.isPresent());
    Assert.assertEquals(TemplateChild.class, child.get().getClass());
    child = com.vaadin.flow.dom.Element.get(feature.get(1)).getComponent();
    Assert.assertTrue(child.isPresent());
    Assert.assertEquals(TestPolymerTemplate.class, child.get().getClass());
}
Also used : VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList) Component(com.vaadin.flow.component.Component)

Example 7 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class PolymerTemplateTest method attachComponentAndVerifyChild.

private void attachComponentAndVerifyChild(PolymerTemplate<?> template, CustomComponent templateChild) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    List<StateNode> templateNodes = new ArrayList<>();
    feature.forEachChild(templateNodes::add);
    assertEquals(1, templateNodes.size());
    StateNode child = templateNodes.get(0);
    String tag = child.getFeature(ElementData.class).getTag();
    assertEquals("div", tag);
    assertNotNull(templateChild);
    assertEquals(child, templateChild.getElement().getNode());
    assertTrue(templateChild.getElement().getComponent().isPresent());
    assertTrue(templateChild.getElement().getComponent().get() instanceof CustomComponent);
    assertEquals(templateChild, templateChild.getElement().getComponent().get());
    assertElementData(child, NodeProperties.INJECT_BY_ID, "child");
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) ElementData(com.vaadin.flow.internal.nodefeature.ElementData) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 8 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class PolymerTemplateTest method assertTemplateInitialization.

private void assertTemplateInitialization(TemplateInitialization template) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    assertEquals(2, feature.size());
    Optional<Component> child = com.vaadin.flow.dom.Element.get(feature.get(0)).getComponent();
    Assert.assertTrue(child.isPresent());
    Assert.assertEquals(TestPolymerTemplate.class, child.get().getClass());
    child = com.vaadin.flow.dom.Element.get(feature.get(1)).getComponent();
    Assert.assertTrue(child.isPresent());
    Assert.assertEquals(TemplateChild.class, child.get().getClass());
}
Also used : VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList) Component(com.vaadin.flow.component.Component)

Example 9 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class TemplateInitializer method attachExistingElementById.

/**
 * Attaches a child element with the given {@code tagName} and {@code id} to
 * an existing dom element on the client side with matching data.
 *
 * @param tagName
 *            tag name of element, not {@code null}
 * @param id
 *            id of element to attach to
 * @param field
 *            field to attach {@code Element} or {@code Component} to
 */
private void attachExistingElementById(String tagName, String id, Field field) {
    if (tagName == null) {
        throw new IllegalArgumentException("Tag name parameter cannot be null");
    }
    Element element = registeredElementIdToInjected.get(id);
    if (element == null) {
        element = new Element(tagName);
        VirtualChildrenList list = getElement().getNode().getFeature(VirtualChildrenList.class);
        list.append(element.getNode(), NodeProperties.INJECT_BY_ID, id);
        registeredElementIdToInjected.put(id, element);
    }
    injectTemplateElement(element, field);
}
Also used : Element(com.vaadin.flow.dom.Element) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 10 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class PolymerTemplateTest method doParseTemplate_hasIdChild_childIsRegisteredInFeature.

private void doParseTemplate_hasIdChild_childIsRegisteredInFeature(IdChildTemplate template) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    assertEquals(1, feature.size());
}
Also used : VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Aggregations

VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)11 StateNode (com.vaadin.flow.internal.StateNode)5 ArrayList (java.util.ArrayList)5 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)3 Component (com.vaadin.flow.component.Component)2 Element (com.vaadin.flow.dom.Element)2 Test (org.junit.Test)2 UI (com.vaadin.flow.component.UI)1 JsonArray (elemental.json.JsonArray)1 JsonObject (elemental.json.JsonObject)1