Search in sources :

Example 21 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class StateNodeTest method collectChanges_initiallyActiveElement_sendOnlyDisalowFeatureChangesWhenInactive.

@Test
public void collectChanges_initiallyActiveElement_sendOnlyDisalowFeatureChangesWhenInactive() {
    StateNode stateNode = createTestNode("Active node", ElementPropertyMap.class, ElementData.class);
    ElementData visibility = stateNode.getFeature(ElementData.class);
    ElementPropertyMap properties = stateNode.getFeature(ElementPropertyMap.class);
    TestStateTree tree = new TestStateTree();
    // attach the node to be able to get changes
    tree.getRootNode().getFeature(ElementChildrenList.class).add(0, stateNode);
    assertCollectChanges_initiallyVisible(stateNode, properties, isVisible -> {
        visibility.setVisible(isVisible);
        stateNode.updateActiveState();
    });
}
Also used : ElementChildrenList(com.vaadin.flow.internal.nodefeature.ElementChildrenList) ElementData(com.vaadin.flow.internal.nodefeature.ElementData) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 22 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class PolymerTemplate method filterUnsetProperties.

private JsonArray filterUnsetProperties(List<String> properties) {
    JsonArray array = Json.createArray();
    ElementPropertyMap map = getStateNode().getFeature(ElementPropertyMap.class);
    int i = 0;
    for (String property : properties) {
        if (!map.hasProperty(property)) {
            array.set(i, property);
            i++;
        }
    }
    return array;
}
Also used : JsonArray(elemental.json.JsonArray) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap)

Example 23 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap 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 24 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class BeanModelTypeTest method modelToApplication.

@Test
public void modelToApplication() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    ElementPropertyMap model = createEmptyModel();
    model.setProperty("string", "3");
    model.setProperty("intValue", Integer.valueOf(3));
    Bean bean = beanType.modelToApplication(model.getNode());
    Assert.assertEquals("3", bean.getString());
    Assert.assertEquals(3, bean.getIntValue());
    Assert.assertNull(bean.getIntObject());
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 25 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class BeanModelTypeTest method importBean_withImportFilter.

@Test
public void importBean_withImportFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    ElementPropertyMap model = createEmptyModel();
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, new PropertyFilter(name -> "intObject".equals(name)));
    Assert.assertEquals(1, model.getPropertyNames().count());
    Assert.assertEquals(Integer.valueOf(3), model.getProperty("intObject"));
}
Also used : HashSet(java.util.HashSet) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Arrays(java.util.Arrays) List(java.util.List) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Map(java.util.Map) JsonCodec(com.vaadin.flow.internal.JsonCodec) Json(elemental.json.Json) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Aggregations

ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)45 Test (org.junit.Test)35 StateNode (com.vaadin.flow.internal.StateNode)21 HashSet (java.util.HashSet)9 Element (com.vaadin.flow.dom.Element)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)6 Json (elemental.json.Json)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Assert (org.junit.Assert)6 ElementChildrenList (com.vaadin.flow.internal.nodefeature.ElementChildrenList)5 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)5 JsonObject (elemental.json.JsonObject)5 Serializable (java.io.Serializable)5 Arrays (java.util.Arrays)5 UI (com.vaadin.flow.component.UI)4 JsonCodec (com.vaadin.flow.internal.JsonCodec)4 JsonArray (elemental.json.JsonArray)4