use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.
the class TreeChangeProcessor method processPutChange.
private static void processPutChange(JsonObject change, StateNode node) {
MapProperty property = findProperty(change, node);
if (change.hasKey(JsonConstants.CHANGE_PUT_VALUE)) {
JsonValue jsonValue = change.get(JsonConstants.CHANGE_PUT_VALUE);
Object value = ClientJsonCodec.decodeWithoutTypeInfo(jsonValue);
property.setValue(value);
} else if (change.hasKey(JsonConstants.CHANGE_PUT_NODE_VALUE)) {
int childId = (int) change.getNumber(JsonConstants.CHANGE_PUT_NODE_VALUE);
StateNode child = node.getTree().getNode(childId);
assert child != null;
child.setParent(node);
property.setValue(child);
} else {
assert false : "Change should have either value or nodeValue property: " + WidgetUtil.stringify(change);
}
}
use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.
the class TreeChangeProcessor method processRemoveChange.
private static void processRemoveChange(JsonObject change, StateNode node) {
MapProperty property = findProperty(change, node);
property.removeValue();
}
use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.
the class GwtBasicElementBinderTest method testBindVirtualChild_withCorrespondingElementInShadowRoot_byId.
public void testBindVirtualChild_withCorrespondingElementInShadowRoot_byId() {
Element shadowRootElement = addShadowRootElement(element);
String childId = "childElement";
StateNode childNode = createChildNode(childId, element.getTagName());
NodeMap properties = childNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
MapProperty fooProperty = properties.getProperty("foo");
fooProperty.setValue("bar");
Binder.bind(node, element);
addVirtualChild(node, childNode, NodeProperties.INJECT_BY_ID, Json.create(childId));
Element addressedElement = createAndAppendElementToShadowRoot(shadowRootElement, childId, element.getTagName());
List<Integer> expectedAfterBindingFeatures = Arrays.asList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS, NodeFeatures.ELEMENT_CHILDREN);
expectedAfterBindingFeatures.forEach(notExpectedFeature -> assertFalse("Child node should not have any features from list " + expectedAfterBindingFeatures + " before binding, but got feature " + notExpectedFeature, childNode.hasFeature(notExpectedFeature)));
Reactive.flush();
expectedAfterBindingFeatures.forEach(expectedFeature -> assertTrue("Child node should have all features from list " + expectedAfterBindingFeatures + " before binding, but missing feature " + expectedFeature, childNode.hasFeature(expectedFeature)));
// nothing has changed: no new child
assertEquals("No new child should be added to the element after attach", 0, element.getChildElementCount());
assertEquals("No new child should be added to the shadow root after attach", 1, shadowRootElement.getChildElementCount());
Element childElement = shadowRootElement.getFirstElementChild();
assertSame("Existing element should be the same as element in the StateNode object", addressedElement, childElement);
}
use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.
the class GwtBasicElementBinderTest method setVisible.
private void setVisible(boolean visible) {
NodeMap map = node.getMap(NodeFeatures.ELEMENT_DATA);
MapProperty visibility = map.getProperty(NodeProperties.VISIBLE);
visibility.setValue(visible);
}
use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.
the class SimpleElementBindingStrategy method handlePropertyChange.
private void handlePropertyChange(String fullPropertyName, Supplier<Object> valueProvider, StateNode node) {
UpdatableModelProperties updatableProperties = node.getNodeData(UpdatableModelProperties.class);
if (updatableProperties == null || !updatableProperties.isUpdatableProperty(fullPropertyName)) {
// collection of updatable properties
return;
}
// This is not the property value itself, its a parent node of the
// property
String[] subProperties = fullPropertyName.split("\\.");
StateNode model = node;
MapProperty mapProperty = null;
int i = 0;
int size = subProperties.length;
for (String subProperty : subProperties) {
NodeMap elementProperties = model.getMap(NodeFeatures.ELEMENT_PROPERTIES);
if (!elementProperties.hasPropertyValue(subProperty) && i < size - 1) {
Console.debug("Ignoring property change for property '" + fullPropertyName + "' which isn't defined from server");
return;
}
mapProperty = elementProperties.getProperty(subProperty);
if (mapProperty.getValue() instanceof StateNode) {
model = (StateNode) mapProperty.getValue();
}
i++;
}
if (mapProperty.getValue() instanceof StateNode) {
// Don't send to the server updates for list nodes
StateNode nodeValue = (StateNode) mapProperty.getValue();
JsonObject obj = WidgetUtil.crazyJsCast(valueProvider.get());
if (!obj.hasKey("nodeId") || nodeValue.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
return;
}
}
mapProperty.syncToServer(valueProvider.get());
}
Aggregations