Search in sources :

Example 46 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class TemplateElementStateProviderTest method setAttribute_regularAttribute_hasAttributeAndHasProperValue.

@Test
public void setAttribute_regularAttribute_hasAttributeAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("attr", "foo");
    Assert.assertTrue(element.hasAttribute("attr"));
    Assert.assertEquals("foo", element.getAttribute("attr"));
    List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
    Assert.assertEquals(1, attrs.size());
    Assert.assertEquals("attr", attrs.get(0));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 47 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class TemplateElementStateProviderTest method removeProperty_regularProperty_elementDelegatesPropertyToOverrideNode.

@Test
public void removeProperty_regularProperty_elementDelegatesPropertyToOverrideNode() {
    TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("prop", "foo");
    element.removeProperty("prop");
    StateNode overrideNode = element.getNode().getFeature(TemplateOverridesMap.class).get(node, false);
    Assert.assertFalse(BasicElementStateProvider.get().hasProperty(overrideNode, "prop"));
    List<String> props = BasicElementStateProvider.get().getPropertyNames(overrideNode).collect(Collectors.toList());
    Assert.assertEquals(0, props.size());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TemplateOverridesMap(com.vaadin.flow.internal.nodefeature.TemplateOverridesMap) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 48 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class TemplateMap method setChild.

/**
 * Sets the root node of the element that occupies the <code>@child@</code>
 * slot in this template.
 *
 * @param child
 *            the state node of the element to put in the child slot, or
 *            <code>null</code> to remove the current child
 */
public void setChild(StateNode child) {
    TemplateNode rootTemplate = getRootTemplate();
    if (rootTemplate == null) {
        throw new IllegalStateException(TemplateMap.class.getSimpleName() + " must be initialized using setRootTemplate before using this method.");
    }
    Optional<ChildSlotNode> maybeSlot = ChildSlotNode.find(rootTemplate);
    if (!maybeSlot.isPresent()) {
        throw new IllegalStateException("AngularTemplate has no child slot");
    }
    ChildSlotNode childTemplateNode = maybeSlot.get();
    // Reset bookkeeping for old child
    getChild().ifPresent(oldChild -> {
        ParentGeneratorHolder oldParentGeneratorHolder = oldChild.getFeature(ParentGeneratorHolder.class);
        assert oldParentGeneratorHolder.getParentGenerator().get() == childTemplateNode;
        oldParentGeneratorHolder.setParentGenerator(null);
    });
    put(CHILD_SLOT_CONTENT, child);
    // Update bookkeeping for finding the parent of the new child
    if (child != null) {
        ParentGeneratorHolder parentGeneratorHolder = child.getFeature(ParentGeneratorHolder.class);
        assert !parentGeneratorHolder.getParentGenerator().isPresent();
        parentGeneratorHolder.setParentGenerator(childTemplateNode);
    }
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) ChildSlotNode(com.vaadin.flow.template.angular.ChildSlotNode)

Aggregations

TemplateNode (com.vaadin.flow.template.angular.TemplateNode)48 Test (org.junit.Test)42 Element (com.vaadin.flow.dom.Element)29 StateNode (com.vaadin.flow.internal.StateNode)18 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)13 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)12 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)11 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)4 HashMap (java.util.HashMap)4 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)3 TemplateMap (com.vaadin.flow.internal.nodefeature.TemplateMap)2 Component (com.vaadin.flow.component.Component)1 UIInternals (com.vaadin.flow.component.internal.UIInternals)1 StateTree (com.vaadin.flow.internal.StateTree)1 MapPutChange (com.vaadin.flow.internal.change.MapPutChange)1 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)1 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)1 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)1 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)1 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)1