Procházet zdrojové kódy

Optimizes adding and removing of columns (#13334)

Previously, the scrollbar logic was evaluated once per RowContainer,
which is just silly.

Change-Id: I71ea144054c08b61836ae22ac6c3f6199fa7f524
tags/7.4.0.beta1
Henrik Paul před 9 roky
rodič
revize
24254eecf4
1 změnil soubory, kde provedl 36 přidání a 38 odebrání
  1. 36
    38
      client/src/com/vaadin/client/ui/grid/Escalator.java

+ 36
- 38
client/src/com/vaadin/client/ui/grid/Escalator.java Zobrazit soubor

@@ -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);
}
}
}


Načítá se…
Zrušit
Uložit