Skip to content

Commit

Permalink
Merge pull request #12 from paodb/v22
Browse files Browse the repository at this point in the history
feat: upgrade so component works with vaadin 22
  • Loading branch information
TatuLund authored Jan 17, 2022
2 parents 3728f52 + 88cb3bd commit 6592cbe
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 104 deletions.
6 changes: 3 additions & 3 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>0.9.1</version>
<version>2.0.0</version>

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

<properties>
<vaadin.version>14.4.4</vaadin.version>
<vaadin.version>22.0.2</vaadin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow</artifactId>
<version>0.9.1</version>
<version>${project.version}</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 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>0.9.1</version>
<version>2.0.0</version>
<packaging>jar</packaging>

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

<properties>
<vaadin.version>14.4.4</vaadin.version>
<vaadin.version>22.0.2</vaadin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>com.vaadin.componentfactory</groupId>
<artifactId>popup</artifactId>
<version>2.2.4</version>
<version>3.0.0</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected <U extends GridArrayUpdater, B extends DataCommunicatorBuilder<T, U>>
B dataCommunicatorBuilder) {
super(pageSize, updateQueueBuilder, dataCommunicatorBuilder);
}

/**
* Define if an item can be selected.
*
Expand All @@ -193,14 +193,14 @@ public SerializablePredicate<T> getSelectionPredicate() {
public void setSelectionPredicate(SerializablePredicate<T> selectionPredicate) {
this.selectionPredicate = selectionPredicate;
if (generateSelectionGenerator != null) {
removeDataGenerator(generateSelectionGenerator);
generateSelectionGenerator.destroyAllData();
}
generateSelectionGenerator = this::generateSelectionAccess;
addDataGenerator(generateSelectionGenerator);

super.setClassNameGenerator(item -> selectionDisabled.apply(item).concat(" ").concat(defaultClassNameGenerator.apply(item)));
}

@Override
public void setClassNameGenerator(SerializableFunction<T, String> classNameGenerator) {
defaultClassNameGenerator = classNameGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,29 @@
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.GridArrayUpdater;
import com.vaadin.flow.component.grid.GridArrayUpdater.UpdateQueueData;
import com.vaadin.flow.component.grid.dataview.GridDataView;
import com.vaadin.flow.component.grid.dataview.GridLazyDataView;
import com.vaadin.flow.component.grid.dataview.GridListDataView;
import com.vaadin.flow.component.treegrid.CollapseEvent;
import com.vaadin.flow.component.treegrid.ExpandEvent;
import com.vaadin.flow.component.treegrid.HierarchyColumnComponentRenderer;
import com.vaadin.flow.component.treegrid.TreeGrid;
import com.vaadin.flow.component.treegrid.TreeGridArrayUpdater;
import com.vaadin.flow.data.binder.PropertyDefinition;
import com.vaadin.flow.data.provider.BackEndDataProvider;
import com.vaadin.flow.data.provider.CallbackDataProvider;
import com.vaadin.flow.data.provider.CompositeDataGenerator;
import com.vaadin.flow.data.provider.DataChangeEvent;
import com.vaadin.flow.data.provider.DataCommunicator;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.data.provider.ListDataProvider;
import com.vaadin.flow.data.provider.hierarchy.HasHierarchicalDataProvider;
import com.vaadin.flow.data.provider.hierarchy.HierarchicalArrayUpdater.HierarchicalUpdate;
import com.vaadin.flow.data.provider.hierarchy.HierarchicalConfigurableFilterDataProvider;
import com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicator;
import com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider;
import com.vaadin.flow.data.provider.hierarchy.HierarchicalQuery;
import com.vaadin.flow.data.provider.hierarchy.TreeData;
import com.vaadin.flow.data.provider.hierarchy.TreeDataProvider;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.data.renderer.Renderer;
Expand Down Expand Up @@ -286,24 +293,190 @@ public Registration addCollapseListener(
}

@Override
public void setDataProvider(DataProvider<T, ?> dataProvider) {
if (!(dataProvider instanceof HierarchicalDataProvider)) {
throw new IllegalArgumentException(
"TreeGrid only accepts hierarchical data providers. "
+ "An example of interface to be used: HierarchicalDataProvider");
}
if (dataProviderRegistration != null) {
dataProviderRegistration.remove();
}
dataProviderRegistration = dataProvider.addDataProviderListener(e -> {
if (!(e instanceof DataChangeEvent.DataRefreshEvent)) {
// refreshAll was called
getElement().callJsFunction("$connector.reset");
}
});
super.setDataProvider(dataProvider);
}

public void setDataProvider(DataProvider<T, ?> dataProvider) {
if (dataProvider instanceof HierarchicalDataProvider) {
this.setDataProvider((HierarchicalDataProvider) dataProvider);
} else {
throw new IllegalArgumentException(
"TreeGrid only accepts hierarchical data providers. "
+ "An example of interface to be used: HierarchicalDataProvider");
}
}

@Override
public void setDataProvider(
HierarchicalDataProvider<T, ?> hierarchicalDataProvider) {
if (dataProviderRegistration != null) {
dataProviderRegistration.remove();
}
dataProviderRegistration = hierarchicalDataProvider
.addDataProviderListener(e -> {
if (!(e instanceof DataChangeEvent.DataRefreshEvent)) {
// refreshAll was called
getElement().executeJs(
"$0.$connector && $0.$connector.reset()",
getElement());
}
});
super.setDataProvider(hierarchicalDataProvider);
}

/**
* Tree grid does not support data views. Use
* {@link #setDataProvider(HierarchicalDataProvider)} instead. This method
* is inherited from Grid and it will throw an
* {@link UnsupportedOperationException}.
*
* @param dataProvider
* the data provider
* @return the data view
* @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
* {@link #setItems(Collection, ValueProvider)},
* {@link #setItems(Stream, ValueProvider)} or
* {@link #setTreeData(TreeData)} instead.
*/
@Deprecated
@Override
public GridLazyDataView<T> setItems(
BackEndDataProvider<T, Void> dataProvider) {
throw new UnsupportedOperationException(
"TreeGrid only accepts hierarchical data providers. "
+ "Use another setDataProvider/setItems method instead with hierarchical data."
+ "An example of interface to be used: HierarchicalDataProvider");
}

