All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.extjs.gxt.ui.client.util.DelayedTask Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * 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);
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy