]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merge "Clean up Table popup menu close handler to prevent a memory leak" from 6.8...
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Wed, 8 May 2013 10:49:20 +0000 (10:49 +0000)
committerVaadin Code Review <review@vaadin.com>
Mon, 13 May 2013 14:03:40 +0000 (14:03 +0000)
svn changeset:25919/svn branch:6.8

Change-Id: If0b414588252226947230cf2f7a5a8ab253cc5d7

client/src/com/vaadin/client/ui/VScrollTable.java
client/src/com/vaadin/client/ui/table/TableConnector.java

index b03fa945cd82803a4aaf5eb0267fb3849580782e..8705a826cc149afd30a5d8756078081db87a5db5 100644 (file)
@@ -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,
      * <p>
      * For internal use only. May be removed or replaced in the future.
      */
-    public class ContextMenuDetails {
+    public class ContextMenuDetails implements CloseHandler<PopupPanel> {
         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<PopupPanel> 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?
              * 
index fc31cdf8eae26521ba39f4c68d36950e3f5733c6..6e50bab9abd95bc598879eb8214e4e61a87e9896 100644 (file)
@@ -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);
                 }
             }
         }