Skip to content
l0rdn1kk0n edited this page Jul 22, 2012 · 9 revisions

By default wicket-bootstrap uses the BootswatchThemeProvider, which provides access to all free bootswatch themes (link), and the SessionThemeProvider, which uses the Session to store and read the active theme.

superhero theme

Usage

All theme specific css files will be rendered automatically by BootstrapBaseBahavior. You can access the available themes by calling List<Theme> Bootstrap.getSettings(application).getThemeProvider().available(). If you want to change the active theme just update the ActiveThemeProvider by calling Bootstrap.getSettings(application).getActiveThemeProvider().setActiveTheme(theme or theme name).

Create Theme Button Component

IBootstrapSettings settings = Bootstrap.getSettings(getApplication());
List<Theme> themes = settings.getThemeProvider().available();
for (Theme theme : themes) {
       PageParameters params = new PageParameters();
       params.set("theme", theme.name());
       dropdown.addMenuButton(new MenuPageButton<Page>(getPage().getPageClass(), params, Model.of(theme.name())));
}

Updating active theme

StringValue theme = pageParameters.get("theme");
if (!theme.isEmpty()) {
    IBootstrapSettings settings = Bootstrap.getSettings(getApplication());
    settings.getActiveThemeProvider().setActiveTheme(theme.toString(""));
}

Theme Provider

public interface ThemeProvider {

    /**
     * returns a theme by its name. If
     *
     * @param name The name of the theme
     * @return the theme according to given name
     */
    Theme byName(final String name);

    /**
     * @return a list of all available themes
     */
    List<Theme> available();

    /**
     * @return the default theme
     */
    Theme defaultTheme();
}

Active Theme Provider

public interface ActiveThemeProvider {

    /**
     * returns the current active theme (can be user/session scoped). If none is
     * set a default theme should be returned (implementation specific).
     * There is a session scoped implementation: {@code SessionThemeProvider}
     *
     * @return the current active theme
     */
    Theme getActiveTheme();

    /**
     * sets the active theme by its name. 
     * 
     * @param themeName the theme name
     */
    void setActiveTheme(String themeName);

    /**
     * sets the active theme
     * 
     * @param theme the theme to set
     */
    void setActiveTheme(Theme theme);
}
Clone this wiki locally