Example usage for com.google.gwt.jsonp.client JsonpRequestBuilder requestObject

List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder requestObject

Introduction

In this page you can find the example usage for com.google.gwt.jsonp.client JsonpRequestBuilder requestObject.

Prototype

public <T extends JavaScriptObject> JsonpRequest<T> requestObject(String url, AsyncCallback<T> callback) 

Source Link

Document

Sends a JSONP request and expects a JavaScript object as a result.

Usage

From source file:com.sencha.gxt.data.client.loader.ScriptTagProxy.java

License:sencha.com license

public void load(C loadConfig, final Callback<JavaScriptObject, Throwable> callback) {
    String prepend = url.indexOf("?") != -1 ? "&" : "?";
    String u = url + prepend + generateUrl(loadConfig);

    JsonpRequestBuilder b = new JsonpRequestBuilder();
    b.requestObject(u, new AsyncCallback<JavaScriptObject>() {
        @Override/*from  ww w  .j  a  v a 2  s . c  om*/
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(JavaScriptObject result) {
            callback.onSuccess(result);
        }
    });
}

From source file:com.sharad.quizbowl.ui.client.QuizbowlUI.java

License:Open Source License

public void onModuleLoad() {
    JsonpRequestBuilder dataGrabber = new JsonpRequestBuilder();
    dataGrabber.setTimeout(30000);/* ww w.j  a v  a2  s. c  o m*/
    dataGrabber.requestObject(SERVER_URL + "/data?alt=json-in-script", new AsyncCallback<DataPackage>() {

        @Override
        public void onFailure(Throwable caught) {
            Window.alert(caught.getMessage());

        }

        @Override
        public void onSuccess(DataPackage result) {
            YEARS = result.getYears();
            TOURNAMENTS = result.getTournaments();
            DIFFICULTIES = result.getDifficulties();
            CATEGORIES = result.getCategories();
            NUM_QUESTIONS = result.getNumQuestions();
            NUM_USERS = result.getNumUsers();
            NUM_SCORES = result.getNumScores();
            for (int i = 0; i < CATEGORIES.length(); i++) {
                CATEGORIES_LIST.add(CATEGORIES.get(i));
            }
            final HomeWidget home = new HomeWidget(YEARS, TOURNAMENTS, DIFFICULTIES, CATEGORIES);
            RootLayoutPanel.get().add(home);

            Timer timer = new Timer() {

                @Override
                public void run() {
                    home.search.searchBox.setFocus(true);

                }

            };
            timer.schedule(400);

        }
    });
}

From source file:com.vaadin.client.SuperDevMode.java

License:Apache License

private static void recompileWidgetsetAndStartInDevMode(final String serverUrl) {
    getLogger()/*from  w w  w .  j a v  a  2  s  . c o m*/
            .info("Recompiling widgetset using<br/>" + serverUrl + "<br/>and then reloading in super dev mode");
    VNotification n = new VNotification();
    n.show("<b>Recompiling widgetset, please wait</b>", VNotification.CENTERED, VNotification.STYLE_SYSTEM);

    JsonpRequestBuilder b = new JsonpRequestBuilder();
    b.setCallbackParam("_callback");
    b.setTimeout(COMPILE_TIMEOUT_IN_SECONDS * 1000);
    b.requestObject(
            serverUrl + "recompile/" + GWT.getModuleName() + "?" + getRecompileParameters(GWT.getModuleName()),
            new AsyncCallback<RecompileResult>() {

                @Override
                public void onSuccess(RecompileResult result) {
                    getLogger().fine("JSONP compile call successful");

                    if (!result.ok()) {
                        getLogger().fine("* result: " + result);
                        failed();
                        return;
                    }

                    setSession(getSuperDevModeHookKey(),
                            getSuperDevWidgetSetUrl(GWT.getModuleName(), serverUrl));
                    setSession(SKIP_RECOMPILE, "1");

                    getLogger().fine("* result: OK. Reloading");
                    Location.reload();
                }

                @Override
                public void onFailure(Throwable caught) {
                    getLogger().severe("JSONP compile call failed");
                    // Don't log exception as they are shown as
                    // notifications
                    getLogger().severe(caught.getClass().getSimpleName() + ": " + caught.getMessage());
                    failed();

                }

                private void failed() {
                    VNotification n = new VNotification();
                    n.addEventListener(new EventListener() {

                        @Override
                        public void notificationHidden(HideEvent event) {
                            recompileWidgetsetAndStartInDevMode(serverUrl);
                        }
                    });
                    n.show("Recompilation failed.<br/>" + "Make sure CodeServer is running, "
                            + "check its output and click to retry", VNotification.CENTERED,
                            VNotification.STYLE_SYSTEM);
                }
            });

}

From source file:edu.caltech.ipac.firefly.core.JsonUtils.java

