KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > DeferredCommand


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client;
17
18 /**
19  * This class allows you to execute code after all currently pending event
20  * handlers have completed, using the {@link #addCommand(Command)} or
21  * {@link #addCommand(IncrementalCommand)} methods. This is useful when you need
22  * to execute code outside of the context of the current stack.
23  */

24 public class DeferredCommand {
25   private static final CommandExecutor commandExecutor = new CommandExecutor();
26
27   /**
28    * Enqueues a {@link Command} to be fired after all current events have been
29    * handled.
30    *
31    * @param cmd the command to be fired. If cmd is null, a "pause" will be
32    * inserted into the queue. Any events added after the pause will
33    * wait for an additional cycle through the system event loop before
34    * executing. Pauses are cumulative.
35    *
36    * @deprecated As of release 1.4, replaced by {@link #addCommand(Command)}
37    */

38   public static void add(Command cmd) {
39     commandExecutor.submit(cmd);
40   }
41
42   /**
43    * Enqueues a {@link Command} to be fired after all current events have been
44    * handled.
45    *
46    * Note that the {@link Command} should not perform any blocking operations.
47    *
48    * @param cmd the command to be fired
49    * @throws NullPointerException if cmd is <code>null</code>
50    */

51   public static void addCommand(Command cmd) {
52     if (cmd == null) {
53       throw new NullPointerException JavaDoc("cmd can not be null");
54     }
55
56     commandExecutor.submit(cmd);
57   }
58
59   /**
60    * Enqueues an {@link IncrementalCommand} to be fired after all current events
61    * have been handled.
62    *
63    * Note that the {@link IncrementalCommand} should not perform any blocking
64    * operations.
65    *
66    * @param cmd the command to be fired
67    * @throws NullPointerException if cmd is <code>null</code>
68    */

69   public static void addCommand(IncrementalCommand cmd) {
70     if (cmd == null) {
71       throw new NullPointerException JavaDoc("cmd can not be null");
72     }
73
74     commandExecutor.submit(cmd);
75   }
76
77   /**
78    * Adds a "pause" to the queue of {@link DeferredCommand}s. Any
79    * {@link DeferredCommand}s or pauses that are added after this pause will
80    * wait for an additional cycle through the system event loop before
81    * executing.
82    */

83   public static void addPause() {
84     commandExecutor.submit((Command) null);
85   }
86 }
87
Popular Tags