Change-Id: I2d0a80a26e8211d6f5e9110e1476f857803b4d3ftags/7.5.0.beta1
final double widthFixed = Math.max(widthAsIs, | final double widthFixed = Math.max(widthAsIs, | ||||
column.getMinimumWidth()); | column.getMinimumWidth()); | ||||
defaultExpandRatios = defaultExpandRatios | defaultExpandRatios = defaultExpandRatios | ||||
&& column.getExpandRatio() == -1; | |||||
&& (column.getExpandRatio() == -1 || column == selectionColumn); | |||||
if (isFixedWidth) { | if (isFixedWidth) { | ||||
columnSizes.put(indexOfColumn(column), widthFixed); | columnSizes.put(indexOfColumn(column), widthFixed); | ||||
.getExpandRatio()); | .getExpandRatio()); | ||||
final double newWidth = column.getWidthActual(); | final double newWidth = column.getWidthActual(); | ||||
final double maxWidth = getMaxWidth(column); | final double maxWidth = getMaxWidth(column); | ||||
boolean shouldExpand = newWidth < maxWidth && expandRatio > 0; | |||||
boolean shouldExpand = newWidth < maxWidth && expandRatio > 0 | |||||
&& column != selectionColumn; | |||||
if (shouldExpand) { | if (shouldExpand) { | ||||
totalRatios += expandRatio; | totalRatios += expandRatio; | ||||
columnsToExpand.add(column); | columnsToExpand.add(column); |
*/ | */ | ||||
package com.vaadin.tests.components.grid; | 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.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUI; | import com.vaadin.tests.components.AbstractTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | import com.vaadin.ui.Button.ClickEvent; | ||||
import com.vaadin.ui.Grid; | import com.vaadin.ui.Grid; | ||||
import com.vaadin.ui.Grid.SelectionMode; | |||||
import com.vaadin.ui.NativeSelect; | |||||
import com.vaadin.ui.VerticalLayout; | import com.vaadin.ui.VerticalLayout; | ||||
public class GridColumnWidthsWithoutData extends AbstractTestUI { | public class GridColumnWidthsWithoutData extends AbstractTestUI { | ||||
private SelectionMode selectionMode = SelectionMode.NONE; | |||||
private Grid grid = createGrid(true); | private Grid grid = createGrid(true); | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
addComponent(grid); | 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", | addComponent(new Button("Recreate without data", | ||||
new Button.ClickListener() { | new Button.ClickListener() { | ||||
@Override | @Override | ||||
grid.addColumn("foo"); | grid.addColumn("foo"); | ||||
grid.addColumn("bar"); | grid.addColumn("bar"); | ||||
grid.setWidth("300px"); | grid.setWidth("300px"); | ||||
grid.setSelectionMode(selectionMode); | |||||
if (withData) { | if (withData) { | ||||
addDataToGrid(grid); | addDataToGrid(grid); |
import com.vaadin.testbench.elements.ButtonElement; | import com.vaadin.testbench.elements.ButtonElement; | ||||
import com.vaadin.testbench.elements.GridElement; | import com.vaadin.testbench.elements.GridElement; | ||||
import com.vaadin.testbench.elements.GridElement.GridCellElement; | import com.vaadin.testbench.elements.GridElement.GridCellElement; | ||||
import com.vaadin.testbench.elements.NativeSelectElement; | |||||
import com.vaadin.testbench.elements.NotificationElement; | import com.vaadin.testbench.elements.NotificationElement; | ||||
import com.vaadin.tests.tb3.SingleBrowserTest; | import com.vaadin.tests.tb3.SingleBrowserTest; | ||||
} | } | ||||
@Test | @Test | ||||
public void restWidthsWhenInitiallyEmpty() { | |||||
public void testWidthsWhenInitiallyEmpty() { | |||||
setDebug(true); | setDebug(true); | ||||
openTestURL(); | openTestURL(); | ||||
$(ButtonElement.class).caption("Recreate without data").first().click(); | $(ButtonElement.class).caption("Recreate without data").first().click(); | ||||
isElementPresent(NotificationElement.class)); | 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) { | private static void assertSameWidths(int[] expected, int[] actual) { | ||||
Assert.assertEquals("Arrays have differing lengths", expected.length, | Assert.assertEquals("Arrays have differing lengths", expected.length, | ||||
actual.length); | actual.length); |