Hi,
I would like to have a set of buttons in the AppLayou NavBar section that is dependent on the page shown (in the content section). My setup is fairly simple with the a set of RouterLink links in the drawer (wrapped in tabs) and the content set by instanciating a view when the link is clicked.
I would like each view to be able to add a relevent set of buttons to the AppLayout navBar, but I don’t know how to access it. I was hoping the a parent layout would be availble to a child view, or that I could pass the parent layout to the child. However, (I assume) the view does not exist until the RouterLink generates it, so I can’t pass the layout
I also considered firing an event when the router navigates, but I can’t work out how to add a listener in the child view.
Perhaps I’m overthinking it… Is there a straightforward way to do this?
Thanks!
MainLayout.java
public class MainLayout extends AppLayout implements BeforeEnterObserver, TrackerConfigurator {
private Map<Tab, Component> tabSet = new HashMap<>();
public MainLayout() {
FlexLayout navBarLayout = new FlexLayout(leftNavBarLayout, navBarContentContainer, rightNavBarLayout);
navBarLayout.setWidthFull();
navBarLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.BETWEEN);
navBarLayout.setAlignItems(FlexComponent.Alignment.CENTER);
addToNavbar(navBarLayout);
// Tabs
TabWithIdentifier page0 = tabForPageWithRouter("Dashboard", new IronIcon("icomoon", "icons"), DashboardView.class);
TabWithIdentifier page1 = tabForPageWithRouter("Users", new IronIcon("icomoon", "users2"), UserView.class);
...
final Tabs tabs = new Tabs(page0, page1, ...);
tabs.setOrientation(Tabs.Orientation.VERTICAL);
addToDrawer(tabs);
}
private TabWithIdentifier tabForPageWithRouter(String title, IronIcon icon, Class classType) {
icon.setSize("1.3em");
icon.getStyle().set("margin-right", "10px");
RouterLink routerLink = new RouterLink(null, classType);
routerLink.add(icon);
routerLink.add(title);
TabWithIdentifier tab = new TabWithIdentifier(routerLink);
tab.setId(title);
tab.setIdentifier(title);
tab.addClassName("drawer-tab");
return tab;
}
In the view I would like to access navBarContentContainer, clear out any controls from the last page visited and add buttons relevant for the current view.