use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ModelDescriptorTest method assertComplexModeType.
private <T extends Serializable> void assertComplexModeType(Class<T> clazz, T wrappedValue, T value) {
Optional<ComplexModelType<?>> type = BasicComplexModelType.get(clazz);
StateNode stateNode = type.get().applicationToModel(wrappedValue, null);
Assert.assertEquals(wrappedValue, stateNode.getFeature(BasicTypeValue.class).getValue());
stateNode.getFeature(BasicTypeValue.class).setValue(value);
Object modelValue = type.get().modelToApplication(stateNode);
Assert.assertEquals(value, modelValue);
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ModelDescriptorTest method basicComplexModelType_intAndInteger_numberFromClient.
@Test
public void basicComplexModelType_intAndInteger_numberFromClient() {
ComplexModelType<?> type = BasicComplexModelType.get(Integer.class).get();
StateNode stateNode = type.applicationToModel(2.0d, null);
Object applicationValue = type.modelToApplication(stateNode);
Assert.assertEquals(Integer.valueOf(2), applicationValue);
}
use of com.vaadin.flow.internal.StateNode 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 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);
ElementPropertyMap modelMap = ElementPropertyMap.getModel(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.StateNode in project flow by vaadin.
the class BeanModelTypeTest method applicationToModel.
@Test
public void applicationToModel() {
BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
Bean bean = new Bean(3);
StateNode applicationToModel = beanType.applicationToModel(bean, PropertyFilter.ACCEPT_ALL);
ElementPropertyMap model = ElementPropertyMap.getModel(applicationToModel);
assertThreeBean(model);
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class TemplateModelTest method beanModelType_emptySubBeanAsInitialValue.
@Test
public void beanModelType_emptySubBeanAsInitialValue() {
SubBeansTemplate template = new SubBeansTemplate();
// Check that even before calling any model method the properties are
// available via features
Serializable bean = template.getElement().getNode().getFeature(ElementPropertyMap.class).getProperty("bean");
StateNode node = (StateNode) bean;
Serializable subBean = node.getFeature(ElementPropertyMap.class).getProperty("bean");
assertTrue(subBean instanceof StateNode);
// Now check properties via API
Assert.assertNotNull(template.getModel().getBean().getBean());
}
Aggregations