use of com.github.appreciated.app.layout.builder.factories.left.DefaultLeftSubmenuNavigationElementFactory 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;
}
Aggregations