From b4a5adca6c2d69bb521ae71fd584bef7a320e7d0 Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Tue, 3 Mar 2015 16:49:19 +0200 Subject: Adds support for -1 row index Escalator spacers (#16644) Change-Id: Iced2f089785983ce2ef1d2225517156cec4a7db4 --- .../src/com/vaadin/client/widget/escalator/RowContainer.java | 3 ++- client/src/com/vaadin/client/widgets/Escalator.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/widget/escalator/RowContainer.java b/client/src/com/vaadin/client/widget/escalator/RowContainer.java index e2baf9a03b..b7aae1f4f3 100644 --- a/client/src/com/vaadin/client/widget/escalator/RowContainer.java +++ b/client/src/com/vaadin/client/widget/escalator/RowContainer.java @@ -57,7 +57,8 @@ public interface RowContainer { * * @param rowIndex * the row index for the spacer to modify. The affected - * spacer is underneath the given index + * spacer is underneath the given index. Use -1 to insert a + * spacer before the first row * @param height * the pixel height of the spacer. If {@code height} is * negative, the affected spacer (if exists) will be removed diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 1d7d9a9910..9b11e7aec1 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -4453,8 +4453,15 @@ public class Escalator extends Widget implements RequiresResize, .getScrollSize() + heightDiff); } + /* + * Don't modify the scrollbars if we're expanding the -1 spacer + * while we're scrolled to the top. + */ + boolean minusOneSpacerException = spacerIsGrowing + && getRow() == -1 && body.getTopRowLogicalIndex() == 0; + boolean viewportNeedsScrolling = getRow() < body - .getTopRowLogicalIndex(); + .getTopRowLogicalIndex() && !minusOneSpacerException; if (viewportNeedsScrolling) { /* @@ -4570,7 +4577,7 @@ public class Escalator extends Widget implements RequiresResize, public void setSpacer(int rowIndex, double height) throws IllegalArgumentException { - if (rowIndex < 0 || rowIndex >= getBody().getRowCount()) { + if (rowIndex < -1 || rowIndex >= getBody().getRowCount()) { throw new IllegalArgumentException("invalid row index: " + rowIndex + ", while the body only has " + getBody().getRowCount() + " rows."); -- cgit v1.2.3