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;
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();
setStyleName("v-contextmenu");
}
+ protected void imagesLoaded() {
+ if (isVisible()) {
+ show();
+ }
+ }
+
/**
* Sets the element from which to build menu
*
Util.doIE6PngFix((Element) Element.as(event.getNativeEvent()
.getEventTarget()));
}
- if (isVisible()) {
- show();
- }
+ delayedImageLoadExecutioner.trigger();
}
}
--- /dev/null
+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