forked from GitHub/gf-core
More GWT refactoring.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/Users/bringert/src/gwt-mac-1.5.3/gwt-user.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package se.chalmers.cs.gf.gwt.client;
|
||||
|
||||
public class Arg {
|
||||
public final String name;
|
||||
public final String value;
|
||||
public Arg (String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
public Arg (String name, int value) {
|
||||
this(name, Integer.toString(value));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,18 @@ import java.util.List;
|
||||
|
||||
public class JSONRequestBuilder {
|
||||
|
||||
public static class Arg {
|
||||
public final String name;
|
||||
public final String value;
|
||||
public Arg (String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
public Arg (String name, int value) {
|
||||
this(name, Integer.toString(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends JavaScriptObject> JSONRequest sendRequest (String base, List<Arg> vars, final JSONCallback<T> callback) {
|
||||
String url = base + "?" + buildQueryString(vars);
|
||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
|
||||
@@ -27,7 +39,7 @@ public class JSONRequestBuilder {
|
||||
|
||||
public void onResponseReceived(Request request, Response response) {
|
||||
if (200 == response.getStatusCode()) {
|
||||
callback.onResult((T)eval(response.getText()).cast());
|
||||
callback.onResult(JSONRequestBuilder.<T>eval(response.getText()));
|
||||
} else {
|
||||
RequestException e = new RequestException("Response not OK: " + response.getStatusCode() + ". " + response.getText());
|
||||
callback.onError(e);
|
||||
@@ -41,7 +53,7 @@ public class JSONRequestBuilder {
|
||||
return new JSONRequest(request);
|
||||
}
|
||||
|
||||
private static native JavaScriptObject eval(String json) /*-{
|
||||
private static native <T extends JavaScriptObject> T eval(String json) /*-{
|
||||
return eval('(' + json + ')');
|
||||
}-*/;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package se.chalmers.cs.gf.gwt.client;
|
||||
|
||||
import static se.chalmers.cs.gf.gwt.client.JSONRequestBuilder.Arg;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user