diff options
| author | Dirk Fauth | 2022-12-21 10:30:36 +0000 |
|---|---|---|
| committer | Dirk Fauth | 2022-12-21 10:30:36 +0000 |
| commit | bc4dfb5891f1081e4617ce4a404019728b15eb60 (patch) | |
| tree | b5ed561f2f19868d2c07d64d6126aef0eb72bbc4 | |
| parent | a493cfbb8e00fd4110f9cfb20b60b15ff9e82c03 (diff) | |
| download | org.eclipse.nebula.widgets.nattable-bc4dfb5891f1081e4617ce4a404019728b15eb60.tar.gz org.eclipse.nebula.widgets.nattable-bc4dfb5891f1081e4617ce4a404019728b15eb60.tar.xz org.eclipse.nebula.widgets.nattable-bc4dfb5891f1081e4617ce4a404019728b15eb60.zip | |
Bug 581254 - Strange errors with DataChangeLayer if IRowIdAccessor is a
lambda
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
Change-Id: Ied928314d9d6b770b7c08fe8e7db767239e1b5dc
| -rw-r--r-- | org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/datachange/IdIndexKeyHandler.java | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/datachange/IdIndexKeyHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/datachange/IdIndexKeyHandler.java index cefd83d3..20055324 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/datachange/IdIndexKeyHandler.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/datachange/IdIndexKeyHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2020 Dirk Fauth and others. + * Copyright (c) 2017, 2022 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,8 @@ import java.lang.reflect.Method; import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider; import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Implementation of {@link CellKeyHandler} that uses {@link IdIndexIdentifier} @@ -30,11 +32,26 @@ import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor; */ public class IdIndexKeyHandler<T> implements CellKeyHandler<IdIndexIdentifier<T>> { + private static final Logger LOG = LoggerFactory.getLogger(IdIndexKeyHandler.class); + private final IRowDataProvider<T> rowDataProvider; private final IRowIdAccessor<T> rowIdAccessor; private Class<?> clazz; + /** + * Creates an {@link IdIndexKeyHandler} that identifies the type to handle + * via reflection. If the reflection fails or produces strange results, try + * to pass the type via + * {@link IdIndexKeyHandler#IdIndexKeyHandler(IRowDataProvider, IRowIdAccessor, Class)} + * + * @param rowDataProvider + * The {@link IRowDataProvider} needed to retrieve the modified + * row object. + * @param rowIdAccessor + * The {@link IRowIdAccessor} needed to retrieve the row object + * id. + */ public IdIndexKeyHandler(IRowDataProvider<T> rowDataProvider, IRowIdAccessor<T> rowIdAccessor) { this.rowDataProvider = rowDataProvider; this.rowIdAccessor = rowIdAccessor; @@ -47,6 +64,36 @@ public class IdIndexKeyHandler<T> implements CellKeyHandler<IdIndexIdentifier<T> } } } + + if (this.clazz == null && rowDataProvider.getRowCount() > 0) { + // type could not be retrieved from the IRowIdAccessor + // maybe it is a lambda or method reference + // try to get the type from the collection + this.clazz = rowDataProvider.getRowObject(0).getClass(); + } + + if (this.clazz == null) { + LOG.error("row object type could not be retrieved via reflection, use constructor with type parameter!"); //$NON-NLS-1$ + } + } + + /** + * + * @param rowDataProvider + * The {@link IRowDataProvider} needed to retrieve the modified + * row object. + * @param rowIdAccessor + * The {@link IRowIdAccessor} needed to retrieve the row object + * id. + * @param type + * The type of objects handled by the IRowDataProvider and the + * IRowIdAcccessor. + * @since 2.1 + */ + public IdIndexKeyHandler(IRowDataProvider<T> rowDataProvider, IRowIdAccessor<T> rowIdAccessor, Class<T> type) { + this.rowDataProvider = rowDataProvider; + this.rowIdAccessor = rowIdAccessor; + this.clazz = type; } @Override |
