diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2018-01-29 14:48:28 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-01-29 14:48:28 +0200 |
commit | eb398be6f7884bc10239daab7689dd82ae643f7d (patch) | |
tree | 8a40cbaba2a6d01ce3203a9fda92cfc16b829956 | |
parent | fbf5565e30615897124f4c68119bc7cb0a370d8b (diff) | |
download | vaadin-framework-eb398be6f7884bc10239daab7689dd82ae643f7d.tar.gz vaadin-framework-eb398be6f7884bc10239daab7689dd82ae643f7d.zip |
Fix column width in resize event when mode is SIMPLE (#10442)
3 files changed, 88 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index f0b309bae7..4c28ffe244 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -5979,9 +5979,12 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, @Override public void onComplete() { dragEnded(); - col.setWidth(width); - fireEvent(new ColumnResizeEvent<>(col)); + + // Need to wait for column width recalculation + // scheduled by setWidth() before firing the event + Scheduler.get().scheduleDeferred(() -> fireEvent( + new ColumnResizeEvent<>(col))); } }; diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java index be05ed7d87..0deb5b1b3a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java @@ -169,6 +169,7 @@ public class GridBasics extends AbstractTestUIWithLog { private PersistingDetailsGenerator persistingDetails; private List<Column<DataObject, ?>> initialColumnOrder; private Registration selectionListenerRegistration; + private Registration columnResizeListenerRegistration; public GridBasics() { generators.put("NULL", null); @@ -367,6 +368,20 @@ public class GridBasics extends AbstractTestUIWithLog { item -> grid.setColumnResizeMode(item.isChecked() ? ColumnResizeMode.SIMPLE : ColumnResizeMode.ANIMATED)) .setCheckable(true); + + columnsMenu.addItem("Add resize listener", item -> { + if (item.isChecked()) { + columnResizeListenerRegistration = grid.addColumnResizeListener( + event -> log( + "Column resized: caption=" + event.getColumn() + .getCaption() + ", width=" + event + .getColumn().getWidth())); + } else { + if (columnResizeListenerRegistration != null) { + columnResizeListenerRegistration.remove(); + } + } + }).setCheckable(true); } private void createSizeMenu(MenuItem sizeMenu) { diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java index bb8655bd35..a016bed8be 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue; import java.util.List; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebElement; @@ -26,6 +27,7 @@ import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.By; import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.parallel.TestCategory; import com.vaadin.tests.components.grid.basics.GridBasicsTest; @@ -80,4 +82,70 @@ public class GridColumnResizeModeTest extends GridBasicsTest { } + @Test + public void testSimpleResizeModeMultipleDrag() { + GridElement grid = getGridElement(); + + List<WebElement> handles = grid + .findElements(By.className("v-grid-column-resize-handle")); + WebElement handle = handles.get(1); + + GridCellElement cell = grid.getHeaderCell(0, 1); + + int initialWidth = cell.getSize().getWidth(); + + selectMenuPath("Component", "Columns", "Simple resize mode"); + sleep(250); + + drag(handle, 100); + Assert.assertEquals(initialWidth + 100, cell.getSize().getWidth()); + + drag(handle, -100); + Assert.assertEquals(initialWidth, cell.getSize().getWidth()); + } + + @Test + public void testResizeReportedWidth() { + GridElement grid = getGridElement(); + + selectMenuPath("Component", "Columns", "Add resize listener"); + + List<WebElement> handles = grid + .findElements(By.className("v-grid-column-resize-handle")); + WebElement handle = handles.get(1); + + GridCellElement cell = grid.getHeaderCell(0, 1); + + // ANIMATED resize mode + drag(handle, 100); + assertTrue(getLogRow(0).contains( + "Column resized: caption=Column 1, width=" + cell.getSize() + .getWidth())); + + drag(handle, -100); + assertTrue(getLogRow(0).contains( + "Column resized: caption=Column 1, width=" + cell.getSize() + .getWidth())); + + // SIMPLE resize mode + selectMenuPath("Component", "Columns", "Simple resize mode"); + sleep(250); + + drag(handle, 100); + assertTrue(getLogRow(0).contains( + "Column resized: caption=Column 1, width=" + cell.getSize() + .getWidth())); + + drag(handle, -100); + assertTrue(getLogRow(0).contains( + "Column resized: caption=Column 1, width=" + cell.getSize() + .getWidth())); + } + + private void drag(WebElement handle, int xOffset) { + new Actions(getDriver()).moveToElement(handle).clickAndHold() + .moveByOffset(20, 0).moveByOffset(xOffset - 20, 0).release() + .perform(); + sleep(250); + } } |