Example usage for org.springframework.ui.context HierarchicalThemeSource getParentThemeSource

List of usage examples for org.springframework.ui.context HierarchicalThemeSource getParentThemeSource

Introduction

In this page you can find the example usage for org.springframework.ui.context HierarchicalThemeSource getParentThemeSource.

Prototype

@Nullable
ThemeSource getParentThemeSource();

Source Link

Document

Return the parent of this ThemeSource, or null if none.

Usage

From source file:org.springframework.ui.context.support.UiApplicationContextUtils.java

/**
 * Initialize the ThemeSource for the given application context,
 * autodetecting a bean with the name "themeSource". If no such
 * bean is found, a default (empty) ThemeSource will be used.
 * @param context current application context
 * @return the initialized theme source (will never be {@code null})
 * @see #THEME_SOURCE_BEAN_NAME/*www .j a v a 2  s  .  c o m*/
 */
public static ThemeSource initThemeSource(ApplicationContext context) {
    if (context.containsLocalBean(THEME_SOURCE_BEAN_NAME)) {
        ThemeSource themeSource = context.getBean(THEME_SOURCE_BEAN_NAME, ThemeSource.class);
        // Make ThemeSource aware of parent ThemeSource.
        if (context.getParent() instanceof ThemeSource && themeSource instanceof HierarchicalThemeSource) {
            HierarchicalThemeSource hts = (HierarchicalThemeSource) themeSource;
            if (hts.getParentThemeSource() == null) {
                // Only set parent context as parent ThemeSource if no parent ThemeSource
                // registered already.
                hts.setParentThemeSource((ThemeSource) context.getParent());
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Using ThemeSource [" + themeSource + "]");
        }
        return themeSource;
    } else {
        // Use default ThemeSource to be able to accept getTheme calls, either
        // delegating to parent context's default or to local ResourceBundleThemeSource.
        HierarchicalThemeSource themeSource = null;
        if (context.getParent() instanceof ThemeSource) {
            themeSource = new DelegatingThemeSource();
            themeSource.setParentThemeSource((ThemeSource) context.getParent());
        } else {
            themeSource = new ResourceBundleThemeSource();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Unable to locate ThemeSource with name '" + THEME_SOURCE_BEAN_NAME
                    + "': using default [" + themeSource + "]");
        }
        return themeSource;
    }
}