Search in sources :

Example 1 with AppLayoutComponent

use of com.github.appreciated.app.layout.behaviour.AppLayoutComponent in project vaadin-app-layout by appreciated.

the class AppLayoutConfiguration method build.

/**
 * FIXME this configuration should only hold configuration => Single responsibility principle
 * This terminating build method is part of the builder and not of the configuration.
 */
public AppLayoutComponent build() {
    // this method has a lot of magic. add some inline comments describing why are you doing what.
    if (navigationElementProvider == null) {
        if (variant.isTop())
            navigationElementProvider = new DefaultLeftNavigationBadgeElementComponentFactory();
        else
            navigationElementProvider = new DefaultLeftNavigationBadgeElementComponentFactory();
    }
    if (customElementProvider == null) {
        if (variant.isTop())
            customElementProvider = new DefaultLeftClickableNavigationElementFactory();
        else
            customElementProvider = new DefaultLeftClickableNavigationElementFactory();
    }
    if (sectionProvider == null) {
        if (variant.isTop())
            sectionProvider = new DefaultLeftSectionElementComponentFactory();
        else
            sectionProvider = new DefaultLeftSectionElementComponentFactory();
    }
    if (submenuProvider == null) {
        if (variant.isTop())
            submenuProvider = new DefaultTopSubmenuNavigationElementFactory();
        else
            submenuProvider = new DefaultLeftSubmenuNavigationElementFactory();
    }
    AppLayoutSessionHelper.setActiveVariant(variant);
    if (titleComponent == null) {
        instance.setTitle(title);
    } else {
        instance.setTitleComponent(titleComponent);
    }
    if (isNavigatorEnabled) {
        navigator = navigatorProducer.apply(instance.getContentHolder());
        if (navigator == null) {
            throw new RuntimeException("The set navigatorProducer returned 'null' as a Navigator");
        }
        navigator.addViewChangeListener(event -> beforeViewChange(event.getViewName()));
        if (viewProviderSupplier != null) {
            navigator.addProvider(viewProviderSupplier.get());
        }
        if (errorProvider != null) {
            navigator.setErrorProvider(errorProvider.get());
        }
        if (errorViewProvider != null) {
            navigator.setErrorView(errorViewProvider.get());
        }
        if (navigatorConsumer != null) {
            navigatorConsumer.accept(navigator);
        }
        if (!isCDI && defaultNavigationElement == null) {
            defaultNavigationElement = navigationElements.stream().filter(element -> element instanceof NavigatorNavigationElement).map(element -> ((NavigatorNavigationElement) element)).findFirst().orElse(null);
        }
    } else {
        componentNavigator = new ComponentNavigator(instance.getContentHolder());
        componentNavigator.addViewChangeListener(event -> beforeViewChange(event.getViewName()));
        if (errorViewProvider != null) {
            componentNavigator.setErrorView(errorViewProvider.get());
        }
        if (componentNavigatorConsumer != null) {
            componentNavigatorConsumer.accept(componentNavigator);
        }
        if (defaultNavigationElement == null) {
            defaultNavigationElement = navigationElements.stream().filter(element -> element instanceof NavigatorNavigationElement).map(element -> ((NavigatorNavigationElement) element)).findFirst().orElse(null);
        }
        defaultNavigationElement.addViewToComponentNavigator(componentNavigator);
    }
    addComponents(headerElements, instance::addNavigationHeaderElement);
    addComponents(navigationElements, instance::addNavigationElement);
    addComponents(footerElements, instance::addNavigationFooterElement);
    appBarElements.forEach(instance::addAppBarElement);
    instance.setDesign(design);
    if (appBarIconComponent != null) {
        instance.addAppBarIcon(appBarIconComponent);
    }
    instance.setNavigatorNavigationElements(navigatorElements);
    if (!isNavigatorEnabled) {
        componentNavigator.navigateTo(defaultNavigationElement.getViewName());
    } else {
        if (!isCDI && defaultNavigationElement != null) {
            defaultNavigationElement.addViewToNavigator(navigator);
        } else if (isCDI && defaultNavigationElement != null) {
            System.err.println("WARNING - AppLayout - You are using isCDI but try to set the DefaultNavigationElement this will have no effect");
        }
    }
    return instance;
}
Also used : DefaultLeftClickableNavigationElementFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftClickableNavigationElementFactory) Panel(com.vaadin.ui.Panel) AppLayoutSessionHelper(com.github.appreciated.app.layout.session.AppLayoutSessionHelper) SectionNavigationElement(com.github.appreciated.app.layout.builder.elements.SectionNavigationElement) Behaviour(com.github.appreciated.app.layout.behaviour.Behaviour) NavigationElementComponent(com.github.appreciated.app.layout.builder.interfaces.NavigationElementComponent) UI(com.vaadin.ui.UI) ComponentFactory(com.github.appreciated.app.layout.builder.interfaces.ComponentFactory) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HasCaptionInterceptor(com.github.appreciated.app.layout.builder.interfaces.HasCaptionInterceptor) SubmenuNavigationElement(com.github.appreciated.app.layout.builder.elements.SubmenuNavigationElement) DefaultLeftSectionElementComponentFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSectionElementComponentFactory) AbstractNavigationElement(com.github.appreciated.app.layout.builder.elements.AbstractNavigationElement) NavigatorNavigationElement(com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement) AppLayoutDesign(com.github.appreciated.app.layout.builder.design.AppLayoutDesign) NavigationElementInfo(com.github.appreciated.app.layout.builder.entities.NavigationElementInfo) DefaultLeftNavigationBadgeElementComponentFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftNavigationBadgeElementComponentFactory) Navigator(com.vaadin.navigator.Navigator) Consumer(java.util.function.Consumer) List(java.util.List) AppLayoutComponent(com.github.appreciated.app.layout.behaviour.AppLayoutComponent) ComponentNavigator(com.github.appreciated.app.layout.navigator.ComponentNavigator) Factory(com.github.appreciated.app.layout.builder.interfaces.Factory) Optional(java.util.Optional) DefaultTopSubmenuNavigationElementFactory(com.github.appreciated.app.layout.builder.factories.top.DefaultTopSubmenuNavigationElementFactory) DefaultLeftClickableNavigationElementFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftClickableNavigationElementFactory) DefaultLeftSubmenuNavigationElementFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSubmenuNavigationElementFactory) ViewProvider(com.vaadin.navigator.ViewProvider) View(com.vaadin.navigator.View) Component(com.vaadin.ui.Component) ComponentNavigator(com.github.appreciated.app.layout.navigator.ComponentNavigator) DefaultTopSubmenuNavigationElementFactory(com.github.appreciated.app.layout.builder.factories.top.DefaultTopSubmenuNavigationElementFactory) DefaultLeftSectionElementComponentFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSectionElementComponentFactory) NavigatorNavigationElement(com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement) DefaultLeftNavigationBadgeElementComponentFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftNavigationBadgeElementComponentFactory) DefaultLeftSubmenuNavigationElementFactory(com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSubmenuNavigationElementFactory)

