Skip to content
Merged
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
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