From 39bf9747248aee0d05dc9e9ab5e1ad4cb79ad09b Mon Sep 17 00:00:00 2001 From: Paola De Bartolo Date: Mon, 30 May 2022 17:46:00 -0300 Subject: [PATCH] feat: upgrade component to Vaadin 23 Close #15 --- enhanced-grid-flow-demo/pom.xml | 8 +- enhanced-grid-flow/pom.xml | 8 +- .../enhancedtreegrid/EnhancedTreeGrid.java | 113 ++++++++++-------- pom.xml | 11 +- 4 files changed, 74 insertions(+), 66 deletions(-) diff --git a/enhanced-grid-flow-demo/pom.xml b/enhanced-grid-flow-demo/pom.xml index ec53276..97489f2 100644 --- a/enhanced-grid-flow-demo/pom.xml +++ b/enhanced-grid-flow-demo/pom.xml @@ -6,7 +6,7 @@ com.vaadin.componentfactory enhanced-grid-flow-demo - 2.0.2-SNAPSHOT + 3.0.0 Enhanced Grid Demo war @@ -18,9 +18,9 @@ - 22.0.2 - 1.8 - 1.8 + 23.0.9 + 11 + 11 UTF-8 UTF-8 false diff --git a/enhanced-grid-flow/pom.xml b/enhanced-grid-flow/pom.xml index 69b7e51..79856b6 100644 --- a/enhanced-grid-flow/pom.xml +++ b/enhanced-grid-flow/pom.xml @@ -6,7 +6,7 @@ com.vaadin.componentfactory enhanced-grid-flow - 2.0.2-SNAPSHOT + 3.0.0 jar Enhanced Grid @@ -19,9 +19,9 @@ - 22.0.2 - 1.8 - 1.8 + 23.0.9 + 11 + 11 UTF-8 UTF-8 diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedtreegrid/EnhancedTreeGrid.java b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedtreegrid/EnhancedTreeGrid.java index b711588..4bbbc5a 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedtreegrid/EnhancedTreeGrid.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedtreegrid/EnhancedTreeGrid.java @@ -23,10 +23,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,6 +43,7 @@ import com.vaadin.flow.component.grid.Filter; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.GridArrayUpdater; +import com.vaadin.flow.component.grid.Grid.Column; import com.vaadin.flow.component.grid.GridArrayUpdater.UpdateQueueData; import com.vaadin.flow.component.grid.dataview.GridDataView; import com.vaadin.flow.component.grid.dataview.GridLazyDataView; @@ -152,8 +156,13 @@ public UpdateQueueData getUpdateQueueData() { } } - private final ValueProvider defaultUniqueKeyProvider = item -> String - .valueOf(item.hashCode()); + private final AtomicLong uniqueKeyCounter = new AtomicLong(0); + private final Map objectUniqueKeyMap = new HashMap<>(); + + ValueProvider defaultUniqueKeyProvider = item -> String.valueOf( + objectUniqueKeyMap.computeIfAbsent(getDataProvider().getId(item), + key -> uniqueKeyCounter.getAndIncrement())); + private Registration dataProviderRegistration; @@ -477,57 +486,57 @@ public GridDataView getGenericDataView() { } - /** - * Adds a new Hierarchy column to this {@link Grid} with a value provider. - * The value is converted to String when sent to the client by using - * {@link String#valueOf(Object)}. - *

- * Hierarchy column is rendered by using 'vaadin-grid-tree-toggle' web - * component. - * - * @param valueProvider - * the value provider - * @return the created hierarchy column - */ - public EnhancedColumn addHierarchyColumn(ValueProvider valueProvider) { - EnhancedColumn column = addColumn(TemplateRenderer - . of("[[item.name]]" - + "") - .withProperty("leaf", - item -> !getDataCommunicator().hasChildren(item)) - .withProperty("name", - value -> String.valueOf(valueProvider.apply(value)))); - final SerializableComparator comparator = - (a, b) -> compareMaybeComparables(valueProvider.apply(a), - valueProvider.apply(b)); - column.setComparator(comparator); - - return column; - } + /** + * Adds a new Hierarchy column to this {@link Grid} with a value provider. + * The value is converted to String when sent to the client by using + * {@link String#valueOf(Object)}. + *

+ * Hierarchy column is rendered by using 'vaadin-grid-tree-toggle' web + * component. + * + * @param valueProvider + * the value provider + * @return the created hierarchy column + */ + public EnhancedColumn addHierarchyColumn(ValueProvider valueProvider) { + EnhancedColumn column = addColumn(TemplateRenderer + . of("[[item.name]]" + + "") + .withProperty("children", + item -> getDataCommunicator().hasChildren(item)) + .withProperty("name", + value -> String.valueOf(valueProvider.apply(value)))); + final SerializableComparator comparator = (a, + b) -> compareMaybeComparables(valueProvider.apply(a), + valueProvider.apply(b)); + column.setComparator(comparator); + + return column; + } - /** - * Adds a new Hierarchy column that shows components. - *

- * NOTE: Using {@link ComponentRenderer} is not as efficient as the - * built in renderers. - *

- * - * @param componentProvider - * a value provider that will return a component for the given - * item - * @param - * the component type - * @return the new column - * @see #addColumn(Renderer) - * @see #removeColumn(Column) - */ - public EnhancedColumn addComponentHierarchyColumn( - ValueProvider componentProvider) { - return addColumn(new HierarchyColumnComponentRenderer( - componentProvider).withProperty("leaf", - item -> !getDataCommunicator().hasChildren(item))); - } + /** + * Adds a new Hierarchy column that shows components. + *

+ * NOTE: Using {@link ComponentRenderer} is not as efficient as the + * built in renderers. + *

+ * + * @param componentProvider + * a value provider that will return a component for the given + * item + * @param + * the component type + * @return the new column + * @see #addColumn(Renderer) + * @see #removeColumn(Column) + */ + public EnhancedColumn addComponentHierarchyColumn( + ValueProvider componentProvider) { + return addColumn(new HierarchyColumnComponentRenderer( + componentProvider).withProperty("children", + item -> getDataCommunicator().hasChildren(item))); + } /** diff --git a/pom.xml b/pom.xml index 6f5afa8..0c790d4 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.vaadin.componentfactory enhanced-grid-flow-root - 2.0.2-SNAPSHOT + 3.0.0 pom enhanced-grid-flow @@ -13,12 +13,11 @@ enhanced-grid-flow - 22.0.2 - 1.8 - 1.8 + 23.0.9 + 11 + 11 UTF-8 UTF-8 - 2.0.0 2020 @@ -31,7 +30,7 @@ ${project.groupId} enhanced-grid-flow - ${enhanced-grid-flow.version} + ${project.version} com.vaadin