diff options
author | Henrik Paul <henrik@vaadin.com> | 2014-08-28 16:39:18 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-09-03 15:36:32 +0000 |
commit | 24254eecf49853b9c839f4ea3a5ee5e0fdee70db (patch) | |
tree | 2b8fe619533380885a6e4a25fd7eb3638dcc8b39 /client | |
parent | e29e468727a262983966e9413fee621124471b0a (diff) | |
download | vaadin-framework-24254eecf49853b9c839f4ea3a5ee5e0fdee70db.tar.gz vaadin-framework-24254eecf49853b9c839f4ea3a5ee5e0fdee70db.zip |
Optimizes adding and removing of columns (#13334)
Previously, the scrollbar logic was evaluated once per RowContainer,
which is just silly.
Change-Id: I71ea144054c08b61836ae22ac6c3f6199fa7f524
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/grid/Escalator.java | 74 |
1 files changed, 36 insertions, 38 deletions
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<ColumnConfigurationImpl.Column> removedColumns) { + final int numberOfColumns) { final NodeList<Node> 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); + } } } |