if (position instanceof AbsolutePosition) { | if (position instanceof AbsolutePosition) { | ||||
/* | /* | ||||
* we don't want to put "top: 0" on the footer, since it'll | * we don't want to put "top: 0" on the footer, since it'll | ||||
* render wrong, as we already have | |||||
* "bottom: $footer-height". | |||||
* render wrong, as we already have "bottom: $footer-height" | |||||
* . | |||||
*/ | */ | ||||
footElem.getStyle().setLeft(-scrollLeft, Unit.PX); | footElem.getStyle().setLeft(-scrollLeft, Unit.PX); | ||||
} else { | } else { | ||||
assertArgumentsAreValidAndWithinRange(index, numberOfRows); | assertArgumentsAreValidAndWithinRange(index, numberOfRows); | ||||
rows -= numberOfRows; | rows -= numberOfRows; | ||||
if (heightMode == HeightMode.UNDEFINED) { | |||||
heightByRows = rows; | |||||
} | |||||
if (!isAttached()) { | if (!isAttached()) { | ||||
return; | return; | ||||
} | } | ||||
rows += numberOfRows; | rows += numberOfRows; | ||||
if (heightMode == HeightMode.UNDEFINED) { | |||||
heightByRows = rows; | |||||
} | |||||
/* | /* | ||||
* only add items in the DOM if the widget itself is attached to the | * only add items in the DOM if the widget itself is attached to the | ||||
super(bodyElement); | super(bodyElement); | ||||
} | } | ||||
@Override | |||||
public void insertRows(int index, int numberOfRows) { | |||||
super.insertRows(index, numberOfRows); | |||||
if (heightMode == HeightMode.UNDEFINED) { | |||||
heightByRows = getRowCount(); | |||||
} | |||||
} | |||||
@Override | |||||
public void removeRows(int index, int numberOfRows) { | |||||
super.removeRows(index, numberOfRows); | |||||
if (heightMode == HeightMode.UNDEFINED) { | |||||
heightByRows = getRowCount(); | |||||
} | |||||
} | |||||
@Override | @Override | ||||
public void setStylePrimaryName(String primaryStyleName) { | public void setStylePrimaryName(String primaryStyleName) { | ||||
super.setStylePrimaryName(primaryStyleName); | super.setStylePrimaryName(primaryStyleName); |
package com.vaadin.tests.components.grid; | |||||
import com.vaadin.annotations.Theme; | |||||
import com.vaadin.server.VaadinRequest; | |||||
import com.vaadin.shared.ui.grid.HeightMode; | |||||
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.VerticalLayout; | |||||
@Theme("valo") | |||||
public class GridUndefinedHeight extends AbstractTestUI { | |||||
@Override | |||||
protected void setup(VaadinRequest request) { | |||||
VerticalLayout layout = new VerticalLayout(); | |||||
final Grid grid = new Grid(); | |||||
grid.addColumn("toString", String.class); | |||||
grid.addRow("Foo"); | |||||
grid.addRow("Bar"); | |||||
grid.addRow("Baz"); | |||||
grid.setHeightMode(HeightMode.UNDEFINED); | |||||
layout.addComponents(grid, | |||||
new Button("Add header row", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
grid.appendHeaderRow(); | |||||
} | |||||
})); | |||||
layout.setHeight("600px"); | |||||
layout.setExpandRatio(grid, 1.0f); | |||||
addComponent(layout); | |||||
} | |||||
} |
package com.vaadin.tests.components.grid; | |||||
import org.junit.Assert; | |||||
import org.junit.Before; | |||||
import org.junit.Test; | |||||
import com.vaadin.testbench.elements.ButtonElement; | |||||
import com.vaadin.testbench.elements.GridElement; | |||||
import com.vaadin.testbench.parallel.TestCategory; | |||||
import com.vaadin.tests.tb3.SingleBrowserTest; | |||||
@TestCategory("grid") | |||||
public class GridUndefinedHeightTest extends SingleBrowserTest { | |||||
@Before | |||||
public void before() { | |||||
setDebug(true); | |||||
openTestURL(); | |||||
} | |||||
@Test | |||||
public void grid_undefined_height() { | |||||
GridElement grid = $(GridElement.class).first(); | |||||
int oneRow = grid.getRow(0).getSize().getHeight(); | |||||
int gridHeight = grid.getSize().getHeight(); | |||||
int rows = 4; // Header Row + 3 Body Rows | |||||
Assert.assertEquals("Grid height mismatch", oneRow * rows, gridHeight, 1); | |||||
assertNoErrorNotifications(); | |||||
} | |||||
@Test | |||||
public void grid_undefined_height_add_header() { | |||||
// Add header row to Grid | |||||
$(ButtonElement.class).first().click(); | |||||
GridElement grid = $(GridElement.class).first(); | |||||
int oneRow = grid.getRow(0).getSize().getHeight(); | |||||
int gridHeight = grid.getSize().getHeight(); | |||||
int rows = 5; // 2 Header Rows + 3 Body Rows | |||||
Assert.assertEquals("Grid height mismatch", oneRow * rows, gridHeight); | |||||
assertNoErrorNotifications(); | |||||
} | |||||
} |