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