Gridlayout removes columns and rows with no content. Gridlayout is supposed to check for spanned cells and not remove otherwise empty rows or columns if they are covered by a span. Change-Id: I1c25a8e6426e6ce0e24f9110a6b994598c395e7atags/7.3.0.rc1
/** | /** | ||||
* Returns the column widths measured in pixels | * Returns the column widths measured in pixels | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
protected int[] getColumnWidths() { | protected int[] getColumnWidths() { | ||||
/** | /** | ||||
* Returns the row heights measured in pixels | * Returns the row heights measured in pixels | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
protected int[] getRowHeights() { | protected int[] getRowHeights() { | ||||
/** | /** | ||||
* Returns the spacing between the cells horizontally in pixels | * Returns the spacing between the cells horizontally in pixels | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
protected int getHorizontalSpacing() { | protected int getHorizontalSpacing() { | ||||
/** | /** | ||||
* Returns the spacing between the cells vertically in pixels | * Returns the spacing between the cells vertically in pixels | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
protected int getVerticalSpacing() { | protected int getVerticalSpacing() { | ||||
} | } | ||||
for (SpanList l : rowSpans) { | for (SpanList l : rowSpans) { | ||||
for (Cell cell : l.cells) { | for (Cell cell : l.cells) { | ||||
if (cell.row >= i && i < cell.row + cell.rowspan) { | |||||
if (cell.row <= i && i < cell.row + cell.rowspan) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (SpanList l : colSpans) { | for (SpanList l : colSpans) { | ||||
for (Cell cell : l.cells) { | for (Cell cell : l.cells) { | ||||
if (cell.col >= i && i < cell.col + cell.colspan) { | |||||
if (cell.col <= i && i < cell.col + cell.colspan) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
* Creates a new Cell with the given coordinates. | * Creates a new Cell with the given coordinates. | ||||
* <p> | * <p> | ||||
* For internal use only. May be removed or replaced in the future. | * For internal use only. May be removed or replaced in the future. | ||||
* | |||||
* | |||||
* @param row | * @param row | ||||
* @param col | * @param col | ||||
* @return | * @return | ||||
* child component is also returned if "element" is part of its caption. | * child component is also returned if "element" is part of its caption. | ||||
* <p> | * <p> | ||||
* For internal use only. May be removed or replaced in the future. | * For internal use only. May be removed or replaced in the future. | ||||
* | |||||
* | |||||
* @param element | * @param element | ||||
* An element that is a nested sub element of the root element in | * An element that is a nested sub element of the root element in | ||||
* this layout | * this layout | ||||
* child component is also returned if "element" is part of its caption. | * child component is also returned if "element" is part of its caption. | ||||
* <p> | * <p> | ||||
* For internal use only. May be removed or replaced in the future. | * For internal use only. May be removed or replaced in the future. | ||||
* | |||||
* | |||||
* @param element | * @param element | ||||
* An element that is a nested sub element of the root element in | * An element that is a nested sub element of the root element in | ||||
* this layout | * this layout | ||||
* @return The Paintable which the element is a part of. Null if the element | * @return The Paintable which the element is a part of. Null if the element | ||||
* belongs to the layout and not to a child. | * belongs to the layout and not to a child. | ||||
* | |||||
* | |||||
* @since 7.2 | * @since 7.2 | ||||
*/ | */ | ||||
public ComponentConnector getComponent(Element element) { | public ComponentConnector getComponent(Element element) { |
/* | |||||
* Copyright 2000-2014 Vaadin Ltd. | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||||
* use this file except in compliance with the License. You may obtain a copy of | |||||
* the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||||
* License for the specific language governing permissions and limitations under | |||||
* the License. | |||||
*/ | |||||
package com.vaadin.tests.layouts.gridlayout; | |||||
import com.vaadin.server.VaadinRequest; | |||||
import com.vaadin.tests.components.AbstractTestUI; | |||||
import com.vaadin.ui.GridLayout; | |||||
import com.vaadin.ui.Label; | |||||
/** | |||||
* | |||||
* @since | |||||
* @author Vaadin Ltd | |||||
*/ | |||||
public class GridSpanEmptyColumns extends AbstractTestUI { | |||||
@Override | |||||
protected void setup(VaadinRequest request) { | |||||
GridLayout gridLayout = new GridLayout(3, 1); | |||||
gridLayout.setWidth("1000px"); | |||||
Label bigCell = new Label("big cell"); | |||||
bigCell.setId("bigCell"); | |||||
Label smallCell = new Label("small cell"); | |||||
smallCell.setId("smallCell"); | |||||
gridLayout.addComponent(bigCell, 0, 0, 1, 0); // spans first two columns | |||||
gridLayout.addComponent(smallCell, 2, 0, 2, 0); // last column only | |||||
addComponent(gridLayout); | |||||
} | |||||
@Override | |||||
protected String getTestDescription() { | |||||
return "A 3x1 grid has a spanned component on the first two cells and a component on the last cell. The two components should occupy 2/3 and 1/3 of the available space respectively, instead of 1/2 each."; | |||||
} | |||||
@Override | |||||
protected Integer getTicketNumber() { | |||||
return 14335; | |||||
} | |||||
} |
/* | |||||
* Copyright 2000-2014 Vaadin Ltd. | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||||
* use this file except in compliance with the License. You may obtain a copy of | |||||
* the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||||
* License for the specific language governing permissions and limitations under | |||||
* the License. | |||||
*/ | |||||
package com.vaadin.tests.layouts.gridlayout; | |||||
import static org.junit.Assert.assertEquals; | |||||
import java.io.IOException; | |||||
import org.junit.Test; | |||||
import com.vaadin.testbench.elements.LabelElement; | |||||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||||
/** | |||||
* Tests that GridLayout handles elements spanning otherwise empty columns | |||||
* correctly (#14335) | |||||
* | |||||
* @since 7.2.5 | |||||
* @author markus | |||||
*/ | |||||
public class GridSpanEmptyColumnsTest extends MultiBrowserTest { | |||||
@Test | |||||
public void componentsShouldMoveRight() throws IOException { | |||||
openTestURL(); | |||||
LabelElement bigCell = $(LabelElement.class).id("bigCell"); | |||||
LabelElement smallCell = $(LabelElement.class).id("smallCell"); | |||||
// Width is 1000px. Big cell should take up 2/3, small cell should take | |||||
// up 1/3. | |||||
assertEquals(667, bigCell.getSize().width); | |||||
assertEquals(333, smallCell.getSize().width); | |||||
} | |||||
} |