com.extjs.gxt.ui.client.util.DelayedTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxt Show documentation
Show all versions of gxt Show documentation
Rich Internet Application Framework for GWT
/*
* Ext GWT - Ext for GWT
* Copyright(c) 2007, 2008, Ext JS, LLC.
* [email protected]
*
* http://extjs.com/license
*/
package com.extjs.gxt.ui.client.util;
import com.extjs.gxt.ui.client.event.Listener;
import com.google.gwt.user.client.Timer;
/**
* A Timer
that is cancelled if a new request is made.
*/
public class DelayedTask {
private Timer timer;
private Listener listener;
/**
* Creates a new delayed task.
*
* @param listener the listener to be called
*/
public DelayedTask(final Listener listener) {
this.listener = listener;
}
/**
* Cancels the task.
*/
public void cancel() {
if (timer != null) {
timer.cancel();
}
}
/**
* Cancels any running timers and starts a new one.
*
* @param delay the delay in ms
*/
public void delay(int delay) {
if (timer != null) {
timer.cancel();
timer.schedule(delay);
} else {
timer = new Timer() {
public void run() {
timer = null;
listener.handleEvent(null);
}
};
timer.schedule(delay);
}
}
}