]> source.dussan.org Git - vaadin-framework.git/commitdiff
#4376 Tree/Table: Context menu shadow is wrong on first click if it has an icon
authorArtur Signell <artur.signell@itmill.com>
Mon, 3 Jan 2011 13:02:15 +0000 (13:02 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 3 Jan 2011 13:02:15 +0000 (13:02 +0000)
Improved to lazily resize after all (or most) icons have been loaded

svn changeset:16760/svn branch:6.5

src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java
src/com/vaadin/terminal/gwt/client/ui/VLazyExecutor.java [new file with mode: 0644]

index 8345979e2ca5dd664c8015db6b68e3e3d99a4c8b..a5de7f9d22e1b3eab1d7bfa83d40b328da620d10 100644 (file)
@@ -5,6 +5,7 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.dom.client.TableRowElement;
 import com.google.gwt.dom.client.TableSectionElement;
@@ -44,6 +45,13 @@ public class VContextMenu extends VOverlay implements SubPartAware {
 
     private int top;
 
+    private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor(
+            100, new ScheduledCommand() {
+                public void execute() {
+                    imagesLoaded();
+                }
+            });
+
     /**
      * This method should be used only by Client object as only one per client
      * should exists. Request an instance via client.getContextMenu();
@@ -57,6 +65,12 @@ public class VContextMenu extends VOverlay implements SubPartAware {
         setStyleName("v-contextmenu");
     }
 
+    protected void imagesLoaded() {
+        if (isVisible()) {
+            show();
+        }
+    }
+
     /**
      * Sets the element from which to build menu
      * 
@@ -205,9 +219,7 @@ public class VContextMenu extends VOverlay implements SubPartAware {
                 Util.doIE6PngFix((Element) Element.as(event.getNativeEvent()
                         .getEventTarget()));
             }
-            if (isVisible()) {
-                show();
-            }
+            delayedImageLoadExecutioner.trigger();
         }
 
     }
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLazyExecutor.java b/src/com/vaadin/terminal/gwt/client/ui/VLazyExecutor.java
new file mode 100644 (file)
index 0000000..8fe8a96
--- /dev/null
@@ -0,0 +1,49 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;\r
+import com.google.gwt.user.client.Timer;\r
+\r
+/**\r
+ * Executes the given command {@code delayMs} milliseconds after a call to\r
+ * {@link #trigger()}. Calling {@link #trigger()} again before the command has\r
+ * been executed causes the execution to be rescheduled to {@code delayMs} after\r
+ * the second call.\r
+ * \r
+ */\r
+public class VLazyExecutor {\r
+\r
+    private Timer timer;\r
+    private int delayMs;\r
+    private ScheduledCommand cmd;\r
+\r
+    /**\r
+     * @param delayMs\r
+     *            Delay in milliseconds to wait before executing the command\r
+     * @param cmd\r
+     *            The command to execute\r
+     */\r
+    public VLazyExecutor(int delayMs, ScheduledCommand cmd) {\r
+        this.delayMs = delayMs;\r
+        this.cmd = cmd;\r
+    }\r
+\r
+    /**\r
+     * Triggers execution of the command. Each call reschedules any existing\r
+     * execution to {@link #delayMs} milliseconds from that point in time.\r
+     */\r
+    public void trigger() {\r
+        if (timer == null) {\r
+            timer = new Timer() {\r
+                @Override\r
+                public void run() {\r
+                    timer = null;\r
+                    cmd.execute();\r
+                }\r
+            };\r
+        }\r
+        // Schedule automatically cancels any old schedule\r
+        timer.schedule(delayMs);\r
+\r
+    }\r
+\r
+}\r