use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class TemplateModelUtil method resolveListAndRun.
/**
* Resolves a list model type and a model list based on a model instance and
* passes those to the provided callback.
*
* @param <R>
* the return value type
* @param model
* the model instance for which to resolve a type and a list, not
* <code>null</code>
* @param modelPath
* the model path to resolve, not <code>null</code>
* @param callback
* the callback to run with the resolved list type and model
* list, not <code>null</code>
* @return the value returned by the callback
*/
public static <R> R resolveListAndRun(TemplateModel model, String modelPath, BiFunction<ListModelType<?>, ModelList, R> callback) {
assert model != null;
assert modelPath != null;
assert callback != null;
BeanModelType<?> modelType = TemplateModelProxyHandler.getModelTypeForProxy(model);
ModelType listType = modelType.resolveType(modelPath);
if (listType instanceof ListModelType<?>) {
StateNode stateNode = TemplateModelProxyHandler.getStateNodeForProxy(model);
ModelMap modelMap = ModelMap.get(stateNode);
ModelList modelList = modelMap.resolveModelList(modelPath);
return callback.apply((ListModelType<?>) listType, modelList);
} else {
throw new IllegalArgumentException(modelPath + " does not resolve to a list");
}
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class BeanModelTypeTest method importBean_withTypeFilter.
@Test
public void importBean_withTypeFilter() {
BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> "intValue".equals(name)));
ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
Bean bean = new Bean(3);
beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
Assert.assertEquals(1, model.getKeys().count());
Assert.assertEquals(Integer.valueOf(3), model.getValue("intValue"));
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class BeanModelTypeTest method importBean_differentBean.
@Test
public void importBean_differentBean() {
BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
DifferentBean bean = new DifferentBean(3);
// Ignore intValue which has an incompatible type
beanType.importProperties(model, bean, new PropertyFilter(name -> !"intValue".equals(name)));
Assert.assertEquals(1, model.getKeys().count());
Assert.assertEquals("3", model.getValue("string"));
Assert.assertFalse(model.hasValue("date"));
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class BeanModelTypeTest method applicationToModel.
@Test
public void applicationToModel() {
BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
Bean bean = new Bean(3);
StateNode applicationToModel = beanType.applicationToModel(bean, PropertyFilter.ACCEPT_ALL);
ModelMap model = ModelMap.get(applicationToModel);
assertThreeBean(model);
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class TemplateModelTest method setModelPropertyAndVerifyGetter.
private void setModelPropertyAndVerifyGetter(AngularTemplate template, Supplier<Object> getter, String beanPath, String property, Serializable expected) {
ModelMap feature = getModelMap(template, beanPath);
feature.setValue(property, expected);
Assert.assertEquals(expected, getter.get());
}
Aggregations