From db2a8b84b8a4dddf5c888926f9b484d36a7292e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Mon, 18 Mar 2013 13:06:08 +0100 Subject: [PATCH] Add two methods present in the jquery Promise object --- .../main/java/com/google/gwt/query/client/Promise.java | 10 ++++++++++ .../com/google/gwt/query/client/plugins/ajax/Ajax.java | 4 ++-- .../gwt/query/client/plugins/deferred/Deferred.java | 8 ++++++++ ...sonpReqBuilder.java => PromiseReqBuilderJSONP.java} | 8 ++++---- 4 files changed, 24 insertions(+), 6 deletions(-) rename gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/{PromiseJsonpReqBuilder.java => PromiseReqBuilderJSONP.java} (89%) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java index 7d14b439..03c7327b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java @@ -95,4 +95,14 @@ public interface Promise { * 3rd one will be called when progress notifications are sent. */ Promise then(Function... f); + + /** + * Determine whether a Deferred object has been resolved. + */ + boolean isResolved(); + + /** + * Determine whether a Deferred object has been rejected. + */ + boolean isRejected(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index 8d2ed1dc..fefcb67f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -13,7 +13,7 @@ import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.Plugin; import com.google.gwt.query.client.plugins.deferred.Deferred; -import com.google.gwt.query.client.plugins.deferred.PromiseJsonpReqBuilder; +import com.google.gwt.query.client.plugins.deferred.PromiseReqBuilderJSONP; import com.google.gwt.query.client.plugins.deferred.PromiseReqBuilder; import com.google.gwt.user.client.ui.FormPanel; @@ -316,7 +316,7 @@ public class Ajax extends GQuery { } public static Promise getJSONP(String url, Function success, Function error, int timeout) { - return new PromiseJsonpReqBuilder(url, null, timeout) + return new PromiseReqBuilderJSONP(url, null, timeout) .done(success) .fail(error); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java index b2ab8d14..5b26df5d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java @@ -77,6 +77,14 @@ public class Deferred extends GQuery implements Promise.Deferred { } return this; } + + public boolean isResolved() { + return Promise.RESOLVED.equals(state()); + } + + public boolean isRejected() { + return Promise.REJECTED.equals(state()); + } } /** diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseJsonpReqBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java similarity index 89% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseJsonpReqBuilder.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java index 80f00826..29a3d062 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseJsonpReqBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java @@ -22,19 +22,19 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * }); * */ -public class PromiseJsonpReqBuilder extends DeferredPromiseImpl { +public class PromiseReqBuilderJSONP extends DeferredPromiseImpl { private static final JsRegexp callbackRegex = new JsRegexp("^(.+[\\?&])([^=]+)=\\?(.*)$"); - public PromiseJsonpReqBuilder(String url) { + public PromiseReqBuilderJSONP(String url) { this(url, null, 0); } - public PromiseJsonpReqBuilder(String url, int timeout) { + public PromiseReqBuilderJSONP(String url, int timeout) { this(url, null, timeout); } - public PromiseJsonpReqBuilder(String url, String callbackParam, int timeout) { + public PromiseReqBuilderJSONP(String url, String callbackParam, int timeout) { JsonpRequestBuilder builder = new JsonpRequestBuilder(); if (timeout > 0) { builder.setTimeout(timeout); -- 2.39.5