Example 2 with AppLayoutComponent

use of com.github.appreciated.app.layout.behaviour.AppLayoutComponent in project vaadin-app-layout by appreciated.

the class DemoUI method setDrawerVariant.

private void setDrawerVariant(Behaviour variant) {
    holder.removeAllComponents();
    AppLayoutComponent drawer = AppLayout.getDefaultBuilder(variant).withTitle("App Layout").addToAppBar(new AppBarNotificationButton(notifications, true)).withViewNameInterceptor(new DefaultViewNameInterceptor()).withDefaultNavigationView(View1.class).withDesign(AppLayoutDesign.MATERIAL).add(new MenuHeader("Version 0.9.21", new ThemeResource("logo.png")), HEADER).addClickable("Set Behaviour HEADER", VaadinIcons.COG, clickEvent -> openModeSelector(variant), HEADER).add("Home", VaadinIcons.HOME, badge, new View1()).add(SubmenuBuilder.get("My Submenu", VaadinIcons.PLUS).add(SubmenuBuilder.get("My Submenu", VaadinIcons.PLUS).add("Charts3", VaadinIcons.SPLINE_CHART, View2.class).add("Contact3", VaadinIcons.CONNECT, View3.class).add("More3", VaadinIcons.COG, View4.class).build()).add("Contact1", VaadinIcons.CONNECT, View3.class).add("More1", VaadinIcons.COG, View4.class).build()).add(SubmenuBuilder.get("My Submenu", VaadinIcons.PLUS).add(SubmenuBuilder.get("My Submenu", VaadinIcons.PLUS).add("Charts4", VaadinIcons.SPLINE_CHART, View2.class).add("Contact4", VaadinIcons.CONNECT, View3.class).add("More4", VaadinIcons.COG, View4.class).build()).add("Contact2", VaadinIcons.CONNECT, View3.class).add("More2", VaadinIcons.COG, View4.class).build()).add("Menu", VaadinIcons.MENU, View5.class).add("Elements", VaadinIcons.LIST, ElementsView.class).addClickable("Set Behaviour FOOTER", VaadinIcons.COG, clickEvent -> openModeSelector(variant), FOOTER).build();
    drawer.addStyleName("left");
    holder.addComponent(drawer);
    if (getNavigator() != null) {
        getNavigator().navigateTo("");
    }
    reloadNotifications();
}
Also used : ThemeResource(com.vaadin.server.ThemeResource) FOOTER(com.github.appreciated.app.layout.builder.Section.FOOTER) SubmenuBuilder(com.github.appreciated.app.layout.builder.elements.builders.SubmenuBuilder) Behaviour(com.github.appreciated.app.layout.behaviour.Behaviour) VaadinRequest(com.vaadin.server.VaadinRequest) VaadinServlet(com.vaadin.server.VaadinServlet) Transport(com.vaadin.shared.ui.ui.Transport) VaadinIcons(com.vaadin.icons.VaadinIcons) DefaultViewNameInterceptor(com.github.appreciated.app.layout.interceptor.DefaultViewNameInterceptor) AppBarNotificationButton(com.github.appreciated.app.layout.component.button.AppBarNotificationButton) ValoTheme(com.vaadin.ui.themes.ValoTheme) MEDIUM(com.github.appreciated.app.layout.builder.entities.DefaultNotification.Priority.MEDIUM) AppLayoutDesign(com.github.appreciated.app.layout.builder.design.AppLayoutDesign) HEADER(com.github.appreciated.app.layout.builder.Section.HEADER) DefaultNotificationHolder(com.github.appreciated.app.layout.builder.entities.DefaultNotificationHolder) PushStateNavigation(com.vaadin.navigator.PushStateNavigation) DefaultNotification(com.github.appreciated.app.layout.builder.entities.DefaultNotification) WebServlet(javax.servlet.annotation.WebServlet) Consumer(java.util.function.Consumer) AppLayoutComponent(com.github.appreciated.app.layout.behaviour.AppLayoutComponent) com.vaadin.annotations(com.vaadin.annotations) MenuHeader(com.github.appreciated.app.layout.component.MenuHeader) DefaultBadgeHolder(com.github.appreciated.app.layout.builder.entities.DefaultBadgeHolder) AppLayout(com.github.appreciated.app.layout.AppLayout) View(com.vaadin.navigator.View) com.vaadin.ui(com.vaadin.ui) MenuHeader(com.github.appreciated.app.layout.component.MenuHeader) ThemeResource(com.vaadin.server.ThemeResource) DefaultViewNameInterceptor(com.github.appreciated.app.layout.interceptor.DefaultViewNameInterceptor) AppBarNotificationButton(com.github.appreciated.app.layout.component.button.AppBarNotificationButton) AppLayoutComponent(com.github.appreciated.app.layout.behaviour.AppLayoutComponent)

