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

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

7 Examples 7

19 Source : MenuTemplate.java
with MIT License
from netcore-jsa

private void addCategoryName(String name) {
    Element li = ElementFactory.createLisreplacedem();
    Element span = new Span(name).getElement();
    span.getClreplacedList().add("category");
    li.appendChild(span);
    linksContainer.appendChild(li);
}

19 Source : ElementInitOrderView.java
with MIT License
from mcollovati

private static Element createElement(String tag) {
    Element element = new Element(tag);
    element.appendChild(new Element("span"));
    element.getStyle().set("animationName", "style");
    element.getClreplacedList().add("clreplaced");
    element.setAttribute("attribute", "attribute");
    element.setProperty("property", "property");
    return element;
}

18 Source : EventHandlerView.java
with MIT License
from mcollovati

@EventHandler
private void sendData(@EventData("event.button") int button, @EventData("event.type") String type, @EventData("event.srcElement.tagName") String tag) {
    Element container = ElementFactory.createDiv();
    container.appendChild(ElementFactory.createDiv("Received event from the client with the data:"));
    container.appendChild(ElementFactory.createDiv("button: " + button));
    container.appendChild(ElementFactory.createDiv("type: " + type));
    container.appendChild(ElementFactory.createDiv("tag: " + tag.toLowerCase(Locale.ENGLISH)));
    container.setAttribute("id", "event-data");
    getParent().get().getElement().appendChild(container);
}

18 Source : DomEventFilterView.java
with MIT License
from mcollovati

private void addMessage(String message) {
    Element element = new Element("div");
    element.setText(message);
    messages.appendChild(element);
}

17 Source : MenuTemplate.java
with MIT License
from netcore-jsa

private void addNavigation(Clreplaced<? extends Component> navigationTarget, String name) {
    Element li = ElementFactory.createLisreplacedem();
    RouterLink routerLink = new RouterLink(name, navigationTarget);
    routerLink.getClreplacedNames().add("button");
    linksContainer.appendChild(li.appendChild(routerLink.getElement()));
    routerLink.setHighlightCondition((r, event) -> Objects.equals(r.getHref(), event.getLocation().getPath()));
    routerLink.setHighlightAction((r, highlight) -> {
        if (highlight) {
            routerLink.getElement().getClreplacedList().add(SELECTED_CLreplaced_NAME);
        } else {
            routerLink.getElement().getClreplacedList().remove(SELECTED_CLreplaced_NAME);
        }
    });
}

16 Source : MenuTemplate.java
with MIT License
from netcore-jsa

private void addSeparator() {
    Element li = ElementFactory.createLisreplacedem();
    Div div = new Div();
    div.getClreplacedNames().add("separator");
    li.appendChild(div.getElement());
    linksContainer.appendChild(li);
}

6 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);
}