summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/com/vaadin/client/connectors/GridConnector.java2
-rw-r--r--client/src/com/vaadin/client/widget/grid/EventCellReference.java12
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java6
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java8
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/AbstractContextClickUI.java18
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/GridContextClick.java20
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java16
7 files changed, 68 insertions, 14 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java
index 0a6ba1642e..cd7007efec 100644
--- a/client/src/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/com/vaadin/client/connectors/GridConnector.java
@@ -1188,7 +1188,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
Section section = eventCell.getSection();
String rowKey = null;
- if (eventCell.isBody()) {
+ if (eventCell.isBody() && eventCell.getRow() != null) {
rowKey = getRowKey(eventCell.getRow());
}
diff --git a/client/src/com/vaadin/client/widget/grid/EventCellReference.java b/client/src/com/vaadin/client/widget/grid/EventCellReference.java
index 3066e5c1db..4d37be2cc1 100644
--- a/client/src/com/vaadin/client/widget/grid/EventCellReference.java
+++ b/client/src/com/vaadin/client/widget/grid/EventCellReference.java
@@ -49,13 +49,19 @@ public class EventCellReference<T> extends CellReference<T> {
*/
public void set(Cell targetCell, Section section) {
Grid<T> grid = getGrid();
- int row = targetCell.getRow();
+
int columnIndexDOM = targetCell.getColumn();
- Column<?, T> column = grid.getVisibleColumns().get(columnIndexDOM);
+ Column<?, T> column = null;
+ if (columnIndexDOM >= 0
+ && columnIndexDOM < grid.getVisibleColumns().size()) {
+ column = grid.getVisibleColumns().get(columnIndexDOM);
+ }
+ int row = targetCell.getRow();
// Row objects only make sense for body section of Grid.
T rowObject;
- if (section == Section.BODY) {
+ if (section == Section.BODY && row >= 0
+ && row < grid.getDataSource().size()) {
rowObject = grid.getDataSource().getRow(row);
} else {
rowObject = null;
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 9916d085de..90c801fc4a 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -6982,7 +6982,11 @@ public class Grid<T> extends ResizeComposite implements
cell = new Cell(rowIndex, colIndex, cellElement);
} else {
- // Click in a place that does not have a column.
+ if (escalator.getElement().isOrHasChild(e)) {
+ eventCell.set(new Cell(-1, -1, null), Section.BODY);
+ // Fire native events.
+ super.onBrowserEvent(event);
+ }
return;
}
}
diff --git a/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java b/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java
index cff063db5f..272cbfdc0e 100644
--- a/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java
+++ b/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickTest.java
@@ -79,7 +79,9 @@ public abstract class AbstractContextClickTest extends MultiBrowserTest {
AbstractComponentElement component = $(AbstractComponentElement.class)
.id("testComponent");
- contextClick(component);
+ int x = 20;
+ int y = 20;
+ contextClick(component, x, y);
Point l = component.getLocation();
@@ -91,8 +93,8 @@ public abstract class AbstractContextClickTest extends MultiBrowserTest {
int xCoord = Integer.parseInt(matcher.group(1));
int yCoord = Integer.parseInt(matcher.group(2));
- int xExpected = l.getX() + 10;
- int yExpected = l.getY() + 10;
+ int xExpected = l.getX() + x;
+ int yExpected = l.getY() + y;
Assert.assertTrue(
"X Coordinate differs too much from expected. Expected: "
diff --git a/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickUI.java b/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickUI.java
index 9a0ef31692..e1d741ee88 100644
--- a/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickUI.java
+++ b/uitest/src/com/vaadin/tests/contextclick/AbstractContextClickUI.java
@@ -23,6 +23,7 @@ import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.HorizontalLayout;
@Theme("valo")
public abstract class AbstractContextClickUI<T extends AbstractComponent, E extends ContextClickEvent>
@@ -79,14 +80,21 @@ public abstract class AbstractContextClickUI<T extends AbstractComponent, E exte
testComponent.setId("testComponent");
addComponent(testComponent);
-
- addComponent(new Button("Add/Remove default listener",
- new ListenerHandler(defaultListener)));
- addComponent(new Button("Add/Remove typed listener",
- new ListenerHandler(typedListener)));
+ addComponent(createContextClickControls());
}
protected abstract T createTestComponent();
protected abstract void handleContextClickEvent(E event);
+
+ protected HorizontalLayout createContextClickControls() {
+ HorizontalLayout contextClickControls = new HorizontalLayout();
+ contextClickControls.addComponent(new Button(
+ "Add/Remove default listener", new ListenerHandler(
+ defaultListener)));
+ contextClickControls
+ .addComponent(new Button("Add/Remove typed listener",
+ new ListenerHandler(typedListener)));
+ return contextClickControls;
+ }
}
diff --git a/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java b/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java
index a942a2ab0f..77009a0762 100644
--- a/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java
+++ b/uitest/src/com/vaadin/tests/contextclick/GridContextClick.java
@@ -18,8 +18,11 @@ package com.vaadin.tests.contextclick;
import com.vaadin.data.Item;
import com.vaadin.shared.ui.grid.GridConstants.Section;
import com.vaadin.tests.util.PersonContainer;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.GridContextClickEvent;
+import com.vaadin.ui.HorizontalLayout;
public class GridContextClick extends
AbstractContextClickUI<Grid, GridContextClickEvent> {
@@ -34,7 +37,8 @@ public class GridContextClick extends
"phoneNumber", "address.streetAddress", "address.postalCode",
"address.city");
- grid.setSizeFull();
+ grid.setWidth("100%");
+ grid.setHeight("400px");
return grid;
}
@@ -58,4 +62,18 @@ public class GridContextClick extends
log("ContextClickEvent value: " + value + ", propertyId: " + propertyId
+ ", section: " + event.getSection());
}
+
+ @Override
+ protected HorizontalLayout createContextClickControls() {
+ HorizontalLayout controls = super.createContextClickControls();
+ controls.addComponent(new Button("Remove all content",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ testComponent.getContainerDataSource().removeAllItems();
+ }
+ }));
+ return controls;
+ }
}
diff --git a/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java b/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java
index 25847f8bf2..7b97de2be5 100644
--- a/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java
+++ b/uitest/src/com/vaadin/tests/contextclick/GridContextClickTest.java
@@ -19,9 +19,11 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
public class GridContextClickTest extends AbstractContextClickTest {
+
@Test
public void testBodyContextClickWithTypedListener() {
addOrRemoveTypedListener();
@@ -73,4 +75,18 @@ public class GridContextClickTest extends AbstractContextClickTest {
getLogRow(0));
}
+ @Test
+ public void testContextClickInEmptyGrid() {
+ addOrRemoveTypedListener();
+
+ $(ButtonElement.class).caption("Remove all content").first().click();
+
+ contextClick($(GridElement.class).first(), 100, 100);
+
+ assertEquals(
+ "1. ContextClickEvent value: , propertyId: null, section: BODY",
+ getLogRow(0));
+
+ }
+
}