diff options
author | Teppo Kurki <teppo.kurki@vaadin.com> | 2015-07-06 11:59:00 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-07-14 12:11:20 +0000 |
commit | b9c0971afe9596329bd1a7e12f2cca1e647a80d4 (patch) | |
tree | 4ea584909e74cffb367da5ffa8a922c0e6d0d2c0 | |
parent | 00d622a0dd81ecd131705a1d1359f554de7e1430 (diff) | |
download | vaadin-framework-b9c0971afe9596329bd1a7e12f2cca1e647a80d4.tar.gz vaadin-framework-b9c0971afe9596329bd1a7e12f2cca1e647a80d4.zip |
Fixes scrollToLine while resizing Grid via split position (#18424)
Change-Id: I5ecd8a91bd1ebea809d04a54307fcd752fbe3f39
3 files changed, 177 insertions, 44 deletions
diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 436b512294..a6247aee12 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -6022,10 +6022,14 @@ public class Escalator extends Widget implements RequiresResize, public void scrollToRow(final int rowIndex, final ScrollDestination destination, final int padding) throws IndexOutOfBoundsException, IllegalArgumentException { - validateScrollDestination(destination, padding); - verifyValidRowIndex(rowIndex); - - scroller.scrollToRow(rowIndex, destination, padding); + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + validateScrollDestination(destination, padding); + verifyValidRowIndex(rowIndex); + scroller.scrollToRow(rowIndex, destination, padding); + } + }); } private void verifyValidRowIndex(final int rowIndex) { @@ -6086,55 +6090,62 @@ public class Escalator extends Widget implements RequiresResize, * {@code destination == null}; or if {@code rowIndex == -1} and * there is no spacer open at that index. */ - public void scrollToRowAndSpacer(int rowIndex, - ScrollDestination destination, int padding) + public void scrollToRowAndSpacer(final int rowIndex, + final ScrollDestination destination, final int padding) throws IllegalArgumentException { - validateScrollDestination(destination, padding); - if (rowIndex != -1) { - verifyValidRowIndex(rowIndex); - } + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + validateScrollDestination(destination, padding); + if (rowIndex != -1) { + verifyValidRowIndex(rowIndex); + } - // row range - final Range rowRange; - if (rowIndex != -1) { - int rowTop = (int) Math.floor(body.getRowTop(rowIndex)); - int rowHeight = (int) Math.ceil(body.getDefaultRowHeight()); - rowRange = Range.withLength(rowTop, rowHeight); - } else { - rowRange = Range.withLength(0, 0); - } + // row range + final Range rowRange; + if (rowIndex != -1) { + int rowTop = (int) Math.floor(body.getRowTop(rowIndex)); + int rowHeight = (int) Math.ceil(body.getDefaultRowHeight()); + rowRange = Range.withLength(rowTop, rowHeight); + } else { + rowRange = Range.withLength(0, 0); + } - // get spacer - final SpacerContainer.SpacerImpl spacer = body.spacerContainer - .getSpacer(rowIndex); + // get spacer + final SpacerContainer.SpacerImpl spacer = body.spacerContainer + .getSpacer(rowIndex); - if (rowIndex == -1 && spacer == null) { - throw new IllegalArgumentException("Cannot scroll to row index " - + "-1, as there is no spacer open at that index."); - } + if (rowIndex == -1 && spacer == null) { + throw new IllegalArgumentException( + "Cannot scroll to row index " + + "-1, as there is no spacer open at that index."); + } - // make into target range - final Range targetRange; - if (spacer != null) { - final int spacerTop = (int) Math.floor(spacer.getTop()); - final int spacerHeight = (int) Math.ceil(spacer.getHeight()); - Range spacerRange = Range.withLength(spacerTop, spacerHeight); + // make into target range + final Range targetRange; + if (spacer != null) { + final int spacerTop = (int) Math.floor(spacer.getTop()); + final int spacerHeight = (int) Math.ceil(spacer.getHeight()); + Range spacerRange = Range.withLength(spacerTop, + spacerHeight); - targetRange = rowRange.combineWith(spacerRange); - } else { - targetRange = rowRange; - } + targetRange = rowRange.combineWith(spacerRange); + } else { + targetRange = rowRange; + } - // get params - int targetStart = targetRange.getStart(); - int targetEnd = targetRange.getEnd(); - double viewportStart = getScrollTop(); - double viewportEnd = viewportStart + body.getHeightOfSection(); + // get params + int targetStart = targetRange.getStart(); + int targetEnd = targetRange.getEnd(); + double viewportStart = getScrollTop(); + double viewportEnd = viewportStart + body.getHeightOfSection(); - double scrollPos = getScrollPos(destination, targetStart, targetEnd, - viewportStart, viewportEnd, padding); + double scrollPos = getScrollPos(destination, targetStart, + targetEnd, viewportStart, viewportEnd, padding); - setScrollTop(scrollPos); + setScrollTop(scrollPos); + } + }); } private static void validateScrollDestination( diff --git a/uitest/src/com/vaadin/tests/components/grid/GridScrollToLineWhileResizing.java b/uitest/src/com/vaadin/tests/components/grid/GridScrollToLineWhileResizing.java new file mode 100644 index 0000000000..194a9a3acc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridScrollToLineWhileResizing.java @@ -0,0 +1,73 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import com.vaadin.data.Item; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.VerticalSplitPanel; + +public class GridScrollToLineWhileResizing extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final VerticalSplitPanel vsp = new VerticalSplitPanel(); + vsp.setWidth(500, Unit.PIXELS); + vsp.setHeight(500, Unit.PIXELS); + vsp.setSplitPosition(100, Unit.PERCENTAGE); + addComponent(vsp); + + IndexedContainer indexedContainer = new IndexedContainer(); + indexedContainer.addContainerProperty("column1", String.class, ""); + + for (int i = 0; i < 100; i++) { + Item addItem = indexedContainer.addItem(i); + addItem.getItemProperty("column1").setValue("cell" + i); + } + + final Grid grid = new Grid(indexedContainer); + grid.setSizeFull(); + + grid.setSelectionMode(SelectionMode.SINGLE); + grid.addSelectionListener(new SelectionListener() { + + @Override + public void select(SelectionEvent event) { + vsp.setSplitPosition(50, Unit.PERCENTAGE); + grid.scrollTo(event.getSelected().iterator().next()); + } + }); + + vsp.setFirstComponent(grid); + } + + @Override + protected String getTestDescription() { + return "Tests scrollToLine while moving SplitPanel split position to resize the Grid on the same round-trip."; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridScrollToLineWhileResizingTest.java b/uitest/src/com/vaadin/tests/components/grid/GridScrollToLineWhileResizingTest.java new file mode 100644 index 0000000000..aee1db7a85 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridScrollToLineWhileResizingTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridScrollToLineWhileResizingTest extends MultiBrowserTest { + + @Test + public void testScrollToLineWorksWhileMovingSplitProgrammatically() { + openTestURL(); + + $(GridElement.class).first().getCell(21, 0).click(); + + List<WebElement> cells = findElements(By.className("v-grid-cell")); + boolean foundCell21 = false; + for (WebElement cell : cells) { + if ("cell21".equals(cell.getText())) { + foundCell21 = true; + } + } + + assertTrue(foundCell21); + } +}
\ No newline at end of file |