public static <T extends JavaScriptObject> void jsonpRequest(String baseUrl, String cmd, List<Param> paramList,
        AsyncCallback<T> cb) {/*  w ww . ja  v a2 s.  c om*/
    String url = makeURL(baseUrl, cmd, paramList, true);
    JsonpRequestBuilder builder = new JsonpRequestBuilder();
    builder.setTimeout(TIMEOUT);
    builder.requestObject(url, cb);
}

From source file:fr.mncc.gwttoolbox.ajax.client.Jsonp.java

License:Open Source License

public static <T extends JavaScriptObject> void get(String url, AsyncCallback<T> callback) {
    com.google.gwt.jsonp.client.JsonpRequestBuilder jsonp = new com.google.gwt.jsonp.client.JsonpRequestBuilder();
    jsonp.requestObject(url, callback);
}

From source file:fr.mncc.gwttoolbox.rpc.client.requests.RestCall.java

License:Open Source License

/**
 * Send a request using the JSONP mechanism
 * /* w w  w  .ja va  2s . c om*/
 * @param url
 * @param callback on success, returns a GWT javascript object
 */
public static <T extends JavaScriptObject> void retry(final String url, final AsyncCallback<T> callback) {
    final JsonpRequestBuilder rb = new JsonpRequestBuilder();
    rb.requestObject(url, new AsyncCallback<T>() {
        @Override
        public void onFailure(final Throwable caught) {
            if (callback != null)
                callback.onFailure(caught);
        }

        @Override
        public void onSuccess(final T feed) {
            if (callback != null)
                callback.onSuccess(feed);
        }
    });
}

From source file:fr.mncc.minus.ajax.client.Ajax.java

License:Open Source License

public static <T extends JavaScriptObject> void getCrossDomain(String url, AsyncCallback<T> callback) {
    com.google.gwt.jsonp.client.JsonpRequestBuilder requestBuilder = new com.google.gwt.jsonp.client.JsonpRequestBuilder();
    requestBuilder.requestObject(url, callback);
}

From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.AnalyticsViewImpl.java

License:Open Source License

private void getStartDate() {

    String url = Consts.HOST_URL + "/summary/startTime";

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    // Set timeout for 30 seconds (30000 milliseconds)
    jsonp.setTimeout(30000);/*w ww.ja v a  2  s . c om*/
    jsonp.requestObject(url, new AsyncCallback<TweetTimes>() {

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("Failure: " + caught.getMessage());
        }

        @Override
        public void onSuccess(TweetTimes result) {
            // Fire SetDateEvent to change date picker to default date from server
            DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            Date startDate = dateTimeFormat.parse(result.getStartDate());
            Date endDate = dateTimeFormat.parse(result.getEndDate());

            presenter.getEventBus().fireEvent(new SetDateEvent(startDate, endDate));

        }
    });
}

From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.view.ranking.RankingView.java

License:Open Source License

public static void getRetweets(String account, Date start, Date end, final MaterialCollection list,
        final String listType) {

    list.clear();//from w  w  w  .  j  a  v  a 2 s.  c o m

    DateTimeFormat fmt = DateTimeFormat.getFormat("/yyyy/M/d");
    String startDate = fmt.format(start);
    String endDate = fmt.format(end);
    String screenName = account;

    String url = Consts.HOST_URL + "/summary/statuses/retweets/" + listType + "/" + screenName + startDate
            + endDate;

    loader.setVisible(true);

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    // Set timeout for 30 seconds (30000 milliseconds)
    jsonp.setTimeout(30000);
    jsonp.requestObject(url, new AsyncCallback<Mention>() {

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("Failure: " + caught.getMessage());
            loader.setVisible(false);
        }

        @Override
        public void onSuccess(Mention mention) {
            if (mention.getMentions() != null) {
                list.clear();
                updateRetweetList(mention.getMentions(), list, listType);
                loader.setVisible(false);
            }
        }
    });
}

From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.view.ranking.RankingView.java

License:Open Source License

public static void getLikes(String account, Date start, Date end, final MaterialCollection list,
        final String listType) {

    list.clear();//w ww .j  av  a  2  s. c om

    DateTimeFormat fmt = DateTimeFormat.getFormat("/yyyy/M/d");
    String startDate = fmt.format(start);
    String endDate = fmt.format(end);
    String screenName = account;

    String url = Consts.HOST_URL + "/summary/statuses/favorites/" + listType + "/" + screenName + startDate
            + endDate;

    loader.setVisible(true);

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    // Set timeout for 30 seconds (30000 milliseconds)
    jsonp.setTimeout(30000);
    jsonp.requestObject(url, new AsyncCallback<Mention>() {

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("Failure: " + caught.getMessage());
            loader.setVisible(false);
        }

        @Override
        public void onSuccess(Mention mention) {
            if (mention.getMentions() != null) {
                list.clear();
                updateLikesList(mention.getMentions(), list, listType);
                loader.setVisible(false);
            }
        }
    });
}