use of com.vaadin.flow.theme.NoTheme in project flow by vaadin.
the class FrontendDependencies method computeApplicationTheme.
/*
* Visit all end-points and computes the theme for the application. It fails
* in the case that there are multiple themes for the application or in the
* case of Theme and NoTheme found in the application.
*
* If no theme is found and the application has endpoints, it uses lumo if
* found in the class-path
*/
private void computeApplicationTheme() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
// entry-point visits
for (EndPointData endPoint : endPoints.values()) {
if (endPoint.getLayout() != null) {
visitClass(endPoint.getLayout(), endPoint, false);
}
if (endPoint.getTheme() != null) {
visitClass(endPoint.getTheme().getThemeClass(), endPoint, true);
}
}
Set<ThemeData> themes = endPoints.values().stream().filter(data -> data.getTheme().getThemeClass() != null || (data.getTheme().getThemeName() != null && !data.getTheme().getThemeName().isEmpty()) || data.getTheme().isNotheme()).map(EndPointData::getTheme).collect(Collectors.toSet());
if (themes.size() > 1) {
String names = endPoints.values().stream().filter(data -> data.getTheme().getThemeClass() != null || data.getTheme().getThemeName() != null || data.getTheme().isNotheme()).map(data -> "found '" + (data.getTheme().isNotheme() ? NoTheme.class.getName() : data.getTheme().getThemeName()) + "' in '" + data.getName() + "'").collect(Collectors.joining("\n "));
throw new IllegalStateException("\n Multiple Theme configuration is not supported:\n " + names);
}
Class<? extends AbstractTheme> theme = null;
String variant = "";
String themeName = "";
if (themes.isEmpty()) {
theme = getDefaultTheme();
} else {
// we have a proper theme or no-theme for the app
ThemeData themeData = themes.iterator().next();
if (!themeData.isNotheme()) {
String themeClass = themeData.getThemeClass();
if (!themeData.getThemeName().isEmpty() && themeClass != null) {
throw new IllegalStateException("Theme name and theme class can not both be specified. " + "Theme name uses Lumo and can not be used in combination with custom theme class.");
}
variant = themeData.getVariant();
if (themeClass != null) {
theme = getFinder().loadClass(themeClass);
} else {
theme = getDefaultTheme();
if (theme == null) {
throw new IllegalStateException("Lumo dependency needs to be available on the classpath when using a theme name.");
}
}
themeName = themeData.getThemeName();
}
}
// theme could be null when lumo is not found or when a NoTheme found
if (theme != null) {
themeDefinition = new ThemeDefinition(theme, variant, themeName);
themeInstance = new ThemeWrapper(theme);
}
}
Aggregations