Search in sources :

Example 26 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class StateTreeTest method sendNodePropertySyncToServer_nodeDetached_propertyNotIsSent.

@Test
public void sendNodePropertySyncToServer_nodeDetached_propertyNotIsSent() {
    tree.registerNode(node);
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty property = new MapProperty("foo", map);
    property.setValue("bar");
    connector.clear();
    tree.unregisterNode(node);
    tree.sendNodePropertySyncToServer(property);
    connector.assertMessage(null, null, null);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Example 27 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class TreeChangeProcessorTest method testMapReAdd.

@Test
public void testMapReAdd() {
    MapProperty property = tree.getRootNode().getMap(ns).getProperty(myKey);
    property.setValue(myValue);
    JsonObject change = removeChange(rootId, ns, myKey);
    TreeChangeProcessor.processChange(tree, change);
    StateNode child = new StateNode(2, tree);
    tree.registerNode(child);
    change = putNodeChange(rootId, ns, myKey, child.getId());
    StateNode node = TreeChangeProcessor.processChange(tree, change);
    Assert.assertSame(child, property.getValue());
    Assert.assertEquals(tree.getRootNode(), node);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 28 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class InitialPropertiesHandlerTest method flushPropertyUpdates_updateIsNotInProgress_collectInitialProperties.

@Test
public void flushPropertyUpdates_updateIsNotInProgress_collectInitialProperties() {
    Mockito.when(tree.isUpdateInProgress()).thenReturn(false);
    StateNode node = new StateNode(1, tree);
    NodeMap properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty serverSidePropertyUpdatedByClient = properties.getProperty("foo");
    serverSidePropertyUpdatedByClient.setValue("bar");
    MapProperty serverSideProperty = properties.getProperty("other");
    serverSideProperty.setValue("value");
    handler.nodeRegistered(node);
    Mockito.when(tree.getNode(node.getId())).thenReturn(node);
    handler.flushPropertyUpdates();
    serverSidePropertyUpdatedByClient.setValue("updated");
    MapProperty clientSideProperty = properties.getProperty("client");
    clientSideProperty.setValue("baz");
    handler.handlePropertyUpdate(serverSidePropertyUpdatedByClient);
    handler.handlePropertyUpdate(clientSideProperty);
    Reactive.flush();
    Assert.assertEquals("bar", properties.getProperty("foo").getValue());
    Assert.assertEquals("value", properties.getProperty("other").getValue());
    Assert.assertEquals("baz", properties.getProperty("client").getValue());
    Mockito.verify(tree, Mockito.times(0)).sendNodePropertySyncToServer(serverSidePropertyUpdatedByClient);
    Mockito.verify(tree, Mockito.times(0)).sendNodePropertySyncToServer(serverSideProperty);
    Mockito.verify(tree).sendNodePropertySyncToServer(clientSideProperty);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Example 29 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class LoadingIndicatorConfigurator method bindInteger.

/**
 * Binds change events for the property identified by the given key in the
 * given feature to the given setter.
 *
 * @param map
 *            the map containing the property
 * @param key
 *            the key of the property
 * @param setter
 *            the setter to invoke when the value changes
 * @param defaultValue
 *            the value to use if the property value is removed
 */
private static void bindInteger(NodeMap map, String key, Consumer<Integer> setter, int defaultValue) {
    MapProperty property = map.getProperty(key);
    property.addChangeListener(e -> setter.accept(e.getSource().getValueOrDefault(defaultValue)));
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty)

Example 30 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class PolymerUtils method createModelTree.

/**
 * Makes an attempt to convert an object into json.
 *
 * @param object
 *            the object to convert to json
 * @return json from object, {@code null} for null
 */
public static JsonValue createModelTree(Object object) {
    if (object instanceof StateNode) {
        StateNode node = (StateNode) object;
        NodeFeature feature = null;
        if (node.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
            feature = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
        } else if (node.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
            feature = node.getList(NodeFeatures.TEMPLATE_MODELLIST);
        } else if (node.hasFeature(NodeFeatures.BASIC_TYPE_VALUE)) {
            return createModelTree(node.getMap(NodeFeatures.BASIC_TYPE_VALUE).getProperty(NodeProperties.VALUE));
        }
        assert feature != null : "Don't know how to convert node without map or list features";
        JsonValue convert = feature.convert(PolymerUtils::createModelTree);
        if (convert instanceof JsonObject && !((JsonObject) convert).hasKey("nodeId")) {
            ((JsonObject) convert).put("nodeId", node.getId());
            registerChangeHandlers(node, feature, convert);
        }
        return convert;
    } else if (object instanceof MapProperty) {
        MapProperty property = (MapProperty) object;
        if (property.getMap().getId() == NodeFeatures.BASIC_TYPE_VALUE) {
            return createModelTree(property.getValue());
        } else {
            JsonObject convertedObject = Json.createObject();
            convertedObject.put(property.getName(), createModelTree(property.getValue()));
            return convertedObject;
        }
    } else {
        return WidgetUtil.crazyJsoCast(object);
    }
}
Also used : NodeFeature(com.vaadin.client.flow.nodefeature.NodeFeature) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject)

Aggregations

MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)40 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)18 StateNode (com.vaadin.client.flow.StateNode)12 Test (org.junit.Test)8 Element (elemental.dom.Element)7 JsonObject (elemental.json.JsonObject)6 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)5 JsonValue (elemental.json.JsonValue)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)2 SchedulerImpl (com.google.gwt.core.client.impl.SchedulerImpl)1 Computation (com.vaadin.client.flow.reactive.Computation)1 FlushListener (com.vaadin.client.flow.reactive.FlushListener)1 Node (elemental.dom.Node)1 NodeList (elemental.dom.NodeList)1 Text (elemental.dom.Text)1 EventRemover (elemental.events.EventRemover)1 MouseEvent (elemental.events.MouseEvent)1 JsonArray (elemental.json.JsonArray)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1