diff --git a/pom.xml b/pom.xml index 99a3994..d7fd2a8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.flowingcode.vaadin.addons.demo commons-demo - 5.2.1-SNAPSHOT + 5.3.0-SNAPSHOT Commons Demo Common classes for add-ons demo diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/DynamicTheme.java b/src/main/java/com/flowingcode/vaadin/addons/demo/DynamicTheme.java index 679d4a0..92fdc47 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/DynamicTheme.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/DynamicTheme.java @@ -2,11 +2,16 @@ import com.vaadin.flow.component.Component; import com.vaadin.flow.component.HasElement; +import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.component.page.Inline.Position; +import com.vaadin.flow.server.AppShellRegistry; import com.vaadin.flow.server.AppShellSettings; +import com.vaadin.flow.server.VaadinContext; +import com.vaadin.flow.server.VaadinService; import com.vaadin.flow.server.VaadinSession; import com.vaadin.flow.server.Version; import com.vaadin.flow.server.communication.IndexHtmlResponse; +import com.vaadin.flow.theme.Theme; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.jsoup.nodes.Element; @@ -74,6 +79,15 @@ public static boolean isFeatureInitialized() { && VaadinSession.getCurrent().getAttribute(DynamicTheme.class) != null; } + private static void assertNotLegacyTheme() { + VaadinContext context = VaadinService.getCurrent().getContext(); + Class appShellClass = + AppShellRegistry.getInstance(context).getShell(); + if (appShellClass != null && appShellClass.getAnnotation(Theme.class) != null) { + throw new IllegalStateException("App shell is configured with legacy @Theme annotation"); + } + } + /** * Return the current dynamic theme. * @@ -96,9 +110,12 @@ public static DynamicTheme getCurrent() { * * @param settings the application shell settings to be modified * @throws UnsupportedOperationException if the runtime Vaadin version is older than 25 + * @throws IllegalStateException if the {@link AppShellConfigurator} is configured with the legacy + * {@link Theme} annotation */ public void initialize(AppShellSettings settings) { assertFeatureSupported(); + assertNotLegacyTheme(); DynamicTheme theme = getCurrent(); if (theme == null) { @@ -132,6 +149,7 @@ public void initialize(AppShellSettings settings) { */ public void initialize(IndexHtmlResponse response) { assertFeatureSupported(); + assertNotLegacyTheme(); DynamicTheme theme = getCurrent(); if (theme == null) { diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java index a8771a3..2f0c22e 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java @@ -45,6 +45,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Stream; import lombok.NonNull; import org.slf4j.Logger; @@ -199,6 +200,17 @@ public void showRouterLayoutContent(HasElement content) { demo.setId("content"); } + Optional.ofNullable(demo.getClass().getAnnotation(Route.class)) + .map(route -> route.value().replaceFirst("^/+", "")) + .filter(Predicate.not(String::isEmpty)).ifPresent(route -> { + StringBuilder prefix = new StringBuilder(); + for (String segment : route.split("/+")) { + prefix.append(segment); + demo.addClassName(prefix.toString()); + prefix.append('-'); + } + }); + if (helperButton != null) { remove(helperButton); helperButton = null;