Example 3 with AppLayoutComponent

use of com.github.appreciated.app.layout.behaviour.AppLayoutComponent in project vaadin-app-layout by appreciated.

the class DemoUI method init.

// @Autowired
// SpringNavigator navigator;
public void init(VaadinRequest request) {
    DefaultNotificationHolder notifications = new DefaultNotificationHolder();
    DefaultBadgeHolder badge = new DefaultBadgeHolder();
    AppLayoutComponent layout = AppLayout.getCDIBuilder(Behaviour.LEFT_RESPONSIVE_HYBRID).withViewProvider(() -> viewProvider).withNavigationElementInfoProvider(new DefaultSpringNavigationElementInfoProvider()).withTitle("App Layout Basic Example").addToAppBar(new AppBarNotificationButton(notifications, true)).withDesign(AppLayoutDesign.MATERIAL).withNavigatorConsumer(navigator -> {
    /* Do something with it */
    }).add(new MenuHeader("Version 0.9.21", new ThemeResource("logo.png")), HEADER).add("Home", VaadinIcons.HOME, badge, View1.class).add(SubmenuBuilder.get("My Submenu", VaadinIcons.PLUS).add("Charts", VaadinIcons.SPLINE_CHART, View2.class).add("Contact", VaadinIcons.CONNECT, View3.class).add("More", VaadinIcons.COG, View4.class).build()).add("Menu", VaadinIcons.MENU, View5.class).add("Elements", VaadinIcons.LIST, View6.class).build();
    setContent(layout);
}
Also used : DefaultSpringNavigationElementInfoProvider(com.github.appreciated.app.layout.builder.providers.DefaultSpringNavigationElementInfoProvider) DefaultBadgeHolder(com.github.appreciated.app.layout.builder.entities.DefaultBadgeHolder) MenuHeader(com.github.appreciated.app.layout.component.MenuHeader) DefaultNotificationHolder(com.github.appreciated.app.layout.builder.entities.DefaultNotificationHolder) ThemeResource(com.vaadin.server.ThemeResource) AppBarNotificationButton(com.github.appreciated.app.layout.component.button.AppBarNotificationButton) AppLayoutComponent(com.github.appreciated.app.layout.behaviour.AppLayoutComponent)

