diff options
author | Artur Signell <artur.signell@itmill.com> | 2011-01-03 13:02:15 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2011-01-03 13:02:15 +0000 |
commit | 38e8d083a407dfcac1716723389daf955613202d (patch) | |
tree | bdc66e425b011f591bea6033c28ab3c82db14ef7 /src/com | |
parent | 21b204b3bfe325222f69f016a1f9258dff2db17c (diff) | |
download | vaadin-framework-38e8d083a407dfcac1716723389daf955613202d.tar.gz vaadin-framework-38e8d083a407dfcac1716723389daf955613202d.zip |
#4376 Tree/Table: Context menu shadow is wrong on first click if it has an icon
Improved to lazily resize after all (or most) icons have been loaded
svn changeset:16760/svn branch:6.5
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java | 18 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VLazyExecutor.java | 49 |
2 files changed, 64 insertions, 3 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java b/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java index 8345979e2c..a5de7f9d22 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VContextMenu.java @@ -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 index 0000000000..8fe8a96ca2 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VLazyExecutor.java @@ -0,0 +1,49 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.user.client.Timer;
+
+/**
+ * Executes the given command {@code delayMs} milliseconds after a call to
+ * {@link #trigger()}. Calling {@link #trigger()} again before the command has
+ * been executed causes the execution to be rescheduled to {@code delayMs} after
+ * the second call.
+ *
+ */
+public class VLazyExecutor {
+
+ private Timer timer;
+ private int delayMs;
+ private ScheduledCommand cmd;
+
+ /**
+ * @param delayMs
+ * Delay in milliseconds to wait before executing the command
+ * @param cmd
+ * The command to execute
+ */
+ public VLazyExecutor(int delayMs, ScheduledCommand cmd) {
+ this.delayMs = delayMs;
+ this.cmd = cmd;
+ }
+
+ /**
+ * Triggers execution of the command. Each call reschedules any existing
+ * execution to {@link #delayMs} milliseconds from that point in time.
+ */
+ public void trigger() {
+ if (timer == null) {
+ timer = new Timer() {
+ @Override
+ public void run() {
+ timer = null;
+ cmd.execute();
+ }
+ };
+ }
+ // Schedule automatically cancels any old schedule
+ timer.schedule(delayMs);
+
+ }
+
+}
|