From f79b9788842cefc50a58aafd476eaa7b817c92f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Hyv=C3=B6nen?= Date: Tue, 24 Feb 2015 23:51:31 +0200 Subject: [PATCH] Reapplying column width on Grid actually reapplies the width (#16900) Change-Id: I8a0bc92294004411782c6ee5b0e460b892570aa3 --- .../src/com/vaadin/client/widgets/Grid.java | 2 +- .../GridClientColumnPropertiesTest.java | 35 +++++++++++++++++++ .../grid/GridBasicClientFeaturesWidget.java | 9 +++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index f9319b39d2..f0b5e59059 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -3175,7 +3175,7 @@ public class Grid extends ResizeComposite implements } void reapplyWidth() { - setWidth(getWidth()); + scheduleColumnWidthRecalculator(); } /** diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java index 82bf349096..2ba1dbc311 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java @@ -19,9 +19,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.List; + import org.junit.Test; import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget; @@ -122,6 +126,37 @@ public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest .getCell(1, 0).getText()); } + @Test + public void testColumnWidths_onColumnReorder_columnWidthsKeptTheSame() { + // given + openTestURL(); + GridElement gridElement = getGridElement(); + List headerCells = gridElement.getHeaderCells(0); + + final List columnWidths = new ArrayList(); + for (GridCellElement cell : headerCells) { + columnWidths.add(cell.getSize().getWidth()); + } + + // when + selectMenuPath("Component", "State", "Reverse grid columns"); + + // then + gridElement = getGridElement(); + headerCells = gridElement.getHeaderCells(0); + final int size = headerCells.size(); + // skip last column since there is a bug in the width of the last column + for (int i = 0; i < size - 1; i++) { + assertEquals( + "Column widths don't match after reset, index after flip " + + i, + columnWidths.get(i), + Integer.valueOf(headerCells.get(size - 1 - i).getSize() + .getWidth())); + } + + } + private boolean cellIsFrozen(int row, int col) { return getGridElement().getCell(row, col).isFrozen(); } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java index 0452aa65d1..4dc0195f22 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java @@ -649,6 +649,15 @@ public class GridBasicClientFeaturesWidget extends grid.setEnabled(!grid.isEnabled()); } }, "Component", "State"); + addMenuCommand("Reverse grid columns", new ScheduledCommand() { + + @Override + public void execute() { + List columns = new ArrayList(grid.getColumns()); + Collections.reverse(columns); + grid.setColumnOrder(columns.toArray(new Column[columns.size()])); + } + }, "Component", "State"); } private void createColumnsMenu() { -- 2.39.5