summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-10-01 11:53:23 +0300
committerVaadin Code Review <review@vaadin.com>2015-10-02 08:17:15 +0000
commit4e02b7e7402a1d79298787968065a7773e7e34a8 (patch)
treec8fe0423f7d7ae2b8595bd4d1fb9a92797e871c7 /client
parent6d47320640275234a736ab29979a0dfd8eba4084 (diff)
downloadvaadin-framework-4e02b7e7402a1d79298787968065a7773e7e34a8.tar.gz
vaadin-framework-4e02b7e7402a1d79298787968065a7773e7e34a8.zip
Implement ContextClickEvent for Table (#19042)
This patch also introduces a testing infrastructure for context click event and listener testing. Change-Id: I3aa88758278c91086df3d0971edb34914a93fd29
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/table/TableConnector.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java
index 7bbda39c43..70248d367c 100644
--- a/client/src/com/vaadin/client/ui/table/TableConnector.java
+++ b/client/src/com/vaadin/client/ui/table/TableConnector.java
@@ -22,7 +22,9 @@ import java.util.List;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.Style.Position;
+import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
@@ -32,6 +34,7 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
import com.vaadin.client.DirectionalManagedLayout;
import com.vaadin.client.HasComponentsConnector;
+import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.Paintable;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.TooltipInfo;
@@ -41,9 +44,14 @@ import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.VScrollTable;
import com.vaadin.client.ui.VScrollTable.ContextMenuDetails;
+import com.vaadin.client.ui.VScrollTable.FooterCell;
+import com.vaadin.client.ui.VScrollTable.HeaderCell;
import com.vaadin.client.ui.VScrollTable.VScrollTableBody.VScrollTableRow;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.table.TableConstants;
+import com.vaadin.shared.ui.table.TableConstants.Section;
+import com.vaadin.shared.ui.table.TableServerRpc;
import com.vaadin.shared.ui.table.TableState;
@Connect(com.vaadin.ui.Table.class)
@@ -74,6 +82,59 @@ public class TableConnector extends AbstractFieldConnector implements
getWidget().onUnregister();
}
+ @Override
+ protected void sendContextClickEvent(ContextMenuEvent event) {
+ EventTarget eventTarget = event.getNativeEvent().getEventTarget();
+ if (!Element.is(eventTarget)) {
+ super.sendContextClickEvent(event);
+ return;
+ }
+ Element e = Element.as(eventTarget);
+
+ Section section;
+ String colKey;
+ String rowKey = null;
+ if (getWidget().tFoot.getElement().isOrHasChild(e)) {
+ section = Section.FOOTER;
+ FooterCell w = WidgetUtil.findWidget(e, FooterCell.class);
+ colKey = w.getColKey();
+ } else if (getWidget().tHead.getElement().isOrHasChild(e)) {
+ section = Section.HEADER;
+ HeaderCell w = WidgetUtil.findWidget(e, HeaderCell.class);
+ colKey = w.getColKey();
+ } else if (getWidget().scrollBody.getElement().isOrHasChild(e)) {
+ section = Section.BODY;
+ VScrollTableRow w = WidgetUtil.findWidget(e, VScrollTableRow.class);
+ rowKey = w.getKey();
+ colKey = getWidget().tHead.getHeaderCell(
+ getElementIndex(e, w.getElement())).getColKey();
+ } else {
+ super.sendContextClickEvent(event);
+ return;
+ }
+
+ MouseEventDetails details = MouseEventDetailsBuilder
+ .buildMouseEventDetails(event.getNativeEvent());
+
+ // Prevent browser default context menu
+ event.preventDefault();
+ event.stopPropagation();
+
+ getRpcProxy(TableServerRpc.class).contextClick(rowKey, colKey, section,
+ details);
+ }
+
+ private int getElementIndex(Element e,
+ com.google.gwt.user.client.Element element) {
+ int i = 0;
+ Element current = element.getFirstChildElement();
+ while (!current.isOrHasChild(e)) {
+ current = current.getNextSiblingElement();
+ ++i;
+ }
+ return i;
+ }
+
/*
* (non-Javadoc)
*