]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use special logic for allocating selection col widths (#17091)
authorLeif Åstrand <leif@vaadin.com>
Fri, 20 Mar 2015 14:51:45 +0000 (16:51 +0200)
committerLeif Åstrand <leif@vaadin.com>
Fri, 20 Mar 2015 14:51:45 +0000 (16:51 +0200)
Change-Id: I2d0a80a26e8211d6f5e9110e1476f857803b4d3f

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/GridColumnWidthsWithoutData.java
uitest/src/com/vaadin/tests/components/grid/GridColumnWidthsWithoutDataTest.java

index cb9e9c55d11f359f9b6c18f16c1521297cbf54fc..f4a5b0961cd343551aeae51fe88680f107dad57d 100644 (file)
@@ -2528,7 +2528,7 @@ public class Grid<T> extends ResizeComposite implements
                 final double widthFixed = Math.max(widthAsIs,
                         column.getMinimumWidth());
                 defaultExpandRatios = defaultExpandRatios
-                        && column.getExpandRatio() == -1;
+                        && (column.getExpandRatio() == -1 || column == selectionColumn);
 
                 if (isFixedWidth) {
                     columnSizes.put(indexOfColumn(column), widthFixed);
@@ -2546,7 +2546,8 @@ public class Grid<T> extends ResizeComposite implements
                         .getExpandRatio());
                 final double newWidth = column.getWidthActual();
                 final double maxWidth = getMaxWidth(column);
-                boolean shouldExpand = newWidth < maxWidth && expandRatio > 0;
+                boolean shouldExpand = newWidth < maxWidth && expandRatio > 0
+                        && column != selectionColumn;
                 if (shouldExpand) {
                     totalRatios += expandRatio;
                     columnsToExpand.add(column);
index 1dfc7bcf112c798959b200e874ce38caba0d0afb..b04745f17ab56bb74d4dc8c52f3d0b5ee0559514 100644 (file)
  */
 package com.vaadin.tests.components.grid;
 
+import java.util.EnumSet;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.SelectionMode;
+import com.vaadin.ui.NativeSelect;
 import com.vaadin.ui.VerticalLayout;
 
 public class GridColumnWidthsWithoutData extends AbstractTestUI {
 
+    private SelectionMode selectionMode = SelectionMode.NONE;
     private Grid grid = createGrid(true);
 
     @Override
     protected void setup(VaadinRequest request) {
         addComponent(grid);
 
+        NativeSelect selectionModeSelector = new NativeSelect("Selection mode",
+                EnumSet.allOf(SelectionMode.class));
+        selectionModeSelector.setValue(selectionMode);
+        selectionModeSelector.setNullSelectionAllowed(false);
+        selectionModeSelector.addValueChangeListener(new ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                selectionMode = (SelectionMode) event.getProperty().getValue();
+                grid.setSelectionMode(selectionMode);
+            }
+        });
+        addComponent(selectionModeSelector);
+
         addComponent(new Button("Recreate without data",
                 new Button.ClickListener() {
                     @Override
@@ -72,6 +92,7 @@ public class GridColumnWidthsWithoutData extends AbstractTestUI {
         grid.addColumn("foo");
         grid.addColumn("bar");
         grid.setWidth("300px");
+        grid.setSelectionMode(selectionMode);
 
         if (withData) {
             addDataToGrid(grid);
index dd63d6abc9b3779d4cd04b95ffa1fc0fb729e8e3..c215fa0a59245f58f8619da996be3a2bf7fbe917 100644 (file)
@@ -23,6 +23,7 @@ import org.junit.Test;
 import com.vaadin.testbench.elements.ButtonElement;
 import com.vaadin.testbench.elements.GridElement;
 import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.elements.NativeSelectElement;
 import com.vaadin.testbench.elements.NotificationElement;
 import com.vaadin.tests.tb3.SingleBrowserTest;
 
@@ -49,7 +50,7 @@ public class GridColumnWidthsWithoutDataTest extends SingleBrowserTest {
     }
 
     @Test
-    public void restWidthsWhenInitiallyEmpty() {
+    public void testWidthsWhenInitiallyEmpty() {
         setDebug(true);
         openTestURL();
         $(ButtonElement.class).caption("Recreate without data").first().click();
@@ -74,6 +75,37 @@ public class GridColumnWidthsWithoutDataTest extends SingleBrowserTest {
                 isElementPresent(NotificationElement.class));
     }
 
+    @Test
+    public void testMultiSelectWidths() {
+        setDebug(true);
+        openTestURL();
+        $(NativeSelectElement.class).caption("Selection mode").first()
+                .selectByText("Multi");
+
+        GridElement grid = $(GridElement.class).first();
+
+        int sum = sumUsedWidths(grid);
+
+        // 295 instead of 300 to avoid rounding issues
+        Assert.assertTrue("Only " + sum + " out of 300px was used", sum > 295);
+
+        $(ButtonElement.class).caption("Recreate without data").first().click();
+
+        grid = $(GridElement.class).first();
+        sum = sumUsedWidths(grid);
+
+        // 295 instead of 300 to avoid rounding issues
+        Assert.assertTrue("Only " + sum + " out of 300px was used", sum > 295);
+    }
+
+    private int sumUsedWidths(GridElement grid) {
+        int sum = 0;
+        for (int i : getColWidths(grid)) {
+            sum += i;
+        }
+        return sum;
+    }
+
     private static void assertSameWidths(int[] expected, int[] actual) {
         Assert.assertEquals("Arrays have differing lengths", expected.length,
                 actual.length);