|
1 | 1 | /******************************************************************************* |
2 | 2 | * SORMAS® - Surveillance Outbreak Response Management & Analysis System |
3 | 3 | * Copyright © 2016-2018 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI) |
4 | | - * |
| 4 | + * <p> |
5 | 5 | * This program is free software: you can redistribute it and/or modify |
6 | 6 | * it under the terms of the GNU General Public License as published by |
7 | 7 | * the Free Software Foundation, either version 3 of the License, or |
8 | 8 | * (at your option) any later version. |
9 | | - * |
| 9 | + * <p> |
10 | 10 | * This program is distributed in the hope that it will be useful, |
11 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 13 | * GNU General Public License for more details. |
14 | | - * |
| 14 | + * <p> |
15 | 15 | * You should have received a copy of the GNU General Public License |
16 | 16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
17 | 17 | *******************************************************************************/ |
|
23 | 23 | import java.util.Map; |
24 | 24 |
|
25 | 25 | import org.apache.commons.lang3.StringUtils; |
| 26 | +import org.jetbrains.annotations.NotNull; |
26 | 27 |
|
27 | 28 | import com.vaadin.icons.VaadinIcons; |
28 | 29 | import com.vaadin.navigator.Navigator; |
29 | 30 | import com.vaadin.navigator.View; |
30 | 31 | import com.vaadin.server.FileResource; |
| 32 | +import com.vaadin.server.Page; |
31 | 33 | import com.vaadin.server.Resource; |
32 | 34 | import com.vaadin.server.ThemeResource; |
33 | 35 | import com.vaadin.ui.Alignment; |
|
57 | 59 | /** |
58 | 60 | * Responsive navigation menu presenting a list of available views to the user. |
59 | 61 | */ |
60 | | -@SuppressWarnings("serial") |
61 | 62 | public class Menu extends CssLayout { |
62 | 63 |
|
63 | 64 | private static final String VALO_MENUITEMS = "valo-menuitems"; |
64 | 65 | private static final String VALO_MENU_TOGGLE = "valo-menu-toggle"; |
65 | 66 | private static final String VALO_MENU_VISIBLE = "valo-menu-visible"; |
66 | | - private Navigator navigator; |
67 | | - private Map<String, Button> viewButtons = new HashMap<String, Button>(); |
| 67 | + private static final String BACKGROUND_COLOR_CONFIG_KEY = "MENU_BACKGROUND_COLOR"; |
68 | 68 |
|
69 | | - private CssLayout menuItemsLayout; |
70 | | - private CssLayout menuPart; |
| 69 | + private final Navigator navigator; |
| 70 | + private final Map<String, Button> viewButtons = new HashMap<>(); |
| 71 | + |
| 72 | + private final CssLayout menuItemsLayout; |
| 73 | + private final CssLayout menuPart; |
71 | 74 |
|
72 | 75 | public Menu(Navigator navigator) { |
73 | 76 |
|
74 | 77 | this.navigator = navigator; |
75 | 78 | setPrimaryStyleName(ValoTheme.MENU_ROOT); |
| 79 | + |
| 80 | + defineCustomColorBackgroundIfSystemConfigured(); |
| 81 | + |
76 | 82 | menuPart = new CssLayout(); |
77 | 83 | menuPart.addStyleName(ValoTheme.MENU_PART); |
78 | 84 |
|
@@ -136,14 +142,54 @@ public Menu(Navigator navigator) { |
136 | 142 | addComponent(menuPart); |
137 | 143 | } |
138 | 144 |
|
| 145 | + private void defineCustomColorBackgroundIfSystemConfigured() { |
| 146 | + String backgroundColor = FacadeProvider.getSystemConfigurationValueFacade().getValue(BACKGROUND_COLOR_CONFIG_KEY); |
| 147 | + |
| 148 | + if (StringUtils.isNotBlank(backgroundColor) || "default".equals(backgroundColor)) { |
| 149 | + // no need to configure anything as we can keep the default color. |
| 150 | + return; |
| 151 | + } |
| 152 | + |
| 153 | + addStyleName("color-background"); |
| 154 | + |
| 155 | + String actualColorBackgroundColor = determineActualColor(backgroundColor); |
| 156 | + |
| 157 | + Page.Styles styles = Page.getCurrent().getStyles(); |
| 158 | + styles.add( |
| 159 | + ".valo-menu-color-background {\n" + " background-color: " + actualColorBackgroundColor + " !important;\n" |
| 160 | + + " background-image: -webkit-linear-gradient(right, " + actualColorBackgroundColor + " 0%, #EEFA5F" + actualColorBackgroundColor |
| 161 | + + " 8px) !important;\n" + " background-image: linear-gradient(to left, " + actualColorBackgroundColor + " 0%, " |
| 162 | + + actualColorBackgroundColor + " 8px) !important;" + " }"); |
| 163 | + } |
| 164 | + |
| 165 | + private static @NotNull String determineActualColor(String backgroundColor) { |
| 166 | + String actualColorBackgroundColor; |
| 167 | + switch (backgroundColor) { |
| 168 | + case "green": |
| 169 | + actualColorBackgroundColor = "#108548"; |
| 170 | + break; |
| 171 | + case "red": |
| 172 | + actualColorBackgroundColor = "#dd2b0e"; |
| 173 | + break; |
| 174 | + case "indigo": |
| 175 | + actualColorBackgroundColor = "#7b58cf"; |
| 176 | + break; |
| 177 | + case "gray": |
| 178 | + actualColorBackgroundColor = "#737278"; |
| 179 | + break; |
| 180 | + default: |
| 181 | + actualColorBackgroundColor = backgroundColor; |
| 182 | + } |
| 183 | + return actualColorBackgroundColor; |
| 184 | + } |
| 185 | + |
139 | 186 | private void showSettingsPopup() { |
140 | 187 |
|
141 | 188 | Window window = VaadinUiUtil.createPopupWindow(); |
142 | 189 | window.setCaption(I18nProperties.getString(Strings.headingUserSettings)); |
143 | 190 | window.setModal(true); |
144 | 191 |
|
145 | | - CommitDiscardWrapperComponent<UserSettingsForm> component = |
146 | | - ControllerProvider.getUserController().getUserSettingsComponent(() -> window.close()); |
| 192 | + CommitDiscardWrapperComponent<UserSettingsForm> component = ControllerProvider.getUserController().getUserSettingsComponent(window::close); |
147 | 193 |
|
148 | 194 | window.setContent(component); |
149 | 195 | UI.getCurrent().addWindow(window); |
|
0 commit comments