Browse Source

Fix typo that caused spanned cells to be removed in Gridlayout (#14335)

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: I1c25a8e6426e6ce0e24f9110a6b994598c395e7a
tags/7.3.0.rc1
Markus Koivisto 9 years ago
parent
commit
92da25c0b4

+ 10
- 10
client/src/com/vaadin/client/ui/VGridLayout.java View File

@@ -95,7 +95,7 @@ public class VGridLayout extends ComplexPanel {

/**
* Returns the column widths measured in pixels
*
*
* @return
*/
protected int[] getColumnWidths() {
@@ -104,7 +104,7 @@ public class VGridLayout extends ComplexPanel {

/**
* Returns the row heights measured in pixels
*
*
* @return
*/
protected int[] getRowHeights() {
@@ -113,7 +113,7 @@ public class VGridLayout extends ComplexPanel {

/**
* Returns the spacing between the cells horizontally in pixels
*
*
* @return
*/
protected int getHorizontalSpacing() {
@@ -122,7 +122,7 @@ public class VGridLayout extends ComplexPanel {

/**
* Returns the spacing between the cells vertically in pixels
*
*
* @return
*/
protected int getVerticalSpacing() {
@@ -271,7 +271,7 @@ public class VGridLayout extends ComplexPanel {
}
for (SpanList l : rowSpans) {
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;
}
}
@@ -287,7 +287,7 @@ public class VGridLayout extends ComplexPanel {
}
for (SpanList l : colSpans) {
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;
}
}
@@ -751,7 +751,7 @@ public class VGridLayout extends ComplexPanel {
* Creates a new Cell with the given coordinates.
* <p>
* For internal use only. May be removed or replaced in the future.
*
*
* @param row
* @param col
* @return
@@ -767,7 +767,7 @@ public class VGridLayout extends ComplexPanel {
* child component is also returned if "element" is part of its caption.
* <p>
* For internal use only. May be removed or replaced in the future.
*
*
* @param element
* An element that is a nested sub element of the root element in
* this layout
@@ -788,13 +788,13 @@ public class VGridLayout extends ComplexPanel {
* child component is also returned if "element" is part of its caption.
* <p>
* For internal use only. May be removed or replaced in the future.
*
*
* @param element
* An element that is a nested sub element of the root element in
* this layout
* @return The Paintable which the element is a part of. Null if the element
* belongs to the layout and not to a child.
*
*
* @since 7.2
*/
public ComponentConnector getComponent(Element element) {

+ 54
- 0
uitest/src/com/vaadin/tests/layouts/gridlayout/GridSpanEmptyColumns.java View File

@@ -0,0 +1,54 @@
/*
* 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;
}
}

+ 50
- 0
uitest/src/com/vaadin/tests/layouts/gridlayout/GridSpanEmptyColumnsTest.java View File

@@ -0,0 +1,50 @@
/*
* 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);

}

}

Loading…
Cancel
Save