File tree 3 files changed +23
-1
lines changed
src/main/java/com/flowingcode/vaadin/addons/demo
3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 5
5
6
6
<groupId >com.flowingcode.vaadin.addons.demo</groupId >
7
7
<artifactId >commons-demo</artifactId >
8
- <version >4.1.1 -SNAPSHOT</version >
8
+ <version >4.2.0 -SNAPSHOT</version >
9
9
10
10
<name >Commons Demo</name >
11
11
<description >Common classes for add-ons demo</description >
Original file line number Diff line number Diff line change 43
43
import java .util .List ;
44
44
import java .util .Objects ;
45
45
import java .util .Optional ;
46
+ import java .util .stream .Stream ;
46
47
import org .slf4j .Logger ;
47
48
import org .slf4j .LoggerFactory ;
48
49
@@ -340,6 +341,15 @@ public void setOrientation(Orientation orientation) {
340
341
public static void applyTheme (Element element , boolean useDarkTheme ) {
341
342
String theme = useDarkTheme ? "dark" : "" ;
342
343
element .executeJs ("document.documentElement.setAttribute('theme', $0);" , theme );
344
+
345
+ Component c = element .getComponent ().get ();
346
+ collectThemeChangeObservers (c ).forEach (observer -> observer .onThemeChange (theme ));
347
+ }
348
+
349
+ private static Stream <ThemeChangeObserver > collectThemeChangeObservers (Component c ) {
350
+ Stream <ThemeChangeObserver > children =
351
+ c .getChildren ().flatMap (child -> collectThemeChangeObservers (child ));
352
+ return c instanceof ThemeChangeObserver o ? Stream .concat (Stream .of (o ), children ) : children ;
343
353
}
344
354
345
355
private void updateFooterButtonsVisibility () {
Original file line number Diff line number Diff line change
1
+ package com .flowingcode .vaadin .addons .demo ;
2
+
3
+ /**
4
+ * Any attached component implementing this interface will receive an event when a new theme is
5
+ * applied.
6
+ */
7
+ @ FunctionalInterface
8
+ public interface ThemeChangeObserver {
9
+
10
+ void onThemeChange (String themeName );
11
+
12
+ }
You can’t perform that action at this time.
0 commit comments