com.vaadin.flow.dom.Element.addEventListener()

Here are the examples of the java api com.vaadin.flow.dom.Element.addEventListener() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

19 Source : SynchronizedPropertyView.java
with MIT License
from mcollovati

private void addSyncWithInitialValue() {
    add(new Text("Synchronized on 'change' event with initial value"));
    final Div syncOnChangeInitialValueLabel = new Div();
    syncOnChangeInitialValueLabel.setId("syncOnChangeInitialValueLabel");
    Element syncOnChangeInitialValue = ElementFactory.createInput();
    syncOnChangeInitialValueLabel.setText("Server value on create: " + syncOnChangeInitialValue.getProperty("value"));
    syncOnChangeInitialValue.setAttribute("id", "syncOnChangeInitialValue");
    syncOnChangeInitialValue.synchronizeProperty("value", "change");
    syncOnChangeInitialValue.addEventListener("change", e -> {
        syncOnChangeInitialValueLabel.setText("Server value in change listener: " + syncOnChangeInitialValue.getProperty("value"));
    });
    syncOnChangeInitialValue.setProperty("value", "initial");
    getElement().appendChild(syncOnChangeInitialValue);
    add(syncOnChangeInitialValueLabel);
}

19 Source : SynchronizedPropertyView.java
with MIT License
from mcollovati

private void addSyncMultipleProperties() {
    add(new Text("Synchronize 'value' on 'input' event and 'valueAsNumber' on 'blur'"));
    Div valueLabel = new Div();
    valueLabel.setId("multiSyncValueLabel");
    Div valueAsNumberLabel = new Div();
    valueAsNumberLabel.setId("multiSyncValueAsNumberLabel");
    Element multiSync = ElementFactory.createInput("number");
    multiSync.setAttribute("id", "multiSyncValue");
    multiSync.synchronizeProperty("valueAsNumber", "blur");
    multiSync.synchronizeProperty("value", "input");
    multiSync.addEventListener("input", e -> {
        valueLabel.setText("Server value: " + multiSync.getProperty("value"));
    });
    multiSync.addEventListener("blur", e -> {
        valueAsNumberLabel.setText("Server valueAsNumber: " + multiSync.getProperty("valueAsNumber"));
    });
    getElement().appendChild(multiSync);
    add(valueLabel, valueAsNumberLabel);
}

19 Source : PushStateScrollView.java
with MIT License
from mcollovati

private static Element createButton(String name, BiConsumer<JsonValue, String> action) {
    String location = PushStateScrollView.clreplaced.getName() + "/" + name;
    Element button = ElementFactory.createButton(name);
    button.setAttribute("id", name);
    button.addEventListener("click", e -> action.accept(null, location));
    return button;
}

19 Source : PopStateHandlerView.java
with MIT License
from mcollovati

protected Element createPushStateButtons(String target) {
    Element button = ElementFactory.createButton(target).setAttribute("id", target);
    button.addEventListener("click", e -> {
    }, "window.history.pushState(null, null, event.target.textContent)");
    return button;
}

19 Source : DebounceSynchronizePropertyView.java
with MIT License
from mcollovati

private Component createModeToggle(String caption, String id, Consumer<DomListenerRegistration> configurator) {
    Element checkbox = new Element("input");
    checkbox.setAttribute("type", "checkbox");
    checkbox.setAttribute("id", id);
    checkbox.addEventListener("change", new DomEventListener() {

        private DomListenerRegistration registration = null;

        @Override
        public void handleEvent(DomEvent event) {
            if (event.getEventData().getBoolean("element.checked")) {
                replacedert registration == null;
                registration = inputElement.addPropertyChangeListener("value", "input", propertyChange -> addChangeMessage(propertyChange.getValue()));
                configurator.accept(registration);
            } else {
                registration.remove();
                registration = null;
            }
        }
    }).addEventData("element.checked");
    Label label = new Label(caption);
    label.getElement().insertChild(0, checkbox);
    label.getElement().getStyle().set("display", "block");
    return label;
}

9 Source : BasicElementView.java
with MIT License
from mcollovati

@Override
protected void onShow() {
    Element mainElement = getElement();
    mainElement.getStyle().set("margin", "1em");
    Element button = ElementFactory.createButton("Click me");
    Element input = ElementFactory.createInput().setAttribute("placeholder", "Synchronized on change event").synchronizeProperty("value", "change");
    button.addEventListener("click", e -> {
        JsonObject eventData = e.getEventData();
        String buttonText = eventData.getString("element.textContent");
        int clientX = (int) eventData.getNumber("event.clientX");
        int clientY = (int) eventData.getNumber("event.clientY");
        Element greeting = ElementFactory.createDiv("Thank you for clicking \"" + buttonText + "\" at (" + clientX + "," + clientY + ")! The field value is " + input.getProperty("value"));
        greeting.setAttribute("clreplaced", "thankYou");
        greeting.addEventListener("click", e2 -> greeting.removeFromParent());
        mainElement.appendChild(greeting);
    }, "element.textContent", "event.clientX", "event.clientY");
    Element helloWorldElement = ElementFactory.createDiv("Hello world");
    Set<String> spanClreplacedes = helloWorldElement.getClreplacedList();
    helloWorldElement.setProperty("id", "hello-world");
    spanClreplacedes.add("hello");
    helloWorldEventRemover = helloWorldElement.addEventListener("click", e -> {
        if (helloWorldElement.getText().equals("Hello world")) {
            helloWorldElement.setText("Stop touching me!");
        } else {
            // We never get to this code as long as the event
            // removal actually works
            helloWorldElement.setText(helloWorldElement.getText() + " This might be your last warning!");
        }
        spanClreplacedes.clear();
        helloWorldEventRemover.remove();
    });
    Style s = helloWorldElement.getStyle();
    s.set("color", "red");
    s.set("fontWeight", "bold");
    Element elementContainer = ElementFactory.createDiv();
    Element toRemove = ElementFactory.createDiv("To Remove").setAttribute("id", "to-remove");
    elementContainer.appendChild(toRemove);
    elementContainer.setAttribute("id", "addremovecontainer");
    Element addRemoveButton = ElementFactory.createButton("Add and remove element");
    addRemoveButton.setAttribute("id", "addremovebutton");
    addRemoveButton.addEventListener("click", e -> {
        // very basic usecase: append and then immediately remove
        Element div = ElementFactory.createDiv("foobar");
        elementContainer.appendChild(div);
        elementContainer.removeChild(div);
        elementContainer.removeChild(toRemove);
        elementContainer.appendChild(toRemove);
        // Now let's have two "add" operation and then two "remove"
        // operation so that removal has an addition right before which
        // targets different element
        Element div2 = ElementFactory.createDiv("foobar");
        elementContainer.appendChild(div);
        elementContainer.appendChild(div2);
        Element ok = ElementFactory.createDiv("OK");
        ok.setAttribute("id", "ok");
        elementContainer.appendChild(ok);
        elementContainer.removeChild(div);
        elementContainer.removeChild(div2);
    });
    mainElement.appendChild(helloWorldElement, button, input, addRemoveButton, elementContainer);
}