Skip to content

Commit

Permalink
refactor: refactor package protected attribute "propertySet"
Browse files Browse the repository at this point in the history
Close #151
  • Loading branch information
javier-godoy authored and mlopezFC committed Oct 15, 2024
1 parent ceeab79 commit 6fb4ee5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import com.opencsv.CSVWriter;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.data.binder.BeanPropertySet;
import com.vaadin.flow.data.binder.PropertySet;
import com.vaadin.flow.server.VaadinSession;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -92,11 +90,8 @@ public void accept(OutputStream out, VaadinSession session) throws IOException {
}
}

@SuppressWarnings("unchecked")
private String[] buildRow(T item) {
if (exporter.propertySet == null) {
exporter.propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
}

if (exporter.getColumns().isEmpty()) throw new IllegalStateException("Grid has no columns");

String[] result = new String[exporter.getColumns().size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.vaadin.flow.component.grid.ColumnTextAlign;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.data.binder.BeanPropertySet;
import com.vaadin.flow.data.binder.PropertySet;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.server.VaadinSession;
import java.io.IOException;
Expand Down Expand Up @@ -180,16 +178,13 @@ private void fillData(XWPFTable table, XWPFTableCell dataCell, DataProvider<T, ?
});
}

@SuppressWarnings("unchecked")
private void buildRow(
T item,
XWPFTableRow row,
XWPFTableCell startingCell,
CTTcPr tcpr,
XWPFTableCell templateCell) {
if (exporter.propertySet == null) {
exporter.propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
}

if (exporter.getColumns().isEmpty()) {
throw new IllegalStateException("Grid has no columns");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
import com.vaadin.flow.component.grid.ColumnTextAlign;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.data.binder.BeanPropertySet;
import com.vaadin.flow.data.binder.PropertySet;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.function.ValueProvider;
import com.vaadin.flow.server.VaadinSession;
Expand Down Expand Up @@ -237,11 +235,8 @@ private int fillData(
return dataRange.getLastRow();
}

@SuppressWarnings("unchecked")
private void buildRow(T item, Sheet sheet, Cell startingCell) {
if (exporter.propertySet == null) {
exporter.propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
}

if (exporter.getColumns().isEmpty()) {
throw new IllegalStateException("Grid has no columns");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode;
import com.vaadin.flow.data.binder.BeanPropertySet;
import com.vaadin.flow.data.binder.PropertyDefinition;
import com.vaadin.flow.data.binder.PropertySet;
import com.vaadin.flow.data.renderer.BasicRenderer;
Expand Down Expand Up @@ -110,7 +111,7 @@ public class GridExporter<T> implements Serializable {
String footersPlaceHolder = "${footers}";

List<Grid.Column<T>> columns;
PropertySet<T> propertySet;
private PropertySet<T> propertySet;

Map<String, String> additionalPlaceHolders = new HashMap<>();

Expand Down Expand Up @@ -226,6 +227,9 @@ Object extractValueFromColumn(T item, Column<T> column) {

// if there is a key, assume that the property can be retrieved from it
if (value == null && column.getKey() != null) {
if (propertySet == null) {
propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
}
Optional<PropertyDefinition<T, ?>> propertyDefinition =
propertySet.getProperty(column.getKey());
if (propertyDefinition.isPresent()) {
Expand Down

0 comments on commit 6fb4ee5

Please sign in to comment.