use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class TemplateElementStateProviderTest method removeAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode.
@Test
public void removeAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode() {
TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
Element element = createElement(node);
element.setAttribute("attr", "foo");
element.removeAttribute("attr");
StateNode overrideNode = element.getNode().getFeature(TemplateOverridesMap.class).get(node, false);
Assert.assertFalse(BasicElementStateProvider.get().hasAttribute(overrideNode, "attr"));
List<String> attrs = BasicElementStateProvider.get().getAttributeNames(overrideNode).collect(Collectors.toList());
Assert.assertEquals(0, attrs.size());
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class BasicComplexModelType method applicationToModel.
@Override
public StateNode applicationToModel(Object applicationValue, PropertyFilter filter) {
if (applicationValue == null) {
return null;
}
assert applicationValue instanceof Serializable;
StateNode stateNode = new StateNode(Collections.singletonList(BasicTypeValue.class));
stateNode.getFeature(BasicTypeValue.class).setValue((Serializable) applicationValue);
return stateNode;
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class BeanModelType method applicationToModel.
@Override
public StateNode applicationToModel(Object applicationValue, PropertyFilter filter) {
if (applicationValue == null) {
return null;
}
StateNode node = new StateNode(Collections.singletonList(ElementPropertyMap.class));
importProperties(ElementPropertyMap.getModel(node), applicationValue, filter);
return node;
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class PolymerPublishedEventRpcHandler method getTemplateItem.
/**
* Get the template model object and type.
*
* @param template
* polymer template to get model from
* @param argValue
* argument value
* @param convertedType
* value type
* @return the provided model value
* @throws IllegalStateException
* if the component is not attached to the UI
*/
@Override
public Object getTemplateItem(Component template, JsonObject argValue, Type convertedType) {
final Optional<UI> ui = template.getUI();
if (ui.isPresent()) {
StateNode node = ui.get().getInternals().getStateTree().getNodeById((int) argValue.getNumber("nodeId"));
ModelType propertyType = ((PolymerTemplate<?>) template).getModelType(convertedType);
return propertyType.modelToApplication(node);
}
throw new IllegalArgumentException("Event sent for a non attached template component");
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ListModelType method importBeans.
/**
* Imports beans into a model list based on the properties in the item type
* of this model type.
*
* @param modelList
* the model list to import beans into
* @param beans
* the list of beans to import
* @param propertyFilter
* defines which properties from the item model type to import
*/
public void importBeans(ModelList modelList, List<T> beans, PropertyFilter propertyFilter) {
// Collect all child nodes before clearing anything
List<StateNode> childNodes = new ArrayList<>();
for (Object bean : beans) {
StateNode childNode = itemType.applicationToModel(bean, propertyFilter);
childNodes.add(childNode);
}
modelList.clear();
modelList.addAll(childNodes);
}
Aggregations