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());
}
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");
}
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());
}
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);
}
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());
}
Aggregations