Skip to content

Commit cd8d7e8

Browse files
javier-godoymlopezFC
authored andcommitted
refactor: refactor package protected attribute "propertySet"
Close #151
1 parent f6d9b85 commit cd8d7e8

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
import com.opencsv.CSVWriter;
2424
import com.vaadin.flow.component.grid.Grid;
25-
import com.vaadin.flow.data.binder.BeanPropertySet;
26-
import com.vaadin.flow.data.binder.PropertySet;
2725
import com.vaadin.flow.server.VaadinSession;
2826
import java.io.IOException;
2927
import java.io.OutputStream;
@@ -92,11 +90,8 @@ public void accept(OutputStream out, VaadinSession session) throws IOException {
9290
}
9391
}
9492

95-
@SuppressWarnings("unchecked")
9693
private String[] buildRow(T item) {
97-
if (exporter.propertySet == null) {
98-
exporter.propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
99-
}
94+
10095
if (exporter.getColumns().isEmpty()) throw new IllegalStateException("Grid has no columns");
10196

10297
String[] result = new String[exporter.getColumns().size()];

src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import com.vaadin.flow.component.grid.ColumnTextAlign;
2424
import com.vaadin.flow.component.grid.Grid;
2525
import com.vaadin.flow.component.grid.Grid.Column;
26-
import com.vaadin.flow.data.binder.BeanPropertySet;
27-
import com.vaadin.flow.data.binder.PropertySet;
2826
import com.vaadin.flow.data.provider.DataProvider;
2927
import com.vaadin.flow.server.VaadinSession;
3028
import java.io.IOException;
@@ -180,16 +178,13 @@ private void fillData(XWPFTable table, XWPFTableCell dataCell, DataProvider<T, ?
180178
});
181179
}
182180

183-
@SuppressWarnings("unchecked")
184181
private void buildRow(
185182
T item,
186183
XWPFTableRow row,
187184
XWPFTableCell startingCell,
188185
CTTcPr tcpr,
189186
XWPFTableCell templateCell) {
190-
if (exporter.propertySet == null) {
191-
exporter.propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
192-
}
187+
193188
if (exporter.getColumns().isEmpty()) {
194189
throw new IllegalStateException("Grid has no columns");
195190
}

src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
import com.vaadin.flow.component.grid.ColumnTextAlign;
5757
import com.vaadin.flow.component.grid.Grid;
5858
import com.vaadin.flow.component.grid.Grid.Column;
59-
import com.vaadin.flow.data.binder.BeanPropertySet;
60-
import com.vaadin.flow.data.binder.PropertySet;
6159
import com.vaadin.flow.data.provider.DataProvider;
6260
import com.vaadin.flow.function.ValueProvider;
6361
import com.vaadin.flow.server.VaadinSession;
@@ -237,11 +235,8 @@ private int fillData(
237235
return dataRange.getLastRow();
238236
}
239237

240-
@SuppressWarnings("unchecked")
241238
private void buildRow(T item, Sheet sheet, Cell startingCell) {
242-
if (exporter.propertySet == null) {
243-
exporter.propertySet = (PropertySet<T>) BeanPropertySet.get(item.getClass());
244-
}
239+
245240
if (exporter.getColumns().isEmpty()) {
246241
throw new IllegalStateException("Grid has no columns");
247242
}

src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.vaadin.flow.component.grid.Grid.Column;
3131
import com.vaadin.flow.component.html.Anchor;
3232
import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode;
33+
import com.vaadin.flow.data.binder.BeanPropertySet;
3334
import com.vaadin.flow.data.binder.PropertyDefinition;
3435
import com.vaadin.flow.data.binder.PropertySet;
3536
import com.vaadin.flow.data.renderer.BasicRenderer;
@@ -110,7 +111,7 @@ public class GridExporter<T> implements Serializable {
110111
String footersPlaceHolder = "${footers}";
111112

112113
List<Grid.Column<T>> columns;
113-
PropertySet<T> propertySet;
114+
private PropertySet<T> propertySet;
114115

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

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

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

0 commit comments

Comments
 (0)