Aggregations

AppLayoutComponent (com.github.appreciated.app.layout.behaviour.AppLayoutComponent)3 Behaviour (com.github.appreciated.app.layout.behaviour.Behaviour)2 AppLayoutDesign (com.github.appreciated.app.layout.builder.design.AppLayoutDesign)2 DefaultBadgeHolder (com.github.appreciated.app.layout.builder.entities.DefaultBadgeHolder)2 DefaultNotificationHolder (com.github.appreciated.app.layout.builder.entities.DefaultNotificationHolder)2 MenuHeader (com.github.appreciated.app.layout.component.MenuHeader)2 AppBarNotificationButton (com.github.appreciated.app.layout.component.button.AppBarNotificationButton)2 View (com.vaadin.navigator.View)2 ThemeResource (com.vaadin.server.ThemeResource)2 Consumer (java.util.function.Consumer)2 AppLayout (com.github.appreciated.app.layout.AppLayout)1 FOOTER (com.github.appreciated.app.layout.builder.Section.FOOTER)1 HEADER (com.github.appreciated.app.layout.builder.Section.HEADER)1 AbstractNavigationElement (com.github.appreciated.app.layout.builder.elements.AbstractNavigationElement)1 NavigatorNavigationElement (com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement)1 SectionNavigationElement (com.github.appreciated.app.layout.builder.elements.SectionNavigationElement)1 SubmenuNavigationElement (com.github.appreciated.app.layout.builder.elements.SubmenuNavigationElement)1 SubmenuBuilder (com.github.appreciated.app.layout.builder.elements.builders.SubmenuBuilder)1 DefaultNotification (com.github.appreciated.app.layout.builder.entities.DefaultNotification)1 MEDIUM (com.github.appreciated.app.layout.builder.entities.DefaultNotification.Priority.MEDIUM)1