Skip to content

Commit

Permalink
Revert Theme Settings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
glebfox committed Aug 4, 2021
1 parent 4fcda87 commit 272451e
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> modeField;
@Inject
protected RadioButtonGroup<String> sizeField;

@Inject
protected GroupBoxLayout previewBox;
@Inject
protected ScrollBoxLayout innerPreviewBox;

@Inject
private Table<User> table;
@Inject
private LookupField<String> requiredLookupField;
@Inject
private LookupField<String> lookupField;
@Inject
private RadioButtonGroup<String> radioButtonGroup;
@Inject
private CheckBoxGroup<String> 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<String> appThemeModeList = variantsManager.getAppThemeModeList();
List<String> appThemeSizeList = variantsManager.getAppThemeSizeList();

settingsAvailable = CollectionUtils.isNotEmpty(appThemeModeList)
|| CollectionUtils.isNotEmpty(appThemeSizeList);
}

protected void initTableSample() {
CollectionContainer<User> container = dataComponents.createCollectionContainer(User.class);
container.setItems(generateUsersSampleData());
table.setItems(new ContainerTableItems<>(container));
}

protected List<User> generateUsersSampleData() {
List<User> 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<String> options = generateSampleOptions();
checkBoxGroup.setOptionsList(options);
radioButtonGroup.setOptionsList(options);
lookupField.setOptionsList(options);
requiredLookupField.setOptionsList(options);
}

protected List<String> 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<String> event) {
previewBox.setStyleName(appWindowTheme + " " + modeField.getValue());
}

@Subscribe("sizeField")
public void onSizeFieldValueChange(HasValue.ValueChangeEvent<String> event) {
innerPreviewBox.setStyleName(sizeField.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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=Для текущей темы нет доступных настроек
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ 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.
-->

<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
caption="msg://caption"
messagesPack="com.haulmont.addon.helium.web.screens.settings">
<layout expand="previewBox" spacing="true">
<hbox id="settingsForm" spacing="true">
<label id="modeLabel"
align="MIDDLE_LEFT"
stylename="bold"
value="msg://modeField.caption"/>
<radioButtonGroup id="modeField"
align="MIDDLE_LEFT"
orientation="horizontal"/>

<label id="separator"
align="MIDDLE_CENTER"
css="margin: 0 10px 0 10px"
value="|"/>

<label id="sizeLabel"
align="MIDDLE_LEFT"
stylename="bold"
value="msg://sizeField.caption"/>
<radioButtonGroup id="sizeField"
align="MIDDLE_LEFT"
orientation="horizontal"/>
</hbox>

<groupBox id="previewBox" caption="msg://previewBox.caption" width="100%">
<scrollBox id="innerPreviewBox" height="100%" width="100%" spacing="true">
<flowBox spacing="true">
<vbox id="buttonsBox" margin="true" stylename="card" width="450px" height="250px">
<vbox spacing="true" align="MIDDLE_CENTER" width="AUTO">
<hbox spacing="true">
<button caption="OK" icon="OK" stylename="primary" description="Primary"/>
<button caption="Cancel" icon="CANCEL" description="Default"/>
</hbox>
<hbox spacing="true">
<button caption="Save" icon="SAVE" stylename="friendly" description="Friendly"/>
<button caption="Remove" icon="REMOVE" stylename="danger" description="Danger"/>
<button caption="Secondary" stylename="secondary" description="Secondary"/>
</hbox>
</vbox>
</vbox>
<vbox id="textFieldsBox" margin="true" stylename="card" width="350px" height="250px">
<vbox spacing="true" align="MIDDLE_CENTER" width="AUTO">
<textField caption="TextField" inputPrompt="Placeholder"/>
<textField caption="TextField | Required" required="true"/>
</vbox>
</vbox>
<vbox id="checkBoxGroupBox" margin="true" stylename="card" width="250px" height="250px">
<checkBoxGroup id="checkBoxGroup" align="MIDDLE_CENTER"/>
</vbox>
<vbox id="lookupFieldsBox" margin="true" stylename="card" width="350px" height="250px">
<vbox spacing="true" align="MIDDLE_CENTER" width="AUTO">
<lookupField id="lookupField"
caption="LookupField"
inputPrompt="Placeholder"/>
<lookupField id="requiredLookupField"
caption="LookupField | Required"
required="true"/>
</vbox>
</vbox>
<vbox id="radioButtonGroupBox" margin="true" stylename="card" width="250px" height="250px">
<radioButtonGroup id="radioButtonGroup" align="MIDDLE_CENTER"/>
</vbox>
<vbox id="tabSheetsBox" margin="true" stylename="card" width="300px" height="300px">
<vbox spacing="true" align="MIDDLE_CENTER">
<tabSheet height="100px" width="100%">
<tab id="tab11"
caption="Tab 1"/>
<tab id="tab12"
caption="Tab 2"/>
<tab id="tab13"
caption="Tab 3"/>
</tabSheet>
<tabSheet height="100px" width="100%" stylename="framed">
<tab id="tab21"
caption="Tab 1"/>
<tab id="tab22"
caption="Tab 2"/>
<tab id="tab23"
caption="Tab 3"/>
</tabSheet>
</vbox>
</vbox>
<vbox id="tableBox" margin="true" stylename="card" width="450px" height="300px">
<table id="table" metaClass="sec$User" height="100%" width="100%">
<columns>
<column id="login"/>
<column id="name"/>
<column id="active"/>
</columns>
</table>
</vbox>
<vbox id="labelsBox" margin="true" stylename="card" width="300px" height="350px">
<vbox spacing="true" align="MIDDLE_CENTER">
<label value="Header 1" stylename="h1"/>
<label value="Header 2" stylename="h2"/>
<label value="Header 3" stylename="h3"/>
<label value="Header 4" stylename="h4"/>
<label value="Lorem ipsum dolor sit amet, consectetur adipisicing elit." width="100%"/>
</vbox>
</vbox>
</flowBox>
</scrollBox>
</groupBox>

<button id="applyBtn" caption="msg://applyBtn.caption"/>
</layout>
</window>

0 comments on commit 272451e

Please sign in to comment.