From 29eeda592cf0f219582f1ccc9320457ca630a28e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Wed, 8 May 2013 10:49:20 +0000 Subject: [PATCH] Merge "Clean up Table popup menu close handler to prevent a memory leak" from 6.8 (#11840) svn changeset:25919/svn branch:6.8 Change-Id: If0b414588252226947230cf2f7a5a8ab253cc5d7 --- .../com/vaadin/client/ui/VScrollTable.java | 31 ++++++++++++++----- .../client/ui/table/TableConnector.java | 5 ++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index b03fa945cd..8705a826cc 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -60,6 +60,7 @@ import com.google.gwt.event.dom.client.ScrollEvent; import com.google.gwt.event.dom.client.ScrollHandler; import com.google.gwt.event.logical.shared.CloseEvent; import com.google.gwt.event.logical.shared.CloseHandler; +import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; @@ -556,15 +557,24 @@ public class VScrollTable extends FlowPanel implements HasWidgets, *

* For internal use only. May be removed or replaced in the future. */ - public class ContextMenuDetails { + public class ContextMenuDetails implements CloseHandler { public String rowKey; public int left; public int top; + HandlerRegistration closeRegistration; - public ContextMenuDetails(String rowKey, int left, int top) { + public ContextMenuDetails(VContextMenu menu, String rowKey, int left, + int top) { this.rowKey = rowKey; this.left = left; this.top = top; + this.closeRegistration = menu.addCloseHandler(this); + } + + @Override + public void onClose(CloseEvent event) { + contextMenu = null; + closeRegistration.removeHandler(); } } @@ -6021,15 +6031,20 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public void showContextMenu(Event event) { if (enabled && actionKeys != null) { // Show context menu if there are registered action handlers - int left = Util.getTouchOrMouseClientX(event); - int top = Util.getTouchOrMouseClientY(event); - top += Window.getScrollTop(); - left += Window.getScrollLeft(); - contextMenu = new ContextMenuDetails(getKey(), left, top); - client.getContextMenu().showAt(this, left, top); + int left = Util.getTouchOrMouseClientX(event) + + Window.getScrollLeft(); + int top = Util.getTouchOrMouseClientY(event) + + Window.getScrollTop(); + showContextMenu(left, top); } } + public void showContextMenu(int left, int top) { + VContextMenu menu = client.getContextMenu(); + contextMenu = new ContextMenuDetails(menu, getKey(), left, top); + menu.showAt(this, left, top); + } + /** * Has the row been selected? * diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index fc31cdf8ea..6e50bab9ab 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -364,9 +364,8 @@ public class TableConnector extends AbstractHasComponentsConnector implements Widget w = iterator.next(); VScrollTableRow row = (VScrollTableRow) w; if (row.getKey().equals(savedContextMenu.rowKey)) { - getWidget().contextMenu = savedContextMenu; - getConnection().getContextMenu().showAt(row, - savedContextMenu.left, savedContextMenu.top); + row.showContextMenu(savedContextMenu.left, + savedContextMenu.top); } } } -- 2.39.5