Search in sources :

Example 1 with DataGenerator

use of com.vaadin.flow.data.provider.DataGenerator in project flow-components by vaadin.

the class LitRenderer method render.

/**
 * Sets up rendering of model objects inside a given {@param container}
 * element. The model objects are rendered using the Lit template literal
 * provided when creating this LitRenderer instance, and a given
 * {@param rendererName} JS renderer function.
 *
 * @param container
 *            the DOM element that supports setting a renderer function
 * @param keyMapper
 *            mapper used internally to fetch items by key and to provide
 *            keys for given items. It is required when either functions or
 *            {@link DataGenerator} are supported
 * @param rendererName
 *            name of the renderer function the container element accepts
 * @return the context of the rendering, that can be used by the components
 *         to provide extra customization
 */
public Rendering<SOURCE> render(Element container, DataKeyMapper<SOURCE> keyMapper, String rendererName) {
    DataGenerator<SOURCE> dataGenerator = createDataGenerator();
    Registration registration = createJsRendererFunction(container, keyMapper, rendererName);
    return new Rendering<SOURCE>() {

        @Override
        public Optional<DataGenerator<SOURCE>> getDataGenerator() {
            return Optional.of(dataGenerator);
        }

        @Override
        public Element getTemplateElement() {
            return null;
        }

        @Override
        public Registration getRegistration() {
            return registration;
        }
    };
}
Also used : Registration(com.vaadin.flow.shared.Registration) ReturnChannelRegistration(com.vaadin.flow.internal.nodefeature.ReturnChannelRegistration) DataGenerator(com.vaadin.flow.data.provider.DataGenerator)

Aggregations

DataGenerator (com.vaadin.flow.data.provider.DataGenerator)1 ReturnChannelRegistration (com.vaadin.flow.internal.nodefeature.ReturnChannelRegistration)1 Registration (com.vaadin.flow.shared.Registration)1