Search in sources :

Example 91 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class ElementUtilTest method setupElementHierarchy.

private void setupElementHierarchy() {
    parent = ElementFactory.createDiv();
    child = ElementFactory.createDiv();
    grandchild = ElementFactory.createDiv();
    parent.appendChild(child.appendChild(grandchild));
    stateTree = new StateTree(new UI().getInternals(), ElementChildrenList.class, InertData.class);
    final StateNode rootNode = stateTree.getRootNode();
    rootNode.getFeature(ElementChildrenList.class).add(0, parent.getNode());
}
Also used : StateTree(com.vaadin.flow.internal.StateTree) UI(com.vaadin.flow.component.UI) ElementChildrenList(com.vaadin.flow.internal.nodefeature.ElementChildrenList) StateNode(com.vaadin.flow.internal.StateNode) InertData(com.vaadin.flow.internal.nodefeature.InertData)

Example 92 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class ElementTest method getElementFromInvalidNode.

@Test(expected = IllegalArgumentException.class)
public void getElementFromInvalidNode() {
    StateNode node = new StateNode(ElementPropertyMap.class);
    Element.get(node);
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test) ElementListenersTest(com.vaadin.flow.internal.nodefeature.ElementListenersTest)

Example 93 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class ShadowRootStateProviderTest method createShadowRootNode_originalNodeIsInitialized.

@Test
public void createShadowRootNode_originalNodeIsInitialized() {
    ShadowRootStateProvider provider = ShadowRootStateProvider.get();
    StateNode node = new StateNode(ShadowRootData.class);
    StateNode shadowRoot = provider.createShadowRootNode(node);
    Assert.assertEquals(shadowRoot, node.getFeature(ShadowRootData.class).getShadowRoot());
}
Also used : ShadowRootStateProvider(com.vaadin.flow.dom.impl.ShadowRootStateProvider) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 94 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class PolymerTemplate method removeSimpleProperties.

private List<String> removeSimpleProperties() {
    ElementPropertyMap map = getStateNode().getFeature(ElementPropertyMap.class);
    List<String> props = map.getPropertyNames().filter(name -> !(map.getProperty(name) instanceof StateNode)).collect(Collectors.toList());
    props.forEach(map::removeProperty);
    return props;
}
Also used : BeanModelType(com.vaadin.flow.templatemodel.BeanModelType) ListModelType(com.vaadin.flow.templatemodel.ListModelType) StateNode(com.vaadin.flow.internal.StateNode) Component(com.vaadin.flow.component.Component) TemplateModel(com.vaadin.flow.templatemodel.TemplateModel) Json(elemental.json.Json) Set(java.util.Set) JsonArray(elemental.json.JsonArray) ModelDescriptor(com.vaadin.flow.templatemodel.ModelDescriptor) Collectors(java.util.stream.Collectors) TemplateModelProxyHandler(com.vaadin.flow.templatemodel.TemplateModelProxyHandler) HashSet(java.util.HashSet) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) List(java.util.List) Tag(com.vaadin.flow.component.Tag) ModelType(com.vaadin.flow.templatemodel.ModelType) Stream(java.util.stream.Stream) Type(java.lang.reflect.Type) Map(java.util.Map) Element(com.vaadin.flow.dom.Element) Entry(java.util.Map.Entry) HasComponents(com.vaadin.flow.component.HasComponents) Collections(java.util.Collections) StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap)

Example 95 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class TemplateElementStateProvider method getChild.

@Override
public Element getChild(StateNode node, int index) {
    int templateChildCount = templateNode.getChildCount();
    if (templateChildCount == 0) {
        // No children according to the template, could still have an
        // override node with children
        Optional<StateNode> overrideNode = getOverrideNode(node);
        if (overrideNode.isPresent()) {
            return BasicElementStateProvider.get().getChild(overrideNode.get(), index);
        }
    }
    int currentChildIndex = 0;
    for (int i = 0; i < templateChildCount; i++) {
        TemplateNode templateChild = templateNode.getChild(i);
        int generateCount = templateChild.getGeneratedElementCount(node);
        int indexInChild = index - currentChildIndex;
        if (indexInChild < generateCount) {
            return templateChild.getElement(indexInChild, node);
        }
        currentChildIndex += generateCount;
    }
    throw new IndexOutOfBoundsException();
}
Also used : ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) StateNode(com.vaadin.flow.internal.StateNode)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)196 Test (org.junit.Test)122 Element (com.vaadin.flow.dom.Element)32 JsonObject (elemental.json.JsonObject)24 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)22 UI (com.vaadin.flow.component.UI)19 StateTree (com.vaadin.flow.internal.StateTree)18 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ArrayList (java.util.ArrayList)18 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)17 Serializable (java.io.Serializable)17 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)9 VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9