use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class ModelMapTest method hasValue.
@Test
public void hasValue() {
ModelMap map = new ModelMap(new StateNode());
Assert.assertFalse(map.hasValue("foo"));
map.setValue("foo", "bar");
Assert.assertTrue(map.hasValue("foo"));
map.remove("foo");
Assert.assertFalse(map.hasValue("foo"));
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class ModelMapTest method getParentMapAndAssertMapping.
private ModelMap getParentMapAndAssertMapping(ModelList child, String childKey) {
assert child != null;
assert child.getNode() != null;
ModelMap parentMap = ModelMap.get(child.getNode().getParent());
assert parentMap != null;
Assert.assertEquals(child.getNode(), parentMap.getValue(childKey));
return parentMap;
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class ModelMapTest method resolveAndCreateSubSubChildList.
@Test
public void resolveAndCreateSubSubChildList() {
ModelList child = rootMap.resolveModelList("grand.parent.child");
ModelMap parent = getParentMapAndAssertMapping(child, "child");
ModelMap grand = getParentMapAndAssertMapping(parent, "parent");
ModelMap resolvedRoot = getParentMapAndAssertMapping(grand, "grand");
Assert.assertEquals(rootMap, resolvedRoot);
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class ForElementTemplateNodeTest method createModel.
@SuppressWarnings({ "unchecked" })
@SafeVarargs
private final StateNode createModel(Element templateRootElement, String key, Map<String, String>... map) {
StateNode modelList = new StateNode(new Class[] { ModelList.class });
for (Map<String, String> item : map) {
StateNode modelItem = TemplateElementStateProvider.createSubModelNode(ModelMap.class);
ModelMap modelItemMap = modelItem.getFeature(ModelMap.class);
for (String itemKey : item.keySet()) {
modelItemMap.setValue(itemKey, item.get(itemKey));
}
modelList.getFeature(ModelList.class).add(modelItem);
}
StateNode node = templateRootElement.getNode();
ModelMap.get(node).setValue(key, modelList);
return node;
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class TemplateModelProxyHandler method intercept.
/**
* Processes a method invocation on a Byte buddy proxy instance and returns
* the result. This method will be invoked on an invocation handler when a
* method is invoked on a proxy instance that it is associated with.
*
* @param target
* the proxy instance
* @param method
* the {@code Method} instance corresponding to the proxied
* method invoked on the proxy instance.
*
* @param args
* an array of objects containing the values of the arguments
* passed in the method invocation on the proxy instance.
* @return the value to return from the method invocation on the proxy
* instance.
*/
@RuntimeType
@SuppressWarnings("static-method")
public Object intercept(@This Object target, @Origin Method method, @AllArguments Object[] args) {
String propertyName = ReflectTools.getPropertyName(method);
BeanModelType<?> modelType = getModelTypeForProxy(target);
if (!modelType.hasProperty(propertyName)) {
throw new InvalidTemplateModelException(modelType.getProxyType().getName() + " has no property named " + propertyName + " (or it has been excluded)");
}
ModelType propertyType = modelType.getPropertyType(propertyName);
ModelMap modelMap = ModelMap.get(getStateNodeForProxy(target));
if (ReflectTools.isGetter(method)) {
return handleGetter(modelMap, propertyName, propertyType);
} else if (ReflectTools.isSetter(method)) {
Object value = args[0];
handleSetter(modelMap, propertyName, propertyType, value);
return null;
}
throw new InvalidTemplateModelException(getUnsupportedMethodMessage(method, args));
}
Aggregations