Search in sources :

Example 1 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class Card method getSpacer.

private Element getSpacer() {
    Element spacer = ElementFactory.createDiv();
    spacer.getStyle().set("marginTop", "10px");
    return spacer;
}
Also used : Element(com.vaadin.flow.dom.Element)

Example 2 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class DataCommunicatorTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    ui = new MockUI();
    element = new Element("div");
    ui.getElement().appendChild(element);
    lastClear = null;
    lastSet = null;
    lastUpdateId = -1;
    update = new ArrayUpdater.Update() {

        @Override
        public void clear(int start, int length) {
            lastClear = Range.withLength(start, length);
        }

        @Override
        public void set(int start, List<JsonValue> items) {
            lastSet = Range.withLength(start, items.size());
        }

        @Override
        public void commit(int updateId) {
            lastUpdateId = updateId;
        }
    };
    Mockito.when(arrayUpdater.startUpdate(Mockito.anyInt())).thenReturn(update);
    dataCommunicator = new DataCommunicator<>(dataGenerator, arrayUpdater, data -> {
    }, element.getNode());
}
Also used : IntStream(java.util.stream.IntStream) VaadinSession(com.vaadin.flow.server.VaadinSession) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Mock(org.mockito.Mock) Test(org.junit.Test) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Mockito(org.mockito.Mockito) MockitoAnnotations(org.mockito.MockitoAnnotations) JsonValue(elemental.json.JsonValue) List(java.util.List) Lock(java.util.concurrent.locks.Lock) Stream(java.util.stream.Stream) Element(com.vaadin.flow.dom.Element) VaadinService(com.vaadin.flow.server.VaadinService) UI(com.vaadin.flow.component.UI) Assert(org.junit.Assert) Before(org.junit.Before) Range(com.vaadin.flow.internal.Range) Element(com.vaadin.flow.dom.Element) JsonValue(elemental.json.JsonValue) Before(org.junit.Before)

Example 3 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class AbstractComponentDataGenerator method registerRenderedComponent.

/**
 * Appends the component to the container and registers it for future use
 * during the lifecycle of the generator.
 *
 * @param itemKey
 *            the key of the model item
 * @param component
 *            the component to be attached to the container
 */
protected void registerRenderedComponent(String itemKey, Component component) {
    Element element = component.getElement();
    getContainer().appendChild(element);
    renderedComponents.put(itemKey, component);
}
Also used : Element(com.vaadin.flow.dom.Element)

Example 4 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class BasicRenderer method getTemplatePropertyName.

/**
 * Gets the name of the property to be transmitted and used inside the
 * template. By default, it generates a unique name by using the class name
 * of the renderer and the node id of the template element.
 * <p>
 * This method is only called when
 * {@link #render(Element, DataKeyMapper, Element)} is invoked.
 *
 * @param context
 *            the rendering context
 * @return the property name to be used in template data bindings
 *
 * @see Rendering#getTemplateElement()
 */
protected String getTemplatePropertyName(Rendering<SOURCE> context) {
    Objects.requireNonNull(context, "The context should not be null");
    Element templateElement = context.getTemplateElement();
    if (templateElement == null) {
        throw new IllegalArgumentException("The provided rendering doesn't contain a template element");
    }
    return "_" + getClass().getSimpleName() + "_" + templateElement.getNode().getId();
}
Also used : Element(com.vaadin.flow.dom.Element)

Example 5 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class BasicRenderer method setupTemplateWhenAttached.

private void setupTemplateWhenAttached(Element owner, SimpleValueRendering rendering, DataKeyMapper<SOURCE> keyMapper) {
    Element templateElement = rendering.getTemplateElement();
    owner.appendChild(templateElement);
    if (keyMapper != null) {
        String propertyName = getTemplatePropertyName(rendering);
        templateElement.setProperty("innerHTML", getTemplateForProperty("[[item." + propertyName + "]]", rendering));
        rendering.setPropertyName(propertyName);
        RendererUtil.registerEventHandlers(this, templateElement, owner, keyMapper::get);
    } else {
        String value = getFormattedValue(null);
        templateElement.setProperty("innerHTML", getTemplateForProperty(value, rendering));
        rendering.setContainer(owner);
    }
}
Also used : Element(com.vaadin.flow.dom.Element)

Aggregations

Element (com.vaadin.flow.dom.Element)377 Test (org.junit.Test)322 UI (com.vaadin.flow.component.UI)42 StateNode (com.vaadin.flow.internal.StateNode)32 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)29 Style (com.vaadin.flow.dom.Style)25 StreamResource (com.vaadin.flow.server.StreamResource)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 ArrayList (java.util.ArrayList)14 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)13 JsonObject (elemental.json.JsonObject)12 WeakReference (java.lang.ref.WeakReference)12 URI (java.net.URI)11 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)10 Registration (com.vaadin.flow.shared.Registration)10 JsonValue (elemental.json.JsonValue)10 ShadowRoot (com.vaadin.flow.dom.ShadowRoot)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 ChildElementConsumer (com.vaadin.flow.dom.ChildElementConsumer)8 AttachExistingElementFeature (com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature)8