01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08: package com.gwtext.client.util;
09:
10: import com.google.gwt.core.client.JavaScriptObject;
11: import com.gwtext.client.core.Function;
12: import com.gwtext.client.core.JsObject;
13:
14: /**
15: * Provides a convenient method of performing setTimeout where a new timeout cancels the old timeout.
16: * An example would be performing validation on a keypress. You can use this class to buffer the keypress events for a
17: * certain number of milliseconds, and perform only if they stop for that amount of time.
18: */
19: public class DelayedTask extends JsObject {
20:
21: /**
22: * Creates a new DelayedTask.
23: */
24: public DelayedTask() {
25: jsObj = create();
26: }
27:
28: private native JavaScriptObject create() /*-{
29: return new $wnd.Ext.util.DelayedTask();
30: }-*/;
31:
32: /**
33: * Cancel the last queued timeout.
34: */
35: public native void cancel() /*-{
36: var dtask = this.@com.gwtext.client.core.JsObject::getJsObj()();
37: dtask.cancel();
38: }-*/;
39:
40: /**
41: * Cancels any pending timeout and queues a new one.
42: *
43: * @param delay the milliseconds to delay
44: * @param task the task
45: */
46: public native void delay(int delay, Function task) /*-{
47: var dtask = this.@com.gwtext.client.core.JsObject::getJsObj()();
48: dtask.delay(delay, function() {
49: task.@com.gwtext.client.core.Function::execute()();
50: });
51: }-*/;
52: }
|