]> source.dussan.org Git - vaadin-framework.git/commitdiff
Reapplying column width on Grid actually reapplies the width (#16900)
authorPekka Hyvönen <pekka@vaadin.com>
Tue, 24 Feb 2015 21:51:31 +0000 (23:51 +0200)
committerLeif Åstrand <leif@vaadin.com>
Tue, 3 Mar 2015 08:30:47 +0000 (08:30 +0000)
Change-Id: I8a0bc92294004411782c6ee5b0e460b892570aa3

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java
uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java

index f9319b39d2e4366dbedba0f113c4f0b9e2d51839..f0b5e590597243606392c1d2ad09f71a6008c7a7 100644 (file)
@@ -3175,7 +3175,7 @@ public class Grid<T> extends ResizeComposite implements
         }
 
         void reapplyWidth() {
-            setWidth(getWidth());
+            scheduleColumnWidthRecalculator();
         }
 
         /**
index 82bf349096d592e2b2330277d720930c42668453..2ba1dbc3113cdca6188cb967d1f2f153f2eb737c 100644 (file)
@@ -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<GridCellElement> headerCells = gridElement.getHeaderCells(0);
+
+        final List<Integer> columnWidths = new ArrayList<Integer>();
+        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();
     }
index 0452aa65d1c6883997b9803bf8092f51a8e52a14..4dc0195f228dbcd87e0636acc794f4120f48d01b 100644 (file)
@@ -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<Column> columns = new ArrayList<Column>(grid.getColumns());
+                Collections.reverse(columns);
+                grid.setColumnOrder(columns.toArray(new Column[columns.size()]));
+            }
+        }, "Component", "State");
     }
 
     private void createColumnsMenu() {