implements Serializable {
/** Compact row styling for Vaadin Grid */
// https://cookbook.vaadin.com/grid-dense-theme
- public static final String DENSE_THEME = "fcGh-dense";
+ private static final String DENSE_THEME_NAME = "fcGh-dense";
+
+ /**
+ * Compact row styling for Vaadin Grid.
+ *
+ * @deprecated Use {@link #setDenseTheme(Grid, boolean)} instead. Direct use of this constant
+ * bypasses the bytecode reference to {@code GridHelper}, which prevents the Vaadin production
+ * bundle scanner from discovering the required {@code @CssImport} annotations.
+ */
+ @Deprecated(since = "2.1.0", forRemoval = true)
+ public static final String DENSE_THEME = DENSE_THEME_NAME;
+
+ /**
+ * Adds or removes compact row styling on the given grid.
+ *
+ * Prefer this method over {@code grid.addThemeName(GridHelper.DENSE_THEME)} because it
+ * creates a bytecode reference to {@code GridHelper}, ensuring that the Vaadin production
+ * bundle scanner discovers the required {@code @CssImport} annotations.
+ *
+ * @param grid the grid to style
+ * @param dense {@code true} to enable dense theme, {@code false} to remove it
+ */
+ public static void setDenseTheme(Grid> grid, boolean dense) {
+ if (dense) {
+ grid.addThemeName(DENSE_THEME_NAME);
+ } else {
+ grid.removeThemeName(DENSE_THEME_NAME);
+ }
+ }
+
+ /**
+ * Returns whether the dense theme is currently applied to the given grid.
+ *
+ * @param grid the grid to check
+ * @return {@code true} if the dense theme is applied
+ */
+ public static boolean isDenseTheme(Grid> grid) {
+ return grid.hasThemeName(DENSE_THEME_NAME);
+ }
@Getter(value = AccessLevel.PACKAGE)
private final Grid grid;
diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperServiceInitListener.java b/src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperServiceInitListener.java
deleted file mode 100644
index 25f3be4..0000000
--- a/src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperServiceInitListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * #%L
- * Grid Helpers Add-on
- * %%
- * Copyright (C) 2022 - 2026 Flowing Code
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * #L%
- */
-
-package com.flowingcode.vaadin.addons.gridhelpers;
-
-import com.vaadin.flow.component.dependency.CssImport;
-import com.vaadin.flow.server.ServiceInitEvent;
-import com.vaadin.flow.server.VaadinServiceInitListener;
-
-/**
- * Ensures that the addon's grid styles are always included in the production bundle.
- *
- * {@code VaadinServiceInitListener} subtypes are discovered via ClassGraph reflection and are
- * always treated as entry points, regardless of how consumers use the addon. Placing the
- * {@code @CssImport} annotation here guarantees that the grid styles are included even when
- * {@link GridHelper} is not reachable through bytecode analysis.
- *
- * @see Issue #171
- */
-@CssImport(value = GridHelper.GRID_STYLES, themeFor = "vaadin-grid")
-public class GridHelperServiceInitListener implements VaadinServiceInitListener {
-
- @Override
- public void serviceInit(ServiceInitEvent event) {
- // No initialization needed; this class exists solely to anchor the
- // @CssImport annotation so it is always picked up during the production
- // bundle build via ClassGraph entry-point seeding.
- }
-}
diff --git a/src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener b/src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
deleted file mode 100644
index e483373..0000000
--- a/src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
+++ /dev/null
@@ -1 +0,0 @@
-com.flowingcode.vaadin.addons.gridhelpers.GridHelperServiceInitListener
diff --git a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java
index 3a2f6a1..fad5d65 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java
@@ -263,15 +263,11 @@ private boolean hasSelectionFilter(Grid grid) {
}
private void setDenseTheme(Grid grid, boolean value) {
- if (value) {
- grid.addThemeName(GridHelper.DENSE_THEME);
- } else {
- grid.removeThemeName(GridHelper.DENSE_THEME);
- }
+ GridHelper.setDenseTheme(grid, value);
}
private boolean hasDenseTheme(Grid grid) {
- return grid.hasThemeName(GridHelper.DENSE_THEME);
+ return GridHelper.isDenseTheme(grid);
}
private void setHeaderHidden(Grid grid, boolean value) {
diff --git a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
index 7b0b72a..995a215 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
@@ -44,7 +44,7 @@ public DenseThemeDemo() {
grid.addColumn(Person::getLastName).setHeader("Last name");
grid.addColumn(Person::getCountry).setHeader("Country");
- grid.addThemeName(GridHelper.DENSE_THEME);
+ GridHelper.setDenseTheme(grid, true);
grid.setHeightFull();
add(grid);