Skip to content

Commit 5097f9f

Browse files
javier-godoymlopezFC
authored andcommitted
feat!: replace classNameGenerator with partNameGenerator
Close #148
1 parent 5891f44 commit 5097f9f

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,20 @@ public final class GridHelper<T> implements Serializable {
8383
@Getter(value = AccessLevel.PACKAGE)
8484
private final Grid<T> grid;
8585

86-
private final GridHelperClassNameGenerator<T> helperClassNameGenerator;
86+
private final GridHelperPartNameGenerator<T> helperPartNameGenerator;
8787

88-
protected void setHelperClassNameGenerator(
88+
protected void setHelperPartNameGenerator(
8989
Class<?> clazz, SerializableFunction<T, String> generator) {
90-
getHelper(grid).helperClassNameGenerator.setHelperClassNameGenerator(clazz, generator);
90+
getHelper(grid).helperPartNameGenerator.setHelperPartNameGenerator(clazz, generator);
9191
grid.getDataCommunicator().reset();
9292
}
9393

9494
private boolean selectOnClick;
9595

9696
private GridHelper(Grid<T> grid) {
9797
this.grid = grid;
98-
helperClassNameGenerator = new GridHelperClassNameGenerator<>();
99-
setClassNameGenerator(grid.getClassNameGenerator());
98+
helperPartNameGenerator = new GridHelperPartNameGenerator<>();
99+
setPartNameGenerator(grid.getPartNameGenerator());
100100
grid.addItemClickListener(this::onItemClick);
101101
grid.addAttachListener(this::onAttach);
102102
if (grid.isAttached()) {
@@ -161,26 +161,24 @@ public static SelectionMode getSelectionMode(Grid<?> grid) {
161161
}
162162

163163
/**
164-
* Sets the function that is used for generating CSS class names for all the cells in the rows in
165-
* this grid. Returning {@code null} from the generator results in no custom class name being set.
166-
* Multiple class names can be returned from the generator as space-separated.
164+
* Sets the function that is used for generating CSS part names for all the cells in the rows in
165+
* this grid. Returning {@code null} from the generator results in no custom part name being set.
166+
* Multiple part names can be returned from the generator as space-separated.
167167
*
168-
* <p>If {@link Column#setClassNameGenerator(SerializableFunction)} is used together with this
169-
* method, resulting class names from both methods will be effective. Class names generated by
170-
* grid are applied to the cells before the class names generated by column. This means that if
171-
* the classes contain conflicting style properties, column's classes will win.
168+
* <p>
169+
* If {@link Column#setPartNameGenerator(SerializableFunction)} is used together with this method,
170+
* resulting part names from both methods will be effective.
172171
*
173-
* @param classNameGenerator the class name generator to set, not {@code null}
174-
* @throws NullPointerException if {@code classNameGenerator} is {@code null}
175-
* @see Column#setClassNameGenerator(SerializableFunction)
172+
* @param partNameGenerator the part name generator to set.
173+
* @see Column#setPartNameGenerator(SerializableFunction)
176174
*/
177-
public void setClassNameGenerator(SerializableFunction<T, String> classNameGenerator) {
178-
grid.setClassNameGenerator(helperClassNameGenerator);
179-
if (classNameGenerator instanceof GridHelperClassNameGenerator) {
180-
helperClassNameGenerator.setGridClassNameGenerator(
181-
((GridHelperClassNameGenerator<T>) classNameGenerator).getGridClassNameGenerator());
175+
public void setPartNameGenerator(SerializableFunction<T, String> partNameGenerator) {
176+
grid.setPartNameGenerator(helperPartNameGenerator);
177+
if (partNameGenerator instanceof GridHelperPartNameGenerator) {
178+
helperPartNameGenerator.setGridPartNameGenerator(
179+
((GridHelperPartNameGenerator<T>) partNameGenerator).getGridPartNameGenerator());
182180
} else {
183-
helperClassNameGenerator.setGridClassNameGenerator(classNameGenerator);
181+
helperPartNameGenerator.setGridPartNameGenerator(partNameGenerator);
184182
}
185183
}
186184

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperClassNameGenerator.java renamed to src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperPartNameGenerator.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Grid Helpers Add-on
44
* %%
5-
* Copyright (C) 2022 - 2024 Flowing Code
5+
* Copyright (C) 2022 - 2025 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -31,27 +31,30 @@
3131
import lombok.Setter;
3232

3333
@SuppressWarnings("serial")
34-
final class GridHelperClassNameGenerator<T> implements SerializableFunction<T, String> {
34+
final class GridHelperPartNameGenerator<T> implements SerializableFunction<T, String> {
3535

36-
private Map<Class<?>, SerializableFunction<T, String>> helperClassNameGenerators =
36+
private Map<Class<?>, SerializableFunction<T, String>> helperPartNameGenerators =
3737
new HashMap<>();
3838

39-
@Getter @Setter private SerializableFunction<T, String> gridClassNameGenerator;
39+
@Getter
40+
@Setter
41+
private SerializableFunction<T, String> gridPartNameGenerator;
4042

4143
private transient boolean invoked;
4244

43-
void setHelperClassNameGenerator(Class<?> clazz, SerializableFunction<T, String> generator) {
45+
void setHelperPartNameGenerator(Class<?> clazz, SerializableFunction<T, String> generator) {
4446
if (generator != null) {
45-
helperClassNameGenerators.put(clazz, generator);
47+
helperPartNameGenerators.put(clazz, generator);
4648
} else {
47-
helperClassNameGenerators.remove(clazz);
49+
helperPartNameGenerators.remove(clazz);
4850
}
4951
}
5052

5153
private Stream<SerializableFunction<T, String>> generators() {
54+
5255
return Stream.concat(
53-
Optional.ofNullable(gridClassNameGenerator).map(Stream::of).orElseGet(Stream::empty),
54-
helperClassNameGenerators.values().stream());
56+
Optional.ofNullable(gridPartNameGenerator).map(Stream::of).orElseGet(Stream::empty),
57+
helperPartNameGenerators.values().stream());
5558
}
5659

5760
@Override

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/SelectionFilterHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Grid Helpers Add-on
44
* %%
5-
* Copyright (C) 2022 - 2024 Flowing Code
5+
* Copyright (C) 2022 - 2025 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -59,11 +59,11 @@ public void setSelectionFilter(SerializablePredicate<T> predicate) {
5959
currentSingleSelectedItem = null;
6060
if (predicate != null) {
6161
deselectIf(predicate.negate());
62-
helper.setHelperClassNameGenerator(
62+
helper.setHelperPartNameGenerator(
6363
this.getClass(), row -> predicate.test(row) ? null : "fcGh-noselect");
6464
selectionListenerRegistration = grid.addSelectionListener(this::onSelection);
6565
} else {
66-
helper.setHelperClassNameGenerator(this.getClass(), null);
66+
helper.setHelperPartNameGenerator(this.getClass(), null);
6767
}
6868
}
6969

src/main/resources/META-INF/frontend/fcGridHelper/vaadin-grid.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Grid Helpers Add-on
44
* %%
5-
* Copyright (C) 2022 - 2024 Flowing Code
5+
* Copyright (C) 2022 - 2025 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@
5050
--fcgh-toggle-right: 24px;
5151
}
5252

53-
table[aria-multiselectable="true"] .fcGh-noselect[first-column] ::slotted(*) {
53+
table[aria-multiselectable="true"] [part~="fcGh-noselect"][first-column] ::slotted(*) {
5454
opacity: var(--fcgh-noselect-opacity, 0.5);
5555
pointer-events: none;
5656
}

0 commit comments

Comments
 (0)