|
2 | 2 | * #%L |
3 | 3 | * Error Window Add-on |
4 | 4 | * %% |
5 | | - * Copyright (C) 2017 - 2023 Flowing Code |
| 5 | + * Copyright (C) 2017 - 2024 Flowing Code |
6 | 6 | * %% |
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | * you may not use this file except in compliance with the License. |
|
30 | 30 | import com.vaadin.flow.component.upload.Upload; |
31 | 31 | import com.vaadin.flow.router.PageTitle; |
32 | 32 | import com.vaadin.flow.router.Route; |
| 33 | +import java.util.Optional; |
33 | 34 |
|
34 | 35 | @DemoSource |
35 | 36 | @PageTitle("Error Window Demo") |
@@ -102,9 +103,10 @@ public ErrorwindowDemo() { |
102 | 103 | }); |
103 | 104 |
|
104 | 105 | Checkbox productionModeCb = new Checkbox("Production Mode"); |
| 106 | + productionModeCb.setValue(getProductionMode()); |
105 | 107 | productionModeCb.addValueChangeListener( |
106 | 108 | e -> { |
107 | | - System.setProperty("productionMode", "" + productionModeCb.getValue().toString()); |
| 109 | + setProductionMode(e.getValue()); |
108 | 110 | Notification.show( |
109 | 111 | "Currently production mode is: " + System.getProperty("productionMode")); |
110 | 112 | }); |
@@ -135,4 +137,16 @@ public ErrorwindowDemo() { |
135 | 137 | add(upload); |
136 | 138 |
|
137 | 139 | } |
| 140 | + |
| 141 | + private boolean getProductionMode() { |
| 142 | + return Optional.ofNullable(System.getProperty("errorWindowProductionMode")) |
| 143 | + .map(Boolean::valueOf).orElseGet(() -> { |
| 144 | + setProductionMode(true); |
| 145 | + return Boolean.TRUE; |
| 146 | + }); |
| 147 | + } |
| 148 | + |
| 149 | + private void setProductionMode(boolean mode) { |
| 150 | + System.setProperty("errorWindowProductionMode", Boolean.toString(mode)); |
| 151 | + } |
138 | 152 | } |
0 commit comments