Skip to content

Commit ab41a98

Browse files
javier-godoypaodb
authored andcommitted
chore: add check about legacy theme annotation
1 parent a7f5a80 commit ab41a98

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/main/java/com/flowingcode/vaadin/addons/demo/DynamicTheme.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import com.vaadin.flow.component.Component;
44
import com.vaadin.flow.component.HasElement;
5+
import com.vaadin.flow.component.page.AppShellConfigurator;
56
import com.vaadin.flow.component.page.Inline.Position;
7+
import com.vaadin.flow.server.AppShellRegistry;
68
import com.vaadin.flow.server.AppShellSettings;
9+
import com.vaadin.flow.server.VaadinContext;
10+
import com.vaadin.flow.server.VaadinService;
711
import com.vaadin.flow.server.VaadinSession;
812
import com.vaadin.flow.server.Version;
913
import com.vaadin.flow.server.communication.IndexHtmlResponse;
14+
import com.vaadin.flow.theme.Theme;
1015
import lombok.Getter;
1116
import lombok.RequiredArgsConstructor;
1217
import org.jsoup.nodes.Element;
@@ -74,6 +79,15 @@ public static boolean isFeatureInitialized() {
7479
&& VaadinSession.getCurrent().getAttribute(DynamicTheme.class) != null;
7580
}
7681

82+
private static void assertNotLegacyTheme() {
83+
VaadinContext context = VaadinService.getCurrent().getContext();
84+
Class<? extends AppShellConfigurator> appShellClass =
85+
AppShellRegistry.getInstance(context).getShell();
86+
if (appShellClass != null && appShellClass.getAnnotation(Theme.class) != null) {
87+
throw new IllegalStateException("App shell is configured with legacy @Theme annotation");
88+
}
89+
}
90+
7791
/**
7892
* Return the current dynamic theme.
7993
*
@@ -96,9 +110,12 @@ public static DynamicTheme getCurrent() {
96110
*
97111
* @param settings the application shell settings to be modified
98112
* @throws UnsupportedOperationException if the runtime Vaadin version is older than 25
113+
* @throws IllegalStateException if the {@link AppShellConfigurator} is configured with the legacy
114+
* {@link Theme} annotation
99115
*/
100116
public void initialize(AppShellSettings settings) {
101117
assertFeatureSupported();
118+
assertNotLegacyTheme();
102119

103120
DynamicTheme theme = getCurrent();
104121
if (theme == null) {
@@ -132,6 +149,7 @@ public void initialize(AppShellSettings settings) {
132149
*/
133150
public void initialize(IndexHtmlResponse response) {
134151
assertFeatureSupported();
152+
assertNotLegacyTheme();
135153

136154
DynamicTheme theme = getCurrent();
137155
if (theme == null) {

0 commit comments

Comments
 (0)