diff --git a/modules/web/src/com/haulmont/addon/helium/web/screens/settings/ThemeSettingsScreen.java b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/ThemeSettingsScreen.java new file mode 100644 index 0000000..c02ba8a --- /dev/null +++ b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/ThemeSettingsScreen.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2008-2020 Haulmont. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.haulmont.addon.helium.web.screens.settings; + +import com.haulmont.addon.helium.web.theme.HeliumThemeVariantsManager; +import com.haulmont.cuba.core.global.Metadata; +import com.haulmont.cuba.gui.Notifications; +import com.haulmont.cuba.gui.Route; +import com.haulmont.cuba.gui.components.*; +import com.haulmont.cuba.gui.components.data.table.ContainerTableItems; +import com.haulmont.cuba.gui.model.CollectionContainer; +import com.haulmont.cuba.gui.model.DataComponents; +import com.haulmont.cuba.gui.screen.*; +import com.haulmont.cuba.security.entity.User; +import com.haulmont.cuba.web.app.UserSettingsTools; +import com.vaadin.server.Page; +import org.apache.commons.collections4.CollectionUtils; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Route("helium-theme-settings") +@UiController("helium_ThemeSettingsScreen") +@UiDescriptor("theme-settings-screen.xml") +public class ThemeSettingsScreen extends Screen { + + protected static final int SAMPLE_DATA_SIZE = 10; + + @Inject + protected RadioButtonGroup modeField; + @Inject + protected RadioButtonGroup sizeField; + + @Inject + protected GroupBoxLayout previewBox; + @Inject + protected ScrollBoxLayout innerPreviewBox; + + @Inject + private Table table; + @Inject + private LookupField requiredLookupField; + @Inject + private LookupField lookupField; + @Inject + private RadioButtonGroup radioButtonGroup; + @Inject + private CheckBoxGroup checkBoxGroup; + + @Inject + protected HeliumThemeVariantsManager variantsManager; + + @Inject + private Metadata metadata; + @Inject + private DataComponents dataComponents; + @Inject + protected UserSettingsTools userSettingsTools; + @Inject + private MessageBundle messageBundle; + @Inject + private Notifications notifications; + + protected String appWindowTheme; + protected boolean settingsAvailable; + + @Subscribe + public void onInit(InitEvent event) { + checkSettingsAvailable(); + + if (settingsAvailable) { + appWindowTheme = userSettingsTools.loadAppWindowTheme(); + + initModeField(); + initSizeField(); + initTableSample(); + initOptions(); + } + } + + @Subscribe + public void onAfterShow(AfterShowEvent event) { + if (!settingsAvailable) { + notifications.create() + .withCaption(messageBundle.getMessage("noSettingsAvailable")) + .withType(Notifications.NotificationType.WARNING) + .show(); + + close(WINDOW_CLOSE_ACTION); + } + } + + protected void checkSettingsAvailable() { + List appThemeModeList = variantsManager.getAppThemeModeList(); + List appThemeSizeList = variantsManager.getAppThemeSizeList(); + + settingsAvailable = CollectionUtils.isNotEmpty(appThemeModeList) + || CollectionUtils.isNotEmpty(appThemeSizeList); + } + + protected void initTableSample() { + CollectionContainer container = dataComponents.createCollectionContainer(User.class); + container.setItems(generateUsersSampleData()); + table.setItems(new ContainerTableItems<>(container)); + } + + protected List generateUsersSampleData() { + List users = new ArrayList<>(SAMPLE_DATA_SIZE); + for (int i = 0; i < SAMPLE_DATA_SIZE; i++) { + users.add(createUser(i)); + } + return users; + } + + protected User createUser(int index) { + User user = metadata.create(User.class); + user.setLogin("user" + index); + user.setName("User " + index); + user.setActive(index % 2 == 0); + + return user; + } + + protected void initOptions() { + List options = generateSampleOptions(); + checkBoxGroup.setOptionsList(options); + radioButtonGroup.setOptionsList(options); + lookupField.setOptionsList(options); + requiredLookupField.setOptionsList(options); + } + + protected List generateSampleOptions() { + return Arrays.asList("Option 1", "Options 2", "Option 3"); + } + + protected void initModeField() { + modeField.setOptionsList(variantsManager.getAppThemeModeList()); + modeField.setValue(variantsManager.loadUserAppThemeModeSettingOrDefault()); + } + + protected void initSizeField() { + sizeField.setOptionsList(variantsManager.getAppThemeSizeList()); + sizeField.setValue(variantsManager.loadUserAppThemeSizeSettingOrDefault()); + } + + @Subscribe("applyBtn") + public void onApplyBtnClick(Button.ClickEvent event) { + applyThemeMode(); + applyThemeSize(); + + Page.getCurrent().reload(); + } + + protected void applyThemeMode() { + String mode = modeField.getValue(); + variantsManager.setUserAppThemeMode(mode); + } + + protected void applyThemeSize() { + String size = sizeField.getValue(); + variantsManager.setUserAppThemeSize(size); + } + + @Subscribe("modeField") + public void onModeFieldValueChange(HasValue.ValueChangeEvent event) { + previewBox.setStyleName(appWindowTheme + " " + modeField.getValue()); + } + + @Subscribe("sizeField") + public void onSizeFieldValueChange(HasValue.ValueChangeEvent event) { + innerPreviewBox.setStyleName(sizeField.getValue()); + } +} \ No newline at end of file diff --git a/modules/web/src/com/haulmont/addon/helium/web/screens/settings/messages.properties b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/messages.properties new file mode 100644 index 0000000..38008c2 --- /dev/null +++ b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/messages.properties @@ -0,0 +1,24 @@ +# +# Copyright (c) 2008-2020 Haulmont. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +caption=Theme Settings + +applyBtn.caption=Apply +modeField.caption=Mode: +sizeField.caption=Size: +previewBox.caption=Preview + +noSettingsAvailable=No settings available for the current theme \ No newline at end of file diff --git a/modules/web/src/com/haulmont/addon/helium/web/screens/settings/messages_ru.properties b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/messages_ru.properties new file mode 100644 index 0000000..ebbd7c9 --- /dev/null +++ b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/messages_ru.properties @@ -0,0 +1,24 @@ +# +# Copyright (c) 2008-2020 Haulmont. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +caption=Настройки темы + +applyBtn.caption=Применить +modeField.caption=Режим: +sizeField.caption=Размер: +previewBox.caption=Предварительный просмотр + +noSettingsAvailable=Для текущей темы нет доступных настроек \ No newline at end of file diff --git a/modules/web/src/com/haulmont/addon/helium/web/screens/settings/theme-settings-screen.xml b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/theme-settings-screen.xml new file mode 100644 index 0000000..171a7e2 --- /dev/null +++ b/modules/web/src/com/haulmont/addon/helium/web/screens/settings/theme-settings-screen.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + +