I am currently using Vaadin 8 and have a Navigator with couple of menus contributed through the Views. Similar to default CRUD example in Eclipse for Vaadin 8. I want to add a Submenu to the existing Menu which pops up a window.
Is there a way to add submenu to the menu contributed through views??? I dont have MenuBar and MenuItems. Please find the attached code snippet.
Any help is appreciated.
CssLayout header = new CssLayout();
header.addStyleName("valo-content");
header.setWidth(100, Unit.PERCENTAGE);
viewContainer = new HorizontalLayout();
viewContainer.addStyleName("valo-content");
viewContainer.setWidth(100, Unit.PERCENTAGE);
viewContainer.setSizeFull();
final Navigator navigator = new Navigator(ui, viewContainer);
navigator.setErrorView(ErrorView.class);
ExampleMenu menu = new ExampleMenu(navigator);
menu.addView(new MessageView(), "Message", "Message", VaadinIcons.MAILBOX);
menu.addView(new AboutView(), "About", "About", VaadinIcons.INFO_CIRCLE);
navigator.addViewChangeListener(viewChangeListener);
header.addComponent(menu);
addComponent(header);
addComponent(viewContainer);
public class ExampleMenu extends HorizontalLayout {
public ExampleMenu(Navigator navigator) {
this.navigator = navigator;
setWidth("100%");
setSpacing(true);
setStyleName("backColorBlue");
CssLayout logoContainer = new CssLayout();
logoContainer.addStyleName("valo-content");
logoContainer.setWidth(100, Unit.PERCENTAGE);
addComponent(logoContainer);
// button for toggling the visibility of the menu when on a small screen
final Button showMenu = new Button("Menu", new ClickListener() {
@Override
public void buttonClick(final ClickEvent event) {
if (getStyleName().contains(VALO_MENU_VISIBLE)) {
removeStyleName(VALO_MENU_VISIBLE);
} else {
addStyleName(VALO_MENU_VISIBLE);
}
}
});
showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
showMenu.addStyleName(VALO_MENU_TOGGLE);
showMenu.setIcon(VaadinIcons.MENU);
addComponent(showMenu);
Image image = new Image(null, new ThemeResource("img/logo.jpg"));
// container for the navigation buttons, which are added by addView()
menuItemsLayout = new HorizontalLayout();
menuItemsLayout.setPrimaryStyleName(VALO_MENUITEMS);
logoContainer.addComponent(image);
addComponent(menuItemsLayout);
setExpandRatio(logoContainer, 1);
}
public void addView(Class<? extends View> viewClass, final String name, String caption, Resource icon) {
navigator.addView(name, viewClass);
createViewButton(name, caption, icon);
}
private void createViewButton(final String name, String caption, Resource icon) {
Button button = new Button(caption, new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
navigator.navigateTo(name);
}
});
button.setPrimaryStyleName(ValoTheme.MENU_ITEM);
button.setIcon(icon);
menuItemsLayout.addComponent(button);
viewButtons.put(name, button);
}
}