Skip to content

Commit

Permalink
feat: upgrade component to Vaadin 23
Browse files Browse the repository at this point in the history
Close #15
  • Loading branch information
paodb authored and mlopezFC committed May 31, 2022
1 parent b8a0cf1 commit 39bf974
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 66 deletions.
8 changes: 4 additions & 4 deletions enhanced-grid-flow-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow-demo</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>3.0.0</version>

<name>Enhanced Grid Demo</name>
<packaging>war</packaging>
Expand All @@ -18,9 +18,9 @@
</organization>

<properties>
<vaadin.version>22.0.2</vaadin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<vaadin.version>23.0.9</vaadin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
Expand Down
8 changes: 4 additions & 4 deletions enhanced-grid-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>Enhanced Grid</name>
Expand All @@ -19,9 +19,9 @@
</organization>

<properties>
<vaadin.version>22.0.2</vaadin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<vaadin.version>23.0.9</vaadin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -152,8 +156,13 @@ public UpdateQueueData getUpdateQueueData() {
}
}

private final ValueProvider<T, String> defaultUniqueKeyProvider = item -> String
.valueOf(item.hashCode());
private final AtomicLong uniqueKeyCounter = new AtomicLong(0);
private final Map<Object, Long> objectUniqueKeyMap = new HashMap<>();

ValueProvider<T, String> defaultUniqueKeyProvider = item -> String.valueOf(
objectUniqueKeyMap.computeIfAbsent(getDataProvider().getId(item),
key -> uniqueKeyCounter.getAndIncrement()));


private Registration dataProviderRegistration;

Expand Down Expand Up @@ -477,57 +486,57 @@ public GridDataView<T> 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)}.
* <p>
* Hierarchy column is rendered by using 'vaadin-grid-tree-toggle' web
* component.
*
* @param valueProvider
* the value provider
* @return the created hierarchy column
*/
public EnhancedColumn<T> addHierarchyColumn(ValueProvider<T, ?> valueProvider) {
EnhancedColumn<T> column = addColumn(TemplateRenderer
.<T> of("<vaadin-grid-tree-toggle "
+ "leaf='[[item.leaf]]' expanded='{{expanded}}' level='[[level]]'>[[item.name]]"
+ "</vaadin-grid-tree-toggle>")
.withProperty("leaf",
item -> !getDataCommunicator().hasChildren(item))
.withProperty("name",
value -> String.valueOf(valueProvider.apply(value))));
final SerializableComparator<T> 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)}.
* <p>
* Hierarchy column is rendered by using 'vaadin-grid-tree-toggle' web
* component.
*
* @param valueProvider
* the value provider
* @return the created hierarchy column
*/
public EnhancedColumn<T> addHierarchyColumn(ValueProvider<T, ?> valueProvider) {
EnhancedColumn<T> column = addColumn(TemplateRenderer
.<T> of("<vaadin-grid-tree-toggle "
+ "leaf='[[!item.children]]' expanded='{{expanded}}' level='[[level]]'>[[item.name]]"
+ "</vaadin-grid-tree-toggle>")
.withProperty("children",
item -> getDataCommunicator().hasChildren(item))
.withProperty("name",
value -> String.valueOf(valueProvider.apply(value))));
final SerializableComparator<T> comparator = (a,
b) -> compareMaybeComparables(valueProvider.apply(a),
valueProvider.apply(b));
column.setComparator(comparator);

return column;
}

/**
* Adds a new Hierarchy column that shows components.
* <p>
* <em>NOTE:</em> Using {@link ComponentRenderer} is not as efficient as the
* built in renderers.
* </p>
*
* @param componentProvider
* a value provider that will return a component for the given
* item
* @param <V>
* the component type
* @return the new column
* @see #addColumn(Renderer)
* @see #removeColumn(Column)
*/
public <V extends Component> EnhancedColumn<T> addComponentHierarchyColumn(
ValueProvider<T, V> componentProvider) {
return addColumn(new HierarchyColumnComponentRenderer<V, T>(
componentProvider).withProperty("leaf",
item -> !getDataCommunicator().hasChildren(item)));
}
/**
* Adds a new Hierarchy column that shows components.
* <p>
* <em>NOTE:</em> Using {@link ComponentRenderer} is not as efficient as the
* built in renderers.
* </p>
*
* @param componentProvider
* a value provider that will return a component for the given
* item
* @param <V>
* the component type
* @return the new column
* @see #addColumn(Renderer)
* @see #removeColumn(Column)
*/
public <V extends Component> EnhancedColumn<T> addComponentHierarchyColumn(
ValueProvider<T, V> componentProvider) {
return addColumn(new HierarchyColumnComponentRenderer<V, T>(
componentProvider).withProperty("children",
item -> getDataCommunicator().hasChildren(item)));
}


/**
Expand Down
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>3.0.0</version>
<packaging>pom</packaging>
<modules>
<module>enhanced-grid-flow</module>
Expand All @@ -13,12 +13,11 @@
<description>enhanced-grid-flow</description>

<properties>
<vaadin.version>22.0.2</vaadin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<vaadin.version>23.0.9</vaadin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<enhanced-grid-flow.version>2.0.0</enhanced-grid-flow.version>
</properties>
<inceptionYear>2020</inceptionYear>
<organization>
Expand All @@ -31,7 +30,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>enhanced-grid-flow</artifactId>
<version>${enhanced-grid-flow.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
Expand Down

0 comments on commit 39bf974

Please sign in to comment.