1717
1818import java .util .Objects ;
1919import java .util .UUID ;
20+ import java .util .function .BiConsumer ;
21+ import java .util .function .BiFunction ;
2022
2123import com .vaadin .flow .component .Component ;
2224import com .vaadin .flow .component .dependency .CssImport ;
2325import com .vaadin .flow .component .dependency .JsModule ;
2426import com .vaadin .flow .component .html .Div ;
25- import com .vaadin .flow .component .icon .Icon ;
2627import com .vaadin .flow .component .icon .VaadinIcon ;
2728import com .vaadin .flow .component .shared .Tooltip ;
2829import com .vaadin .flow .theme .lumo .LumoUtility ;
3940@ JsModule (ChartThemeManager .LOCATION )
4041@ JsModule (ChartControlFunc .LOCATION )
4142@ CssImport (ChartContainerStyles .LOCATION )
43+ @ SuppressWarnings ("java:S1948" ) // UI classes will never be serialized due to security
4244public abstract class ChartContainer extends Div implements ChartCom
4345{
4446 protected Component loading = new DefaultLoadingLoadComponent ();
4547 protected Component error = new DefaultLoadingErrorComponent ();
4648 protected Div chartJSDiv = new Div ();
4749
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 );
4957
5058 protected ChartContainer ()
5159 {
5260 this .loading .addClassName (ChartContainerStyles .LOADING_COMPONENT_CLASS );
5361 this .error .addClassName (ChartContainerStyles .ERROR_COMPONENT_CLASS );
54- this .icoProblemsIndicator .addClassName (ChartContainerStyles .PROBLEM_INDICATOR_CLASS );
62+ this .problemsIndicator .addClassName (ChartContainerStyles .PROBLEM_INDICATOR_CLASS );
5563
5664 this .chartJSDiv .addClassNames (
5765 ChartContainerStyles .DIV_CLASS ,
@@ -67,7 +75,7 @@ protected ChartContainer()
6775
6876 protected String createChartJSDivId ()
6977 {
70- return "chartjsdiv" + UUID .randomUUID ();
78+ return "chartjsdiv- " + UUID .randomUUID ();
7179 }
7280
7381 public String getChartJSDivId ()
@@ -115,9 +123,11 @@ protected void clear(final boolean forDisplayingChart)
115123
116124 public void showProblemsIndicator (final String problemsText )
117125 {
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+ }
121131 }
122132
123133 public void showChart (final String payloadJson )
@@ -139,7 +149,7 @@ protected void tryDestroyChart()
139149
140150 protected void executeJS (final String js )
141151 {
142- this .getElement (). executeJs ( js );
152+ this .executeJsFunc . accept ( this , this . wrapJsFunc . apply ( this , js ) );
143153 }
144154
145155 // region Getter + Setter
@@ -173,14 +183,45 @@ public void setChartJSDiv(final Div chartJSDiv)
173183 this .chartJSDiv = chartJSDiv ;
174184 }
175185
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 ()
177207 {
178- return this .icoProblemsIndicator ;
208+ return this .wrapJsFunc ;
179209 }
180210
181- public void setIcoProblemsIndicator (final Icon icoProblemsIndicator )
211+ public void setWrapJsFunc (final BiFunction < ChartContainer , String , String > wrapJsFunc )
182212 {
183- this .icoProblemsIndicator = icoProblemsIndicator ;
213+ this .wrapJsFunc = Objects . requireNonNull ( wrapJsFunc ) ;
184214 }
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+
185226 // endregion
186227}
0 commit comments