Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.flowingcode.vaadin.addons.demo</groupId>
<artifactId>commons-demo</artifactId>
<version>5.2.1-SNAPSHOT</version>
<version>5.3.0-SNAPSHOT</version>

<name>Commons Demo</name>
<description>Common classes for add-ons demo</description>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/flowingcode/vaadin/addons/demo/DynamicTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +79,15 @@ public static boolean isFeatureInitialized() {
&& VaadinSession.getCurrent().getAttribute(DynamicTheme.class) != null;
}

private static void assertNotLegacyTheme() {
VaadinContext context = VaadinService.getCurrent().getContext();
Class<? extends AppShellConfigurator> 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.
*
Expand All @@ -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) {
Expand Down Expand Up @@ -132,6 +149,7 @@ public void initialize(AppShellSettings settings) {
*/
public void initialize(IndexHtmlResponse response) {
assertFeatureSupported();
assertNotLegacyTheme();

DynamicTheme theme = getCurrent();
if (theme == null) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down