|
| 1 | +package software.xdev.vaadin.ui; |
| 2 | + |
| 3 | +import java.util.Objects; |
| 4 | + |
| 5 | +import com.vaadin.flow.component.HasElement; |
| 6 | +import com.vaadin.flow.component.applayout.AppLayout; |
| 7 | +import com.vaadin.flow.component.applayout.DrawerToggle; |
| 8 | +import com.vaadin.flow.component.icon.VaadinIcon; |
| 9 | +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
| 10 | +import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
| 11 | +import com.vaadin.flow.component.sidenav.SideNav; |
| 12 | +import com.vaadin.flow.component.sidenav.SideNavItem; |
| 13 | +import com.vaadin.flow.router.Layout; |
| 14 | +import com.vaadin.flow.router.PageTitle; |
| 15 | + |
| 16 | +import software.xdev.vaadin.breadcrumbs.Breadcrumbs; |
| 17 | +import software.xdev.vaadin.ui.cars.CarsView; |
| 18 | +import software.xdev.vaadin.ui.cars.brand.ElectricView; |
| 19 | +import software.xdev.vaadin.ui.cars.brand.GasolineView; |
| 20 | +import software.xdev.vaadin.ui.cars.brand.HybridView; |
| 21 | + |
| 22 | + |
| 23 | +@Layout |
| 24 | +@PageTitle("Breadcrumb Demo") |
| 25 | +public class MainLayout extends AppLayout |
| 26 | +{ |
| 27 | + private final Breadcrumbs breadcrumbs = new Breadcrumbs() |
| 28 | + .withHomeBreadcrumbName(this.getTranslation(TranslationKeys.HOME)) |
| 29 | + .withBreadcrumbNameResolver((full, part) -> this.getTranslation(part)); |
| 30 | + |
| 31 | + public MainLayout() |
| 32 | + { |
| 33 | + final SideNav sideNav = new SideNav(); |
| 34 | + sideNav.addItem(new SideNavItem( |
| 35 | + this.getTranslation(TranslationKeys.HOME), |
| 36 | + "", |
| 37 | + VaadinIcon.HOME_O.create())); |
| 38 | + |
| 39 | + final SideNavItem carsItem = new SideNavItem( |
| 40 | + this.getTranslation(TranslationKeys.CARS), |
| 41 | + CarsView.class, |
| 42 | + VaadinIcon.CAR.create()); |
| 43 | + carsItem.addItem(new SideNavItem( |
| 44 | + this.getTranslation(TranslationKeys.GASOLINE), |
| 45 | + GasolineView.class, |
| 46 | + VaadinIcon.FIRE.create())); |
| 47 | + carsItem.addItem(new SideNavItem( |
| 48 | + this.getTranslation(TranslationKeys.HYBRID), |
| 49 | + HybridView.class, |
| 50 | + VaadinIcon.GLOBE.create())); |
| 51 | + carsItem.addItem(new SideNavItem( |
| 52 | + this.getTranslation(TranslationKeys.ELECTRIC), |
| 53 | + ElectricView.class, |
| 54 | + VaadinIcon.BOLT.create())); |
| 55 | + |
| 56 | + sideNav.addItem(Objects.requireNonNull(carsItem)); |
| 57 | + |
| 58 | + this.setPrimarySection(Section.DRAWER); |
| 59 | + |
| 60 | + final VerticalLayout navWrapper = new VerticalLayout(sideNav); |
| 61 | + sideNav.setWidthFull(); |
| 62 | + navWrapper.setSpacing(true); |
| 63 | + this.addToDrawer(navWrapper); |
| 64 | + |
| 65 | + final HorizontalLayout vlHeader = new HorizontalLayout(new DrawerToggle(), this.breadcrumbs); |
| 66 | + vlHeader.setSpacing(false); |
| 67 | + this.addToNavbar(vlHeader); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void showRouterLayoutContent(final HasElement content) |
| 72 | + { |
| 73 | + super.showRouterLayoutContent(content); |
| 74 | + this.breadcrumbs.updateFromCurrentPath(); |
| 75 | + } |
| 76 | +} |
0 commit comments