Search in sources :

Example 1 with NavigatorNavigationElement

use of com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement in project vaadin-app-layout by appreciated.

the class AppLayoutConfiguration method prepareNavigationElement.

private void prepareNavigationElement(AbstractNavigationElement element) {
    if (element instanceof HasCaptionInterceptor) {
        ((HasCaptionInterceptor) element).setCaptionInterceptor(captionInterceptor);
    }
    if (element instanceof NavigatorNavigationElement) {
        NavigatorNavigationElement nElement = (NavigatorNavigationElement) element;
        nElement.setCDI(isCDI);
        nElement.setNavigationElementInfoProvider(navigationElementInfoProvider);
        if ((isCDI == false && nElement.getViewClassName() == defaultNavigationElement.getViewClassName()) || (isCDI == true && nElement.getViewName().equals(""))) {
            AppLayoutSessionHelper.updateActiveElementSessionData(nElement);
        }
        nElement.setViewNameInterceptor(viewNameInterceptor);
        if (isNavigatorEnabled) {
            nElement.addViewToNavigator(navigator);
        } else {
            nElement.addViewToComponentNavigator(componentNavigator);
        }
        navigatorElements.add(nElement);
    } else if (element instanceof SubmenuNavigationElement) {
        SubmenuNavigationElement sElement = (SubmenuNavigationElement) element;
        sElement.getSubmenuElements().forEach(element1 -> prepareNavigationElement(element1));
    }
}
Also used : 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) NavigatorNavigationElement(com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement) SubmenuNavigationElement(com.github.appreciated.app.layout.builder.elements.SubmenuNavigationElement) HasCaptionInterceptor(com.github.appreciated.app.layout.builder.interfaces.HasCaptionInterceptor)

Example 2 with NavigatorNavigationElement

use of com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement 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 3 with NavigatorNavigationElement

use of com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement in project vaadin-app-layout by appreciated.

the class DefaultTopSubmenuNavigationElementFactory method addToMenuBar.

private void addToMenuBar(MenuBar menuBar, AbstractNavigationElement element) {
    if (element instanceof SubmenuNavigationElement) {
        SubmenuNavigationElement submenu = (SubmenuNavigationElement) element;
        MenuBar.MenuItem submenuItem = menuBar.addItem(submenu.getTitle(), submenu.getIcon(), null);
        submenu.getSubmenuElements().forEach(element1 -> {
            addToMenuBar(submenuItem, element1);
        });
    }
    if (element instanceof NavigatorNavigationElement) {
        NavigatorNavigationElement submenu = (NavigatorNavigationElement) element;
        menuBar.addItem(submenu.getCaption(), submenu.getIcon(), menuItem -> UI.getCurrent().getNavigator().navigateTo(submenu.getViewName()));
    }
    if (element instanceof ClickableNavigationElement) {
        ClickableNavigationElement submenu = (ClickableNavigationElement) element;
        menuBar.addItem(submenu.getName(), submenu.getIcon(), menuItem -> submenu.getListener().buttonClick(null));
    }
}
Also used : NavigatorNavigationElement(com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement) ClickableNavigationElement(com.github.appreciated.app.layout.builder.elements.ClickableNavigationElement) SubmenuNavigationElement(com.github.appreciated.app.layout.builder.elements.SubmenuNavigationElement) MenuBar(com.vaadin.ui.MenuBar)

Example 4 with NavigatorNavigationElement

use of com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement in project vaadin-app-layout by appreciated.

the class DefaultTopSubmenuNavigationElementFactory method addToMenuBar.

private void addToMenuBar(MenuBar.MenuItem menuBar, AbstractNavigationElement element) {
    if (element instanceof SubmenuNavigationElement) {
        SubmenuNavigationElement submenu = (SubmenuNavigationElement) element;
        MenuBar.MenuItem submenuItem = menuBar.addItem(submenu.getTitle(), submenu.getIcon(), null);
        submenu.getSubmenuElements().forEach(element1 -> {
            addToMenuBar(submenuItem, element1);
        });
    }
    if (element instanceof NavigatorNavigationElement) {
        NavigatorNavigationElement submenu = (NavigatorNavigationElement) element;
        menuBar.addItem(submenu.getCaption(), submenu.getIcon(), menuItem -> UI.getCurrent().getNavigator().navigateTo(submenu.getViewName()));
    }
    if (element instanceof ClickableNavigationElement) {
        ClickableNavigationElement submenu = (ClickableNavigationElement) element;
        menuBar.addItem(submenu.getName(), submenu.getIcon(), menuItem -> submenu.getListener().buttonClick(null));
    }
}
Also used : NavigatorNavigationElement(com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement) ClickableNavigationElement(com.github.appreciated.app.layout.builder.elements.ClickableNavigationElement) SubmenuNavigationElement(com.github.appreciated.app.layout.builder.elements.SubmenuNavigationElement) MenuBar(com.vaadin.ui.MenuBar)

Aggregations

NavigatorNavigationElement (com.github.appreciated.app.layout.builder.elements.NavigatorNavigationElement)4 SubmenuNavigationElement (com.github.appreciated.app.layout.builder.elements.SubmenuNavigationElement)4 AppLayoutComponent (com.github.appreciated.app.layout.behaviour.AppLayoutComponent)2 Behaviour (com.github.appreciated.app.layout.behaviour.Behaviour)2 AppLayoutDesign (com.github.appreciated.app.layout.builder.design.AppLayoutDesign)2 AbstractNavigationElement (com.github.appreciated.app.layout.builder.elements.AbstractNavigationElement)2 ClickableNavigationElement (com.github.appreciated.app.layout.builder.elements.ClickableNavigationElement)2 SectionNavigationElement (com.github.appreciated.app.layout.builder.elements.SectionNavigationElement)2 NavigationElementInfo (com.github.appreciated.app.layout.builder.entities.NavigationElementInfo)2 DefaultLeftClickableNavigationElementFactory (com.github.appreciated.app.layout.builder.factories.left.DefaultLeftClickableNavigationElementFactory)2 DefaultLeftNavigationBadgeElementComponentFactory (com.github.appreciated.app.layout.builder.factories.left.DefaultLeftNavigationBadgeElementComponentFactory)2 DefaultLeftSectionElementComponentFactory (com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSectionElementComponentFactory)2 DefaultLeftSubmenuNavigationElementFactory (com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSubmenuNavigationElementFactory)2 DefaultTopSubmenuNavigationElementFactory (com.github.appreciated.app.layout.builder.factories.top.DefaultTopSubmenuNavigationElementFactory)2 ComponentFactory (com.github.appreciated.app.layout.builder.interfaces.ComponentFactory)2 Factory (com.github.appreciated.app.layout.builder.interfaces.Factory)2 HasCaptionInterceptor (com.github.appreciated.app.layout.builder.interfaces.HasCaptionInterceptor)2 NavigationElementComponent (com.github.appreciated.app.layout.builder.interfaces.NavigationElementComponent)2 ComponentNavigator (com.github.appreciated.app.layout.navigator.ComponentNavigator)2 AppLayoutSessionHelper (com.github.appreciated.app.layout.session.AppLayoutSessionHelper)2