Search in sources :

Example 11 with ContextMenu

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

the class ContextMenuView method addContextMenuWithComponents.

private void addContextMenuWithComponents() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    // Components can be used also inside menu items
    contextMenu.addItem(new H5("First menu item"), e -> message.setText("Clicked on the first item"));
    Checkbox checkbox = new Checkbox("Checkbox");
    contextMenu.addItem(checkbox, e -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    // Components can also be added to the overlay
    // without creating menu items with add()
    Component separator = new Hr();
    contextMenu.add(separator, new Label("This is not a menu item"));
    addCard("ContextMenu With Components", target, message);
    target.setId("context-menu-with-components-target");
    contextMenu.setId("context-menu-with-components");
    message.setId("context-menu-with-components-message");
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Example 12 with ContextMenu

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

the class ContextMenuView method addContextMenuWithComponentsInSubMenu.

private void addContextMenuWithComponentsInSubMenu() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    contextMenu.addItem(new H5("First menu item"), event -> message.setText("Clicked on the first item"));
    MenuItem subMenuItem = contextMenu.addItem("SubMenu Item");
    SubMenu subMenu = subMenuItem.getSubMenu();
    Checkbox checkbox = new Checkbox("Checkbox");
    subMenu.addItem(checkbox, event -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    subMenu.addItem("TextItem", event -> message.setText("Clicked on text item"));
    // Components can also be added to the submenu overlay
    // without creating menu items with add()
    subMenu.addComponentAtIndex(1, new Hr());
    subMenu.add(new Label("This is not a menu item"));
    addCard("ContextMenu With Components in Sub Menu", target, message);
    target.setId("context-menu-with-submenu-components-target");
    contextMenu.setId("context-menu-with-submenu-components");
    message.setId("context-menu-with-submenu-components-message");
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) 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) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Example 13 with ContextMenu

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

the class ContextMenuView method addCheckableMenuItems.

private void addCheckableMenuItems() {
    ContextMenu contextMenu = new ContextMenu();
    Component target = createTargetComponent();
    contextMenu.setTarget(target);
    Label message = new Label("-");
    MenuItem item1 = contextMenu.addItem("Option 1", event -> {
        if (event.getSource().isChecked()) {
            message.setText("Selected option 1");
        } else {
            message.setText("Unselected option 1");
        }
    });
    item1.setCheckable(true);
    MenuItem item2 = contextMenu.addItem("Option 2", event -> {
        if (event.getSource().isChecked()) {
            message.setText("Selected option 2");
        } else {
            message.setText("Unselected option 2");
        }
    });
    item2.setCheckable(true);
    item2.setChecked(true);
    addCard("Checkable Menu Items", target, message);
    target.setId("checkable-menu-items-target");
    message.setId("checkable-menu-items-message");
}
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)

Example 14 with ContextMenu

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

the class OverrideOnBeforeOpenContextMenuPage method addContextMenuThatDynamicallyChangesItems.

private void addContextMenuThatDynamicallyChangesItems() {
    Label target = new Label("Context menu that changes items dynamically");
    target.setId("dynamic-context-menu-target");
    ContextMenu contextMenu = new ContextMenu(target) {

        @Override
        protected boolean onBeforeOpenMenu(JsonObject eventDetail) {
            removeAll();
            addItem("Dynamic Item");
            return super.onBeforeOpenMenu(eventDetail);
        }
    };
    contextMenu.addItem("Item 1");
    contextMenu.addItem("Item 2");
    add(target);
}
Also used : Label(com.vaadin.flow.component.html.Label) JsonObject(elemental.json.JsonObject) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu)

Example 15 with ContextMenu

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

the class OverrideOnBeforeOpenContextMenuPage method addContextMenuThatDoesNotOpen.

private void addContextMenuThatDoesNotOpen() {
    Label target = new Label("Context menu that should not open");
    target.setId("no-open-menu-target");
    ContextMenu contextMenu = new ContextMenu(target) {

        @Override
        protected boolean onBeforeOpenMenu(JsonObject eventDetail) {
            // ensure context menu will not open
            return false;
        }
    };
    contextMenu.addItem("Item 1");
    contextMenu.addItem("Item 2");
    add(target);
}
Also used : Label(com.vaadin.flow.component.html.Label) JsonObject(elemental.json.JsonObject) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu)

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