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