2929import com .vaadin .flow .dom .ClassList ;
3030import com .vaadin .flow .dom .Element ;
3131import java .io .Serializable ;
32+ import java .lang .reflect .Method ;
3233import java .util .AbstractSet ;
3334import java .util .ArrayList ;
3435import java .util .HashMap ;
3536import java .util .Iterator ;
3637import java .util .List ;
3738import java .util .Map ;
39+ import java .util .Objects ;
3840import java .util .stream .Collectors ;
3941import lombok .Getter ;
4042import lombok .RequiredArgsConstructor ;
43+ import lombok .SneakyThrows ;
4144import lombok .experimental .Delegate ;
4245import org .apache .commons .lang3 .StringUtils ;
4346
@@ -121,24 +124,54 @@ protected String getSelectorTemplate() {
121124
122125 }
123126
127+ private static final Method AbstractCell_getColumn ;
128+
129+ static {
130+ Method method = null ;
131+ try {
132+ Class <?> AbstractCell =
133+ Class .forName ("com.vaadin.flow.component.grid.AbstractRow$AbstractCell" );
134+ method = AbstractCell .getDeclaredMethod ("getColumn" );
135+ method .setAccessible (true );
136+ } catch (ClassNotFoundException | NoSuchMethodException e ) {
137+ // Will use cell identity; keep field null.
138+ }
139+
140+ AbstractCell_getColumn = method ;
141+ }
124142
125143 private abstract class CellSelector <ROW , CELL > implements SelectorSupplier {
126144
145+ @ Getter
146+ // AbstractColumn (or CELL if reflection is not available)
147+ private final Object column ;
148+
149+ CellSelector (CELL cell ) {
150+ column = Objects .requireNonNull (getColumn (cell ));
151+ }
152+
153+ @ SneakyThrows
154+ protected final Object getColumn (CELL cell ) {
155+ if (AbstractCell_getColumn != null ) {
156+ return AbstractCell_getColumn .invoke (cell );
157+ } else {
158+ return cell ;
159+ }
160+ }
161+
127162 protected abstract RowSelector <ROW > getRowSelector ();
128163
129164 protected abstract CELL getCell (ROW row , Column <?> c );
130165
131- protected abstract CELL getCell ();
132-
133166 private int getColumnIndex () {
134167 ROW row = getRowSelector ().getRow ();
135168 int j = -1 ;
136169
137- CELL last = null ;
138- CELL target = getCell ();
170+ Object last = null ;
171+ Object target = getColumn ();
139172 for (Column <?> c : helper .getGrid ().getColumns ()) {
140173 if (c .isVisible ()) {
141- CELL curr = getCell (row , c );
174+ Object curr = getColumn ( getCell (row , c ) );
142175 if (curr != last ) {
143176 ++j ;
144177 last = curr ;
@@ -167,14 +200,11 @@ protected String getSelectorTemplate() {
167200
168201 private final class HeaderCellSelector extends CellSelector <HeaderRow , HeaderCell > {
169202
170- @ Getter
171- final HeaderCell cell ;
172-
173203 @ Getter
174204 final HeaderRowSelector rowSelector ;
175205
176206 public HeaderCellSelector (HeaderCell cell ) {
177- this . cell = cell ;
207+ super ( cell ) ;
178208 for (HeaderRow row : helper .getGrid ().getHeaderRows ()) {
179209 if (row .getCells ().contains (cell )) {
180210 rowSelector = new HeaderRowSelector (row );
@@ -194,14 +224,11 @@ protected HeaderCell getCell(HeaderRow row, Column<?> c) {
194224
195225 private final class FooterCellSelector extends CellSelector <FooterRow , FooterCell > {
196226
197- @ Getter
198- final FooterCell cell ;
199-
200227 @ Getter
201228 final FooterRowSelector rowSelector ;
202229
203230 public FooterCellSelector (FooterCell cell ) {
204- this . cell = cell ;
231+ super ( cell ) ;
205232 for (FooterRow row : helper .getGrid ().getFooterRows ()) {
206233 if (row .getCells ().contains (cell )) {
207234 rowSelector = new FooterRowSelector (row );
0 commit comments