File tree Expand file tree Collapse file tree
src/main/java/com/flowingcode/vaadin/addons/demo Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66 <groupId >com.flowingcode.vaadin.addons.demo</groupId >
77 <artifactId >commons-demo</artifactId >
8- <version >4.1.1 -SNAPSHOT</version >
8+ <version >4.2.0 -SNAPSHOT</version >
99
1010 <name >Commons Demo</name >
1111 <description >Common classes for add-ons demo</description >
Original file line number Diff line number Diff line change 4343import java .util .List ;
4444import java .util .Objects ;
4545import java .util .Optional ;
46+ import java .util .stream .Stream ;
4647import org .slf4j .Logger ;
4748import org .slf4j .LoggerFactory ;
4849
@@ -340,6 +341,15 @@ public void setOrientation(Orientation orientation) {
340341 public static void applyTheme (Element element , boolean useDarkTheme ) {
341342 String theme = useDarkTheme ? "dark" : "" ;
342343 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 ;
343353 }
344354
345355 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