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);
}
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);
}
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);
}
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");
}
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");
}
Aggregations