Search in sources :

Example 1 with ThemeConstantsRepository

use of com.haulmont.cuba.gui.theme.ThemeConstantsRepository in project cuba by cuba-platform.

the class App method initTheme.

protected void initTheme() throws Exception {
    DesktopConfig config = configuration.getConfig(DesktopConfig.class);
    String themeName = config.getTheme();
    DesktopThemeLoader desktopThemeLoader = AppBeans.get(DesktopThemeLoader.NAME);
    theme = desktopThemeLoader.loadTheme(themeName);
    theme.init();
    ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME);
    ThemeConstants uiTheme = themeRepository.getConstants(themeName);
    if (uiTheme == null) {
        throw new IllegalStateException("Unable to use theme constants '" + themeName + "'");
    }
    this.themeConstants = uiTheme;
}
Also used : ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) DesktopThemeLoader(com.haulmont.cuba.desktop.theme.DesktopThemeLoader) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository)

Example 2 with ThemeConstantsRepository

use of com.haulmont.cuba.gui.theme.ThemeConstantsRepository in project cuba by cuba-platform.

the class CubaUIProvider method getTheme.

@Override
public String getTheme(UICreateEvent event) {
    // get theme from cookies before app ui initialized for smooth theme enabling
    WebConfig webConfig = configuration.getConfig(WebConfig.class);
    GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
    String appWindowTheme = webConfig.getAppWindowTheme();
    String userAppTheme = getCookieValue(event.getRequest().getCookies(), App.APP_THEME_COOKIE_PREFIX + globalConfig.getWebContextName());
    if (userAppTheme != null) {
        if (!Objects.equals(userAppTheme, appWindowTheme)) {
            // check theme support
            ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME);
            Set<String> supportedThemes = themeRepository.getAvailableThemes();
            if (supportedThemes.contains(userAppTheme)) {
                return userAppTheme;
            }
        }
    }
    return super.getTheme(event);
}
Also used : GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) WebConfig(com.haulmont.cuba.web.WebConfig)

Example 3 with ThemeConstantsRepository

use of com.haulmont.cuba.gui.theme.ThemeConstantsRepository in project cuba by cuba-platform.

the class SettingsWindow method init.

@Override
public void init(Map<String, Object> params) {
    Boolean changeThemeEnabledParam = (Boolean) params.get("changeThemeEnabled");
    if (changeThemeEnabledParam != null) {
        changeThemeEnabled = changeThemeEnabledParam;
    }
    AppWorkArea.Mode mode = userSettingsTools.loadAppWindowMode();
    msgTabbed = getMessage("modeTabbed");
    msgSingle = getMessage("modeSingle");
    modeOptions.setOptionsList(Arrays.asList(msgTabbed, msgSingle));
    if (mode == AppWorkArea.Mode.TABBED)
        modeOptions.setValue(msgTabbed);
    else
        modeOptions.setValue(msgSingle);
    ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME);
    Set<String> supportedThemes = themeRepository.getAvailableThemes();
    appThemeField.setOptionsList(new ArrayList<>(supportedThemes));
    String userAppTheme = userSettingsTools.loadAppWindowTheme();
    appThemeField.setValue(userAppTheme);
    ComboBox vAppThemeField = (ComboBox) WebComponentsHelper.unwrap(appThemeField);
    vAppThemeField.setTextInputAllowed(false);
    appThemeField.setEditable(changeThemeEnabled);
    initTimeZoneFields();
    User user = userSession.getUser();
    changePasswordBtn.setAction(new BaseAction("changePassw").withCaption(getMessage("changePassw")).withHandler(event -> {
        Window passwordDialog = openWindow("sec$User.changePassword", OpenType.DIALOG, ParamsMap.of("currentPasswordRequired", true));
        passwordDialog.addCloseListener(actionId -> {
            // move focus back to window
            changePasswordBtn.requestFocus();
        });
    }));
    if (!user.equals(userSession.getCurrentOrSubstitutedUser()) || ExternalUserCredentials.isLoggedInWithExternalAuth(userSession)) {
        changePasswordBtn.setEnabled(false);
    }
    Map<String, Locale> locales = globalConfig.getAvailableLocales();
    TreeMap<String, Object> options = new TreeMap<>();
    for (Map.Entry<String, Locale> entry : locales.entrySet()) {
        options.put(entry.getKey(), messages.getTools().localeToString(entry.getValue()));
    }
    appLangField.setOptionsMap(options);
    appLangField.setValue(userManagementService.loadOwnLocale());
    Action commitAction = new BaseAction("commit").withCaption(messages.getMainMessage("actions.Ok")).withShortcut(clientConfig.getCommitShortcut()).withHandler(event -> commit());
    addAction(commitAction);
    okBtn.setAction(commitAction);
    cancelBtn.setAction(new BaseAction("cancel").withCaption(messages.getMainMessage("actions.Cancel")).withHandler(event -> cancel()));
    initDefaultScreenField();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) MenuConfig(com.haulmont.cuba.gui.config.MenuConfig) UserSettingsTools(com.haulmont.cuba.web.app.UserSettingsTools) ComboBox(com.vaadin.ui.ComboBox) ParamsMap(com.haulmont.bali.util.ParamsMap) AppBeans(com.haulmont.cuba.core.global.AppBeans) CollectionUtils(org.apache.commons.collections4.CollectionUtils) UserSession(com.haulmont.cuba.security.global.UserSession) Inject(javax.inject.Inject) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) ClientType(com.haulmont.cuba.core.global.ClientType) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) UserSettingService(com.haulmont.cuba.security.app.UserSettingService) TimeZones(com.haulmont.cuba.core.global.TimeZones) App(com.haulmont.cuba.web.App) UserManagementService(com.haulmont.cuba.security.app.UserManagementService) User(com.haulmont.cuba.security.entity.User) WebComponentsHelper(com.haulmont.cuba.web.gui.components.WebComponentsHelper) WebConfig(com.haulmont.cuba.web.WebConfig) MenuItem(com.haulmont.cuba.gui.config.MenuItem) ExternalUserCredentials(com.haulmont.cuba.web.security.ExternalUserCredentials) ClientConfig(com.haulmont.cuba.client.ClientConfig) UserTimeZone(com.haulmont.cuba.security.app.UserTimeZone) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) User(com.haulmont.cuba.security.entity.User) ComboBox(com.vaadin.ui.ComboBox) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) ParamsMap(com.haulmont.bali.util.ParamsMap)

Aggregations

ThemeConstantsRepository (com.haulmont.cuba.gui.theme.ThemeConstantsRepository)3 GlobalConfig (com.haulmont.cuba.core.global.GlobalConfig)2 WebConfig (com.haulmont.cuba.web.WebConfig)2 ParamsMap (com.haulmont.bali.util.ParamsMap)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 ClientType (com.haulmont.cuba.core.global.ClientType)1 TimeZones (com.haulmont.cuba.core.global.TimeZones)1 DesktopThemeLoader (com.haulmont.cuba.desktop.theme.DesktopThemeLoader)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)1 AppWorkArea (com.haulmont.cuba.gui.components.mainwindow.AppWorkArea)1 MenuConfig (com.haulmont.cuba.gui.config.MenuConfig)1 MenuItem (com.haulmont.cuba.gui.config.MenuItem)1 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)1 UserManagementService (com.haulmont.cuba.security.app.UserManagementService)1 UserSettingService (com.haulmont.cuba.security.app.UserSettingService)1 UserTimeZone (com.haulmont.cuba.security.app.UserTimeZone)1 User (com.haulmont.cuba.security.entity.User)1