Search in sources :

Example 36 with StateNode

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

the class TemplateElementStateProviderTest method removeAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode.

@Test
public void removeAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode() {
    TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("attr", "foo");
    element.removeAttribute("attr");
    StateNode overrideNode = element.getNode().getFeature(TemplateOverridesMap.class).get(node, false);
    Assert.assertFalse(BasicElementStateProvider.get().hasAttribute(overrideNode, "attr"));
    List<String> attrs = BasicElementStateProvider.get().getAttributeNames(overrideNode).collect(Collectors.toList());
    Assert.assertEquals(0, attrs.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 37 with StateNode

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

the class BasicComplexModelType method applicationToModel.

@Override
public StateNode applicationToModel(Object applicationValue, PropertyFilter filter) {
    if (applicationValue == null) {
        return null;
    }
    assert applicationValue instanceof Serializable;
    StateNode stateNode = new StateNode(Collections.singletonList(BasicTypeValue.class));
    stateNode.getFeature(BasicTypeValue.class).setValue((Serializable) applicationValue);
    return stateNode;
}
Also used : Serializable(java.io.Serializable) StateNode(com.vaadin.flow.internal.StateNode) BasicTypeValue(com.vaadin.flow.internal.nodefeature.BasicTypeValue)

Example 38 with StateNode

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

the class BeanModelType method applicationToModel.

@Override
public StateNode applicationToModel(Object applicationValue, PropertyFilter filter) {
    if (applicationValue == null) {
        return null;
    }
    StateNode node = new StateNode(Collections.singletonList(ElementPropertyMap.class));
    importProperties(ElementPropertyMap.getModel(node), applicationValue, filter);
    return node;
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap)

Example 39 with StateNode

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

the class PolymerPublishedEventRpcHandler method getTemplateItem.

/**
 * Get the template model object and type.
 *
 * @param template
 *            polymer template to get model from
 * @param argValue
 *            argument value
 * @param convertedType
 *            value type
 * @return the provided model value
 * @throws IllegalStateException
 *             if the component is not attached to the UI
 */
@Override
public Object getTemplateItem(Component template, JsonObject argValue, Type convertedType) {
    final Optional<UI> ui = template.getUI();
    if (ui.isPresent()) {
        StateNode node = ui.get().getInternals().getStateTree().getNodeById((int) argValue.getNumber("nodeId"));
        ModelType propertyType = ((PolymerTemplate<?>) template).getModelType(convertedType);
        return propertyType.modelToApplication(node);
    }
    throw new IllegalArgumentException("Event sent for a non attached template component");
}
Also used : UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ModelType(com.vaadin.flow.templatemodel.ModelType) PolymerTemplate(com.vaadin.flow.component.polymertemplate.PolymerTemplate)

Example 40 with StateNode

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

the class ListModelType method importBeans.

/**
 * Imports beans into a model list based on the properties in the item type
 * of this model type.
 *
 * @param modelList
 *            the model list to import beans into
 * @param beans
 *            the list of beans to import
 * @param propertyFilter
 *            defines which properties from the item model type to import
 */
public void importBeans(ModelList modelList, List<T> beans, PropertyFilter propertyFilter) {
    // Collect all child nodes before clearing anything
    List<StateNode> childNodes = new ArrayList<>();
    for (Object bean : beans) {
        StateNode childNode = itemType.applicationToModel(bean, propertyFilter);
        childNodes.add(childNode);
    }
    modelList.clear();
    modelList.addAll(childNodes);
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList)

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