Search in sources :

Example 1 with ContextMenu

use of com.vaadin.flow.component.contextmenu.ContextMenu in project flow-components by vaadin.

the class ContextMenuCreatedOnAttachPage method createContextMenuAndTarget.

private void createContextMenuAndTarget(String id, boolean openOnClick) {
    final Div target = new Div(new Text(id));
    target.setId(id);
    addAttachListener(ev -> {
        final ContextMenu contextMenu = new ContextMenu();
        contextMenu.addItem("ITEM");
        contextMenu.setTarget(target);
        contextMenu.setOpenOnClick(openOnClick);
        add(contextMenu);
    });
    add(target);
}
Also used : Div(com.vaadin.flow.component.html.Div) Text(com.vaadin.flow.component.Text) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu)

Example 2 with ContextMenu

use of com.vaadin.flow.component.contextmenu.ContextMenu in project flow-components by vaadin.

the class ContextMenuPage method addContextMenuWithOpenedChangeListener.

private void addContextMenuWithOpenedChangeListener() {
    Label target = new Label("Target for context menu with opened change listener");
    target.setId("context-menu-test");
    ContextMenu contextMenu = new ContextMenu();
    contextMenu.setTarget(target);
    Paragraph content = new Paragraph("Context menu test.");
    contextMenu.add(content);
    Div message = new Div();
    message.setId("message");
    contextMenu.addOpenedChangeListener(event -> {
        message.setText("The open state of the context menu is " + contextMenu.isOpened());
    });
    add(target, contextMenu, message);
}
Also used : Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) Paragraph(com.vaadin.flow.component.html.Paragraph)

Example 3 with ContextMenu

use of com.vaadin.flow.component.contextmenu.ContextMenu in project flow-components by vaadin.

the class ContextMenuPage method addContextMenuWithControls.

private void addContextMenuWithControls() {
    ContextMenu contextMenu = new ContextMenu();
    Label target = new Label("Target for context menu with setOpenOnClick() and setTarget()");
    target.setId("context-menu-with-controls");
    contextMenu.setTarget(target);
    Paragraph content = new Paragraph("Context menu With SetOpenOnClick.");
    contextMenu.add(content);
    String current = "Current state is ";
    Div message = new Div();
    message.setId("message-on-click");
    message.setText(current + contextMenu.isOpenOnClick());
    NativeButton on = new NativeButton("setOpenOnClick");
    on.setId("on");
    on.addClickListener(event -> {
        contextMenu.setOpenOnClick(true);
        message.setText(current + contextMenu.isOpenOnClick());
    });
    NativeButton off = new NativeButton("setOpenOnClick-off");
    off.setId("off");
    off.addClickListener(event -> {
        contextMenu.setOpenOnClick(false);
        message.setText(current + contextMenu.isOpenOnClick());
    });
    Label altTarget = new Label("Alternative target");
    altTarget.setId("alt-target");
    NativeButton changeTarget = new NativeButton("Change target", event -> contextMenu.setTarget(altTarget));
    changeTarget.setId("change-target");
    NativeButton removeTarget = new NativeButton("Remove target", event -> contextMenu.setTarget(null));
    removeTarget.setId("remove-target");
    NativeButton detachTarget = new NativeButton("Detach target", event -> remove(target));
    detachTarget.setId("detach-target");
    NativeButton attachTarget = new NativeButton("Attach target", event -> add(target));
    attachTarget.setId("attach-target");
    NativeButton attachDetachTarget = new NativeButton("Attach and Detach target", event -> {
        add(target);
        remove(target);
    });
    attachDetachTarget.setId("attach-detach-target");
    add(contextMenu, target, altTarget, message, on, off, changeTarget, removeTarget, detachTarget, attachTarget, attachDetachTarget);
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) Paragraph(com.vaadin.flow.component.html.Paragraph)

Example 4 with ContextMenu

use of com.vaadin.flow.component.contextmenu.ContextMenu in project flow-components by vaadin.

the class ContextMenuView method addContextMenuWithSubMenus.

private void addContextMenuWithSubMenus() {
    ContextMenu contextMenu = new ContextMenu();
    Component target = createTargetComponent();
    contextMenu.setTarget(target);
    Label message = new Label("-");
    contextMenu.addItem("First menu item", event -> message.setText("Clicked on the first item"));
    MenuItem parent = contextMenu.addItem("Parent item");
    SubMenu subMenu = parent.getSubMenu();
    subMenu.addItem("Second menu item", event -> message.setText("Clicked on the second item"));
    subMenu = subMenu.addItem("Parent item").getSubMenu();
    subMenu.addItem("Third menu item", event -> message.setText("Clicked on the third item"));
    addCard("Hierarchical Menu", target, message);
    target.setId("hierarchical-menu-target");
    message.setId("hierarchical-menu-message");
}
Also used : Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) Component(com.vaadin.flow.component.Component)

Example 5 with ContextMenu

use of com.vaadin.flow.component.contextmenu.ContextMenu in project flow-components by vaadin.

the class ContextMenuView method addBasicContextMenu.

private void addBasicContextMenu() {
    ContextMenu contextMenu = new ContextMenu();
    Component target = createTargetComponent();
    contextMenu.setTarget(target);
    Label message = new Label("-");
    contextMenu.addItem("First menu item", e -> message.setText("Clicked on the first item"));
    contextMenu.addItem("Second menu item", e -> message.setText("Clicked on the second item"));
    // The created MenuItem component can be saved for later use
    MenuItem item = contextMenu.addItem("Disabled menu item", e -> message.setText("This cannot happen"));
    item.setEnabled(false);
    addCard("Basic ContextMenu", target, message);
    target.setId("basic-context-menu-target");
    contextMenu.setId("basic-context-menu");
}
Also used : Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Component(com.vaadin.flow.component.Component)

Aggregations

ContextMenu (com.vaadin.flow.component.contextmenu.ContextMenu)15 Label (com.vaadin.flow.component.html.Label)10 Component (com.vaadin.flow.component.Component)5 MenuItem (com.vaadin.flow.component.contextmenu.MenuItem)5 Div (com.vaadin.flow.component.html.Div)3 NativeButton (com.vaadin.flow.component.html.NativeButton)3 Paragraph (com.vaadin.flow.component.html.Paragraph)3 Avatar (com.vaadin.flow.component.avatar.Avatar)2 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)2 SubMenu (com.vaadin.flow.component.contextmenu.SubMenu)2 H5 (com.vaadin.flow.component.html.H5)2 Hr (com.vaadin.flow.component.html.Hr)2 JsonObject (elemental.json.JsonObject)2 User (com.dala.data.user.User)1 AuthenticatedUser (com.dala.security.AuthenticatedUser)1 Text (com.vaadin.flow.component.Text)1 Image (com.vaadin.flow.component.html.Image)1 Users (org.togetherjava.tjbot.db.generated.tables.pojos.Users)1