Search in sources :

Example 1 with PolymerTemplate

use of com.vaadin.flow.component.polymertemplate.PolymerTemplate 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");
}
Also used : UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ModelType(com.vaadin.flow.templatemodel.ModelType) PolymerTemplate(com.vaadin.flow.component.polymertemplate.PolymerTemplate)

Example 2 with PolymerTemplate

use of com.vaadin.flow.component.polymertemplate.PolymerTemplate in project flow by vaadin.

the class PolymerPublishedEventRpcHandlerTest method getTemplateItem.

public static 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 IllegalStateException("Event sent for a non attached template component");
}
Also used : UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ModelType(com.vaadin.flow.templatemodel.ModelType) PolymerTemplate(com.vaadin.flow.component.polymertemplate.PolymerTemplate)

Aggregations

UI (com.vaadin.flow.component.UI)2 PolymerTemplate (com.vaadin.flow.component.polymertemplate.PolymerTemplate)2 StateNode (com.vaadin.flow.internal.StateNode)2 ModelType (com.vaadin.flow.templatemodel.ModelType)2