'Vaadin 14 popup with button and context menu

I want to have a context menu like this Basic ContextMenu, that shows on button click. Each of the entries of the context menu should open a new window.

 private void button_onClick(final ClickEvent<Button> event)
    {
        final ContextMenu contextMenu = new ContextMenu();
        contextMenu.addItem("Start", e -> this.add(new Dialog(new Start())));
        contextMenu.addItem("Stop", e -> this.add(new Dialog(new Stop())));
    }


Solution 1:[1]

You don't call open() on the dialog.

private void button_onClick(final ClickEvent<Button> event)
{
    final ContextMenu contextMenu = new ContextMenu();
    contextMenu.addItem("Start", e -> this.add(new Dialog(new Start()).open()));
    contextMenu.addItem("Stop", e -> this.add(new Dialog(new Stop()).open()));
}

Solution 2:[2]

final Button button = new Button("context button");
final ContextMenu contextMenu = new ContextMenu();
contextMenu.setOpenOnClick(true); //on left click
contextMenu.setTarget(button); //link button
contextMenu.addItem("xls", event -> Notification.show("xls"));
contextMenu.addItem("pdf", event -> Notification.show("pdf"));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Simon Martinelli
Solution 2 ???? First