/**
* Tree grid supports only hierarchical data so use another method instead.
* This method is inherited from Grid and it will throw an
* {@link UnsupportedOperationException}.
*
* @param fetchCallback
* the fetch callback
* @return the data view
* @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
* {@link #setItems(Collection, ValueProvider)},
* {@link #setItems(Stream, ValueProvider)} or
* {@link #setTreeData(TreeData)} instead.
*/
@Deprecated
@Override
public GridLazyDataView<T> setItems(
CallbackDataProvider.FetchCallback<T, Void> fetchCallback) {
throw new UnsupportedOperationException(
"TreeGrid only accepts hierarchical data providers. "
+ "Use another setDataProvider/setItems method instead with hierarchical data."
+ "An example of interface to be used: HierarchicalDataProvider");
}

/**
* Tree grid supports only hierarchical data providers so use another method
* instead. This method is inherited from Grid and it will throw an
* {@link UnsupportedOperationException}.
*
* @param dataProvider
* the data provider
* @return the data view
* @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
* {@link #setItems(Collection, ValueProvider)},
* {@link #setItems(Stream, ValueProvider)} or
* {@link #setTreeData(TreeData)} instead.
*/
@Deprecated
@Override
public GridListDataView<T> setItems(ListDataProvider<T> dataProvider) {
throw new UnsupportedOperationException(
"TreeGrid only accepts hierarchical data providers. "
+ "Use another setDataProvider/setItems method instead with hierarchical data."
+ "An example of interface to be used: HierarchicalDataProvider");
}

