summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-09-08 16:46:35 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-12 07:41:18 +0000
commitc3af8b1873d77afb279453cd997ed75be4771ed8 (patch)
tree9c626ec35812209ac67dfc7b590dfc4191f45bf0 /client/src
parentddfafb7388c4f1f37034620c34e75e5d995257f7 (diff)
downloadvaadin-framework-c3af8b1873d77afb279453cd997ed75be4771ed8.tar.gz
vaadin-framework-c3af8b1873d77afb279453cd997ed75be4771ed8.zip
Add ItemClick events to Grid
Change-Id: I9d761245e99cde62d0e56b89e5cbb0398fd4c363
Diffstat (limited to 'client/src')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
index 43be3f0623..863cee0c88 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
@@ -22,17 +22,23 @@ import java.util.List;
import java.util.Map;
import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
import com.vaadin.client.DeferredWorker;
import com.vaadin.client.HasComponentsConnector;
+import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.TooltipInfo;
import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.client.widget.grid.CellReference;
+import com.vaadin.client.widget.grid.events.BodyClickHandler;
+import com.vaadin.client.widget.grid.events.BodyDoubleClickHandler;
+import com.vaadin.client.widget.grid.events.GridClickEvent;
+import com.vaadin.client.widget.grid.events.GridDoubleClickEvent;
import com.vaadin.client.widget.grid.selection.ClickSelectHandler;
import com.vaadin.client.widget.grid.selection.SpaceSelectHandler;
import com.vaadin.client.widget.grid.sort.SortEvent;
@@ -43,6 +49,7 @@ import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.data.selection.SelectionModel.Single;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.grid.GridConstants;
import com.vaadin.shared.ui.grid.GridServerRpc;
import com.vaadin.shared.ui.grid.GridState;
@@ -59,12 +66,40 @@ public class GridConnector
extends AbstractListingConnector<SelectionModel<JsonObject>>
implements HasComponentsConnector, SimpleManagedLayout, DeferredWorker {
+ private class ItemClickHandler
+ implements BodyClickHandler, BodyDoubleClickHandler {
+
+ @Override
+ public void onClick(GridClickEvent event) {
+ if (hasEventListener(GridConstants.ITEM_CLICK_EVENT_ID)) {
+ fireItemClick(event.getTargetCell(), event.getNativeEvent());
+ }
+ }
+
+ @Override
+ public void onDoubleClick(GridDoubleClickEvent event) {
+ if (hasEventListener(GridConstants.ITEM_CLICK_EVENT_ID)) {
+ fireItemClick(event.getTargetCell(), event.getNativeEvent());
+ }
+ }
+
+ private void fireItemClick(CellReference<?> cell,
+ NativeEvent mouseEvent) {
+ String rowKey = getRowKey((JsonObject) cell.getRow());
+ String columnId = columnToIdMap.get(cell.getColumn());
+ getRpcProxy(GridServerRpc.class).itemClick(rowKey, columnId,
+ MouseEventDetailsBuilder
+ .buildMouseEventDetails(mouseEvent));
+ }
+ }
+
/* Map to keep track of all added columns */
private Map<Column<?, JsonObject>, String> columnToIdMap = new HashMap<>();
/* Child component list for HasComponentsConnector */
private List<ComponentConnector> childComponents;
private SpaceSelectHandler<JsonObject> spaceSelectHandler;
private ClickSelectHandler<JsonObject> clickSelectHandler;
+ private ItemClickHandler itemClickHandler = new ItemClickHandler();
/**
* Gets the string identifier of a {@link Column} in this grid.
@@ -114,6 +149,10 @@ public class GridConnector
return null;
});
+ /* Item click events */
+ getWidget().addBodyClickHandler(itemClickHandler);
+ getWidget().addBodyDoubleClickHandler(itemClickHandler);
+
layout();
}