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