/**
* Tree grid supports only hierarchical data so use another method instead.
* This method is inherited from Grid and it will throw an
* {@link UnsupportedOperationException}.
*
* @param items
* the items to display, not {@code null}
* @return the data view
* @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
* {@link #setItems(Collection, ValueProvider)},
* {@link #setItems(Stream, ValueProvider)} or
* {@link #setTreeData(TreeData)} instead.
*/
@Deprecated
@Override
public GridListDataView<T> setItems(T... items) {
throw new UnsupportedOperationException(
"TreeGrid only accepts hierarchical data providers. "
+ "Use another setDataProvider/setItems method instead with hierarchical data."
+ "An example of interface to be used: HierarchicalDataProvider");
}

/**
* Tree grid supports only hierarchical data, so use another method instead.
* This method is inherited from Grid and it will throw an
* {@link UnsupportedOperationException}.
*
* @param items
* the items to display, not {@code null}
* @return the data view
* @deprecated use {@link #setDataProvider(HierarchicalDataProvider)},
* {@link #setItems(Collection, ValueProvider)},
* {@link #setItems(Stream, ValueProvider)} or
* {@link #setTreeData(TreeData)} instead.
*/
@Deprecated
@Override
public GridListDataView<T> setItems(Collection<T> items) {
throw new UnsupportedOperationException(
"TreeGrid only accepts hierarchical data providers. "
+ "Use another setDataProvider/setItems method instead with hierarchical data."
+ "An example of interface to be used: HierarchicalDataProvider");
}

/**
* Tree grid does not support list data view, this will throw an
* {@link UnsupportedOperationException}.
*
* @return exception is thrown
* @deprecated not supported
*/
@Deprecated
@Override
public GridListDataView<T> getListDataView() {
throw new UnsupportedOperationException(
"TreeGrid does not support list data view.");
}

/**
* Tree grid does not support list data view, this will throw an
* {@link UnsupportedOperationException}.
*
* @return exception is thrown
* @deprecated not supported
*/
@Deprecated
@Override
public GridLazyDataView<T> getLazyDataView() {
throw new UnsupportedOperationException(
"TreeGrid does not support lazy data view.");
}

/**
* Tree grid does not support list data view, this will throw an
* {@link UnsupportedOperationException}.
*
* @return exception is thrown
* @deprecated not supported
*/
@Deprecated
@Override
public GridDataView<T> getGenericDataView() {
throw new UnsupportedOperationException(
"TreeGrid does not support generic data view.");
}


/**
* 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
Expand Down Expand Up @@ -779,6 +952,22 @@ public HierarchicalDataProvider<T, SerializablePredicate<T>> getDataProvider() {
return (HierarchicalDataProvider<T, SerializablePredicate<T>>) super.getDataProvider();
}

/**
* The effective index of an item depends on the complete hierarchy of the
* tree. {@link TreeGrid} uses lazy loading for performance reasons and does
* not know about the complete hierarchy. Without the knowledge of the
* complete hierarchy, {@link TreeGrid} can’t reliably calculate an exact
* scroll position. <b>This uncertainty makes this method unreliable and so
* should be avoided.</b>
*
* @param rowIndex
* zero based index of the item to scroll to in the current view.
*/
@Override
public void scrollToIndex(int rowIndex) {
super.scrollToIndex(rowIndex);
}

@Override
protected void applyFilterPredicate(SerializablePredicate<T> finalPredicate) {
DataProvider<T, ?> dataProvider = getDataProvider();
Expand All @@ -788,4 +977,5 @@ protected void applyFilterPredicate(SerializablePredicate<T> finalPredicate) {
((HierarchicalConfigurableFilterDataProvider<T, Void, Filter>)dataProvider).setFilter(new Filter<T>(finalPredicate));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.vaadin.componentfactory.enhancedgrid.EnhancedColumn;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.data.provider.ComponentDataGenerator;
import com.vaadin.flow.data.provider.DataGenerator;
import com.vaadin.flow.data.provider.DataKeyMapper;
import com.vaadin.flow.data.renderer.ComponentDataGenerator;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.data.renderer.Rendering;
import com.vaadin.flow.dom.Element;
Expand Down
Loading

0 comments on commit 6592cbe

Please sign in to comment.