aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/main/java/com/vaadin/ui/GridLayout.java12
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java24
2 files changed, 34 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java
index 0a3e139ea9..46275dfdaf 100644
--- a/server/src/main/java/com/vaadin/ui/GridLayout.java
+++ b/server/src/main/java/com/vaadin/ui/GridLayout.java
@@ -203,8 +203,9 @@ public class GridLayout extends AbstractLayout
// Checks the validity of the coordinates
if (column2 < column1 || row2 < row1) {
- throw new IllegalArgumentException(
- "Illegal coordinates for the component");
+ throw new IllegalArgumentException(String.format(
+ "Illegal coordinates for the component: %s!<=%s, %s!<=%s",
+ column1, column2, row1, row2));
}
if (column1 < 0 || row1 < 0 || column2 >= getColumns()
|| row2 >= getRows()) {
@@ -611,6 +612,11 @@ public class GridLayout extends AbstractLayout
return childData.row2;
}
+ @Override
+ public String toString() {
+ return String.format("Area{%s,%s - %s,%s}", getColumn1(), getRow1(),
+ getColumn2(), getRow2());
+ }
}
private static boolean componentsOverlap(ChildComponentData a,
@@ -694,6 +700,8 @@ public class GridLayout extends AbstractLayout
* @param areaOutOfBounds
*/
public OutOfBoundsException(Area areaOutOfBounds) {
+ super(String.format("%s, layout dimension: %sx%s", areaOutOfBounds,
+ getColumns(), getRows()));
this.areaOutOfBounds = areaOutOfBounds;
}
diff --git a/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java b/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java
index abf2e823d5..88b06d7a2d 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java
@@ -99,6 +99,30 @@ public class GridLayoutTest {
assertEquals(1, gl.getColumnExpandRatio(1), 0);
}
+ @Test
+ public void verifyOutOfBoundsExceptionContainsHelpfulMessage() {
+ GridLayout grid = new GridLayout(1, 1);
+ try {
+ grid.addComponent(new Label(), 3, 3);
+ fail("Should have failed");
+ } catch (GridLayout.OutOfBoundsException ex) {
+ assertEquals("Area{3,3 - 3,3}, layout dimension: 1x1",
+ ex.getMessage());
+ }
+ }
+
+ @Test
+ public void verifyAddComponentFailsWithHelpfulMessageOnInvalidArgs() {
+ GridLayout grid = new GridLayout(6, 6);
+ try {
+ grid.addComponent(new Label(), 3, 3, 2, 2);
+ fail("Should have failed");
+ } catch (IllegalArgumentException ex) {
+ assertEquals("Illegal coordinates for the component: 3!<=2, 3!<=2",
+ ex.getMessage());
+ }
+ }
+
private void assertContentPositions(GridLayout grid) {
assertEquals(grid.getComponentCount(), children.length);
int c = 0;