use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsPropertyValueOfStateNode_propertySetToNode.
@Test
public void syncJSON_jsonIsPropertyValueOfStateNode_propertySetToNode() throws Exception {
// Let's use element's ElementPropertyMap for testing.
TestComponent component = new TestComponent();
Element element = component.getElement();
UI ui = new UI();
ui.add(component);
StateNode node = element.getNode();
// Set model value directly via ElementPropertyMap
ElementPropertyMap propertyMap = node.getFeature(ElementPropertyMap.class);
propertyMap.setUpdateFromClientFilter(name -> true);
ElementPropertyMap modelMap = propertyMap.resolveModelMap("foo");
// fake StateNode has been created for the model
StateNode model = modelMap.getNode();
modelMap.setProperty("bar", "baz");
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", model.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, "foo", json);
Serializable testPropertyValue = propertyMap.getProperty("foo");
Assert.assertTrue(testPropertyValue instanceof StateNode);
StateNode newNode = (StateNode) testPropertyValue;
Assert.assertSame(model, newNode);
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class MapSyncRpcHandler method tryCopyStateNode.
private Serializable tryCopyStateNode(StateNode node, JsonObject properties) {
if (node == null) {
return properties;
}
// Copy only if the request is for a node inside a list
if (isInList(node)) {
StateNode copy = new StateNode(node);
ElementPropertyMap originalProperties = node.getFeature(ElementPropertyMap.class);
ElementPropertyMap copyProperties = copy.getFeature(ElementPropertyMap.class);
originalProperties.getPropertyNames().forEach(property -> copyProperties.setProperty(property, originalProperties.getProperty(property)));
return copy;
}
if (isProperty(node)) {
return node;
}
return properties;
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class MapSyncRpcHandlerTest method noSyncPropertiesFeature_noExplicitAllow_throws.
@Test(expected = IllegalArgumentException.class)
public void noSyncPropertiesFeature_noExplicitAllow_throws() {
StateNode noSyncProperties = new StateNode(ElementPropertyMap.class);
ElementPropertyMap map = noSyncProperties.getFeature(ElementPropertyMap.class);
new MapSyncRpcHandler().handleNode(noSyncProperties, createSyncPropertyInvocation(noSyncProperties, TEST_PROPERTY, NEW_VALUE));
Assert.assertEquals(NEW_VALUE, map.getProperty(TEST_PROPERTY));
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class StateNodeTest method collectChanges_initiallyInactiveElement_sendOnlyDisalowAndReportedFeatures_sendAllChangesWhenActive.
@Test
public void collectChanges_initiallyInactiveElement_sendOnlyDisalowAndReportedFeatures_sendAllChangesWhenActive() {
Element element = ElementFactory.createAnchor();
StateNode stateNode = element.getNode();
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_initiallyInactive(stateNode, properties, isVisible -> {
visibility.setVisible(isVisible);
stateNode.updateActiveState();
});
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class StateNodeTest method collectChanges_initiallyInactiveViaParentElement_sendOnlyDisalowAndReportedFeatures_sendAllChangesWhenActive.
@Test
public void collectChanges_initiallyInactiveViaParentElement_sendOnlyDisalowAndReportedFeatures_sendAllChangesWhenActive() {
Element element = ElementFactory.createAnchor();
StateNode stateNode = element.getNode();
StateNode parent = createTestNode("Parent node", ElementPropertyMap.class, ElementData.class, ElementChildrenList.class);
parent.getFeature(ElementChildrenList.class).add(0, stateNode);
ElementData visibility = parent.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, parent);
assertCollectChanges_initiallyInactive(stateNode, properties, isVisible -> {
visibility.setVisible(isVisible);
parent.updateActiveState();
});
}
Aggregations