17
17
18
18
import java .util .Objects ;
19
19
import java .util .UUID ;
20
+ import java .util .function .BiConsumer ;
21
+ import java .util .function .BiFunction ;
20
22
21
23
import com .vaadin .flow .component .Component ;
22
24
import com .vaadin .flow .component .dependency .CssImport ;
23
25
import com .vaadin .flow .component .dependency .JsModule ;
24
26
import com .vaadin .flow .component .html .Div ;
25
- import com .vaadin .flow .component .icon .Icon ;
26
27
import com .vaadin .flow .component .icon .VaadinIcon ;
27
28
import com .vaadin .flow .component .shared .Tooltip ;
28
29
import com .vaadin .flow .theme .lumo .LumoUtility ;
39
40
@ JsModule (ChartThemeManager .LOCATION )
40
41
@ JsModule (ChartControlFunc .LOCATION )
41
42
@ CssImport (ChartContainerStyles .LOCATION )
43
+ @ SuppressWarnings ("java:S1948" ) // UI classes will never be serialized due to security
42
44
public abstract class ChartContainer extends Div implements ChartCom
43
45
{
44
46
protected Component loading = new DefaultLoadingLoadComponent ();
45
47
protected Component error = new DefaultLoadingErrorComponent ();
46
48
protected Div chartJSDiv = new Div ();
47
49
48
- protected Icon icoProblemsIndicator = VaadinIcon .WARNING .create ();
50
+ protected Component problemsIndicator = VaadinIcon .WARNING .create ();
51
+
52
+ protected BiConsumer <Component , String > problemsIndicatorToolTipFunc =
53
+ (comp , msg ) -> Tooltip .forComponent (comp ).withText (msg );
54
+ protected BiFunction <ChartContainer , String , String > wrapJsFunc = (self , js ) -> js ;
55
+ protected BiConsumer <ChartContainer , String > executeJsFunc =
56
+ (self , js ) -> self .getElement ().executeJs (js );
49
57
50
58
protected ChartContainer ()
51
59
{
52
60
this .loading .addClassName (ChartContainerStyles .LOADING_COMPONENT_CLASS );
53
61
this .error .addClassName (ChartContainerStyles .ERROR_COMPONENT_CLASS );
54
- this .icoProblemsIndicator .addClassName (ChartContainerStyles .PROBLEM_INDICATOR_CLASS );
62
+ this .problemsIndicator .addClassName (ChartContainerStyles .PROBLEM_INDICATOR_CLASS );
55
63
56
64
this .chartJSDiv .addClassNames (
57
65
ChartContainerStyles .DIV_CLASS ,
@@ -67,7 +75,7 @@ protected ChartContainer()
67
75
68
76
protected String createChartJSDivId ()
69
77
{
70
- return "chartjsdiv" + UUID .randomUUID ();
78
+ return "chartjsdiv- " + UUID .randomUUID ();
71
79
}
72
80
73
81
public String getChartJSDivId ()
@@ -115,9 +123,11 @@ protected void clear(final boolean forDisplayingChart)
115
123
116
124
public void showProblemsIndicator (final String problemsText )
117
125
{
118
- this .add (this .icoProblemsIndicator );
119
- Tooltip .forComponent (this .icoProblemsIndicator )
120
- .withText (problemsText );
126
+ this .add (this .problemsIndicator );
127
+ if (this .problemsIndicatorToolTipFunc != null )
128
+ {
129
+ this .problemsIndicatorToolTipFunc .accept (this .problemsIndicator , problemsText );
130
+ }
121
131
}
122
132
123
133
public void showChart (final String payloadJson )
@@ -139,7 +149,7 @@ protected void tryDestroyChart()
139
149
140
150
protected void executeJS (final String js )
141
151
{
142
- this .getElement (). executeJs ( js );
152
+ this .executeJsFunc . accept ( this , this . wrapJsFunc . apply ( this , js ) );
143
153
}
144
154
145
155
// region Getter + Setter
@@ -173,14 +183,45 @@ public void setChartJSDiv(final Div chartJSDiv)
173
183
this .chartJSDiv = chartJSDiv ;
174
184
}
175
185
176
- public Icon getIcoProblemsIndicator ()
186
+ public Component getProblemsIndicator ()
187
+ {
188
+ return this .problemsIndicator ;
189
+ }
190
+
191
+ public void setProblemsIndicator (final Component problemsIndicator )
192
+ {
193
+ this .problemsIndicator = problemsIndicator ;
194
+ }
195
+
196
+ public BiConsumer <Component , String > getProblemsIndicatorToolTipFunc ()
197
+ {
198
+ return this .problemsIndicatorToolTipFunc ;
199
+ }
200
+
201
+ public void setProblemsIndicatorToolTipFunc (final BiConsumer <Component , String > problemsIndicatorToolTipFunc )
202
+ {
203
+ this .problemsIndicatorToolTipFunc = problemsIndicatorToolTipFunc ;
204
+ }
205
+
206
+ public BiFunction <ChartContainer , String , String > getWrapJsFunc ()
177
207
{
178
- return this .icoProblemsIndicator ;
208
+ return this .wrapJsFunc ;
179
209
}
180
210
181
- public void setIcoProblemsIndicator (final Icon icoProblemsIndicator )
211
+ public void setWrapJsFunc (final BiFunction < ChartContainer , String , String > wrapJsFunc )
182
212
{
183
- this .icoProblemsIndicator = icoProblemsIndicator ;
213
+ this .wrapJsFunc = Objects . requireNonNull ( wrapJsFunc ) ;
184
214
}
215
+
216
+ public BiConsumer <ChartContainer , String > getExecuteJsFunc ()
217
+ {
218
+ return this .executeJsFunc ;
219
+ }
220
+
221
+ public void setExecuteJsFunc (final BiConsumer <ChartContainer , String > executeJsFunc )
222
+ {
223
+ this .executeJsFunc = Objects .requireNonNull (executeJsFunc );
224
+ }
225
+
185
226
// endregion
186
227
}
0 commit comments