Java Code Examples for com.vaadin.flow.dom.Element#addPropertyChangeListener()

The following examples show how to use com.vaadin.flow.dom.Element#addPropertyChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendMultibyteCharactersUI.java    From flow with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    Push push = getClass().getAnnotation(Push.class);

    getPushConfiguration().setPushMode(push.value());
    getPushConfiguration().setTransport(push.transport());

    Div div = new Div();
    div.setText("Just a label");
    div.setId("label");
    add(div);
    Element area = ElementFactory.createTextarea();
    area.addPropertyChangeListener("value", "change", event -> {
    });
    area.setAttribute("id", "text");
    getElement().appendChild(area);
}
 
Example 2
Source File: SynchronizedPropertyView.java    From flow with Apache License 2.0 6 votes vote down vote up
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.addPropertyChangeListener("value", "change",
            event -> {
            });
    syncOnChangeInitialValue.addEventListener("change", e -> {
        syncOnChangeInitialValueLabel
                .setText("Server value in change listener: "
                        + syncOnChangeInitialValue.getProperty("value"));
    });
    syncOnChangeInitialValue.setProperty("value", "initial");

    getElement().appendChild(syncOnChangeInitialValue);
    add(syncOnChangeInitialValueLabel);
}
 
Example 3
Source File: SynchronizedPropertyView.java    From flow with Apache License 2.0 5 votes vote down vote up
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.addPropertyChangeListener("valueAsNumber", "blur", event -> {
    });
    multiSync.addPropertyChangeListener("value", "input", event -> {
    });

    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);
}
 
Example 4
Source File: BasicElementView.java    From flow with Apache License 2.0 4 votes vote down vote up
@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");
    input.addPropertyChangeListener("value", "change", event -> {
    });

    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("class", "thankYou");
        greeting.addEventListener("click",
                e2 -> greeting.removeFromParent());

        mainElement.appendChild(greeting);
    }).addEventData("element.textContent").addEventData("event.clientX")
            .addEventData("event.clientY");

    Element helloWorldElement = ElementFactory.createDiv("Hello world");

    Set<String> spanClasses = helloWorldElement.getClassList();

    helloWorldElement.setProperty("id", "hello-world");
    spanClasses.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!");
                }
                spanClasses.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);

}
 
Example 5
Source File: HistoryView.java    From flow with Apache License 2.0 4 votes vote down vote up
private static Element createSynchronizedInput(String id) {
    Element element = ElementFactory.createInput().setAttribute("id", id);
    element.addPropertyChangeListener("value", "change", event -> {});
    return element;
}