From 24254eecf49853b9c839f4ea3a5ee5e0fdee70db Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Thu, 28 Aug 2014 16:39:18 +0300 Subject: Optimizes adding and removing of columns (#13334) Previously, the scrollbar logic was evaluated once per RowContainer, which is just silly. Change-Id: I71ea144054c08b61836ae22ac6c3f6199fa7f524 --- .../src/com/vaadin/client/ui/grid/Escalator.java | 74 +++++++++++----------- 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/grid/Escalator.java b/client/src/com/vaadin/client/ui/grid/Escalator.java index f686ec03ca..b1782afb18 100644 --- a/client/src/com/vaadin/client/ui/grid/Escalator.java +++ b/client/src/com/vaadin/client/ui/grid/Escalator.java @@ -1496,8 +1496,7 @@ public class Escalator extends Widget { throws IndexOutOfBoundsException; protected void paintRemoveColumns(final int offset, - final int numberOfColumns, - final List removedColumns) { + final int numberOfColumns) { final NodeList childNodes = root.getChildNodes(); for (int visualRowIndex = 0; visualRowIndex < childNodes .getLength(); visualRowIndex++) { @@ -1533,25 +1532,6 @@ public class Escalator extends Widget { } reapplyRowWidths(); - final int firstRemovedColumnLeft = columnConfiguration - .getCalculatedColumnsWidth(Range.withLength(0, offset)); - final boolean columnsWereRemovedFromLeftOfTheViewport = scroller.lastScrollLeft > firstRemovedColumnLeft; - - if (columnsWereRemovedFromLeftOfTheViewport) { - int removedColumnsPxAmount = 0; - for (ColumnConfigurationImpl.Column removedColumn : removedColumns) { - removedColumnsPxAmount += removedColumn - .getCalculatedWidth(); - } - final int leftByDiff = (int) (scroller.lastScrollLeft - removedColumnsPxAmount); - final int newScrollLeft = Math.max(firstRemovedColumnLeft, - leftByDiff); - horizontalScrollbar.setScrollPos(newScrollLeft); - } - - // this needs to be after the scroll position adjustment above. - scroller.recalculateScrollbarsForVirtualViewport(); - /* * Because we might remove columns where affected by colspans, it's * easiest to simply redraw everything when columns are modified. @@ -1580,21 +1560,6 @@ public class Escalator extends Widget { } } - // this needs to be before the scrollbar adjustment. - scroller.recalculateScrollbarsForVirtualViewport(); - - int pixelsToInsertedColumn = columnConfiguration - .getCalculatedColumnsWidth(Range.withLength(0, offset)); - final boolean columnsWereAddedToTheLeftOfViewport = scroller.lastScrollLeft > pixelsToInsertedColumn; - - if (columnsWereAddedToTheLeftOfViewport) { - int insertedColumnsWidth = columnConfiguration - .getCalculatedColumnsWidth(Range.withLength(offset, - numberOfColumns)); - horizontalScrollbar.setScrollPos(scroller.lastScrollLeft - + insertedColumnsWidth); - } - /* * Because we might insert columns where affected by colspans, it's * easiest to simply redraw everything when columns are modified. @@ -3627,9 +3592,27 @@ public class Escalator extends Widget { if (hasSomethingInDom()) { for (final AbstractRowContainer rowContainer : rowContainers) { - rowContainer.paintRemoveColumns(index, numberOfColumns, - removedColumns); + rowContainer.paintRemoveColumns(index, numberOfColumns); + } + + final int firstRemovedColumnLeft = columnConfiguration + .getCalculatedColumnsWidth(Range.withLength(0, index)); + final boolean columnsWereRemovedFromLeftOfTheViewport = scroller.lastScrollLeft > firstRemovedColumnLeft; + + if (columnsWereRemovedFromLeftOfTheViewport) { + int removedColumnsPxAmount = 0; + for (ColumnConfigurationImpl.Column removedColumn : removedColumns) { + removedColumnsPxAmount += removedColumn + .getCalculatedWidth(); + } + final int leftByDiff = (int) (scroller.lastScrollLeft - removedColumnsPxAmount); + final int newScrollLeft = Math.max(firstRemovedColumnLeft, + leftByDiff); + horizontalScrollbar.setScrollPos(newScrollLeft); } + + // this needs to be after the scroll position adjustment above. + scroller.recalculateScrollbarsForVirtualViewport(); } } @@ -3699,6 +3682,21 @@ public class Escalator extends Widget { rowContainer.paintInsertColumns(index, numberOfColumns, frozen); } + + // this needs to be before the scrollbar adjustment. + scroller.recalculateScrollbarsForVirtualViewport(); + + int pixelsToInsertedColumn = columnConfiguration + .getCalculatedColumnsWidth(Range.withLength(0, index)); + final boolean columnsWereAddedToTheLeftOfViewport = scroller.lastScrollLeft > pixelsToInsertedColumn; + + if (columnsWereAddedToTheLeftOfViewport) { + int insertedColumnsWidth = columnConfiguration + .getCalculatedColumnsWidth(Range.withLength(index, + numberOfColumns)); + horizontalScrollbar.setScrollPos(scroller.lastScrollLeft + + insertedColumnsWidth); + } } } -- cgit v1.2.3