diff options
author | Henri Sara <henri.sara@gmail.com> | 2017-03-16 10:23:02 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-03-16 10:23:02 +0200 |
commit | 28a815fb833087c1825365ac9b22c097e6d28ca5 (patch) | |
tree | 97691c8ae07c63c8f1939ffb53b9c9d9b0506978 /client | |
parent | 71679dfd1626737081b86127e6c547e37c77923f (diff) | |
download | vaadin-framework-28a815fb833087c1825365ac9b22c097e6d28ca5.tar.gz vaadin-framework-28a815fb833087c1825365ac9b22c097e6d28ca5.zip |
Remove unnecessary width calculation on Grid initial render (#8848)
Do not calculate column widths unnecessarily, especially for columns
with fixed width.
Fixes #8678
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/widgets/Escalator.java | 77 | ||||
-rwxr-xr-x | client/src/main/java/com/vaadin/client/widgets/Grid.java | 10 |
2 files changed, 56 insertions, 31 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 5cfad18540..34cdb70b2b 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -1121,6 +1121,8 @@ public class Escalator extends Widget private double defaultRowHeight = INITIAL_DEFAULT_ROW_HEIGHT; + private boolean initialColumnSizesCalculated = false; + public AbstractRowContainer( final TableSectionElement rowContainerElement) { root = rowContainerElement; @@ -1324,21 +1326,28 @@ public class Escalator extends Widget if (isAttached()) { paintInsertRows(index, numberOfRows); + /* + * We are inserting the first rows in this container. We + * potentially need to set the widths for the cells for the + * first time. + */ if (rows == numberOfRows) { - /* - * We are inserting the first rows in this container. We - * potentially need to set the widths for the cells for the - * first time. - */ - Map<Integer, Double> colWidths = new HashMap<>(); - for (int i = 0; i < getColumnConfiguration() - .getColumnCount(); i++) { - Double width = Double.valueOf( - getColumnConfiguration().getColumnWidth(i)); - Integer col = Integer.valueOf(i); - colWidths.put(col, width); - } - getColumnConfiguration().setColumnWidths(colWidths); + Scheduler.get().scheduleFinally(() -> { + if (initialColumnSizesCalculated) { + return; + } + initialColumnSizesCalculated = true; + + Map<Integer, Double> colWidths = new HashMap<>(); + for (int i = 0; i < getColumnConfiguration() + .getColumnCount(); i++) { + Double width = Double.valueOf( + getColumnConfiguration().getColumnWidth(i)); + Integer col = Integer.valueOf(i); + colWidths.put(col, width); + } + getColumnConfiguration().setColumnWidths(colWidths); + }); } } } @@ -4001,6 +4010,9 @@ public class Escalator extends Widget private boolean measuringRequested = false; public void setWidth(double px) { + Profiler.enter( + "Escalator.ColumnConfigurationImpl.Column.setWidth"); + definedWidth = px; if (px < 0) { @@ -4016,6 +4028,9 @@ public class Escalator extends Widget } else { calculatedWidth = px; } + + Profiler.leave( + "Escalator.ColumnConfigurationImpl.Column.setWidth"); } public double getDefinedWidth() { @@ -4389,24 +4404,32 @@ public class Escalator extends Widget return; } - for (Entry<Integer, Double> entry : indexWidthMap.entrySet()) { - int index = entry.getKey().intValue(); - double width = entry.getValue().doubleValue(); + Profiler.enter("Escalator.ColumnConfigurationImpl.setColumnWidths"); + try { - checkValidColumnIndex(index); + for (Entry<Integer, Double> entry : indexWidthMap.entrySet()) { + int index = entry.getKey().intValue(); + double width = entry.getValue().doubleValue(); - // Not all browsers will accept any fractional size.. - width = WidgetUtil.roundSizeDown(width); - columns.get(index).setWidth(width); + checkValidColumnIndex(index); - } + // Not all browsers will accept any fractional size.. + width = WidgetUtil.roundSizeDown(width); + columns.get(index).setWidth(width); - widthsArray = null; - header.reapplyColumnWidths(); - body.reapplyColumnWidths(); - footer.reapplyColumnWidths(); + } - recalculateElementSizes(); + widthsArray = null; + header.reapplyColumnWidths(); + body.reapplyColumnWidths(); + footer.reapplyColumnWidths(); + + recalculateElementSizes(); + + } finally { + Profiler.leave( + "Escalator.ColumnConfigurationImpl.setColumnWidths"); + } } private void checkValidColumnIndex(int index) diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index a58418d443..0b0642668f 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -5002,7 +5002,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, if (this.sortable != sortable) { this.sortable = sortable; if (grid != null) { - grid.refreshHeader(); + grid.getHeader().requestSectionRefresh(); } } return this; @@ -5035,7 +5035,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, if (this.resizable != resizable) { this.resizable = resizable; if (grid != null) { - grid.refreshHeader(); + grid.getHeader().requestSectionRefresh(); } } return this; @@ -8720,12 +8720,14 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, protected void onAttach() { super.onAttach(); + // Grid was just attached to DOM. Column widths should be + // calculated. + recalculateColumnWidths(); + if (getEscalator().getBody().getRowCount() == 0 && dataSource != null) { setEscalatorSizeFromDataSource(); } - // Grid was just attached to DOM. Column widths should be calculated. - recalculateColumnWidths(); for (int row : reattachVisibleDetails) { setDetailsVisible(row, true); } |