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:net.cbtltd.client.widget.image.ImageWidget.java

private void getJsonpImages() {
    if (productField.noValue()) {
        return;//  w w w. java  2s .  com
    }

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.IMAGE + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productField.getValue();

    loader.setVisible(true);
    jsonp.requestObject(url, new AsyncCallback<ImageWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.product_json.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(ImageWidgetItems response) {
            loader.setVisible(false);
            if (response == null || response.getItems() == null && response.getItems().length() == 0) {
                AbstractField.addMessage(Level.ERROR, CONSTANTS.productError(), imageField);
            } else {
                ArrayList<String> items = new ArrayList<String>();
                for (int index = 0; index < response.getItems().length(); index++) {
                    String name = response.getItems().get(index).getNotes();
                    items.add(response.getItems().get(index).getURL());
                }
                imageField.setValue(items);
            }
        }
    });
}

From source file:net.cbtltd.client.widget.image.ImageWidget.java

private void getJsonpProductNameIds(String productid) {

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.NAMEID + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productid;

    loader.setVisible(true);/*w w  w .  j  a  va  2  s  .  c  om*/
    jsonp.requestObject(url, new AsyncCallback<NameIdWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.product_list.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(NameIdWidgetItems response) {
            loader.setVisible(false);
            if (response != null && response.getItems() != null && response.getItems().length() > 0) {
                ArrayList<NameId> items = new ArrayList<NameId>();
                for (int index = 0; index < response.getItems().length(); index++) {
                    items.add(new NameId(response.getItems().get(index).getName(),
                            response.getItems().get(index).getId()));
                }
                productField.setItems(items);
            }
        }
    });
}

From source file:net.cbtltd.client.widget.map.MapWidget.java

private void getJsonpProduct() {
    if (productField.noValue()) {
        return;/*from  ww w  . j  a  v  a  2s . c  o m*/
    }

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.PRODUCT + "&pos=" + pos + "&id="
            + productField.getValue();

    loader.setVisible(true);
    jsonp.requestObject(url, new AsyncCallback<ProductWidgetItem>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.product_id.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(ProductWidgetItem response) {
            loader.setVisible(false);
            if (response == null) {
                AbstractField.addMessage(Level.ERROR, CONSTANTS.productError(), mapField);
            } else {
                mapField.setValue(LatLng.newInstance(response.getLatitude(), response.getLongitude()));
            }
        }
    });
}

From source file:net.cbtltd.client.widget.price.PriceWidget.java

private void getJsonpPrice() {
    if (productField.noValue() || currencyField.noValue()) {
        return;/* w w w.  j  a  v  a2  s . co  m*/
    }

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.PRICE + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productField.getValue() + "&date="
            + RazorWidget.DF.format(RazorWidget.getDate()) + "&currency=" + currencyField.getValue() + "&rows="
            + RazorWidget.getRows();

    loader.setVisible(true);
    jsonp.requestObject(url, new AsyncCallback<PriceWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.price_json.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(PriceWidgetItems response) {
            loader.setVisible(false);
            if (response == null || response.getItems() == null || response.getItems().length() == 0) {
                AbstractField.addMessage(Level.ERROR, CONSTANTS.priceError(), priceGrid);
            } else {
                ArrayList<Price> prices = new ArrayList<Price>();
                for (int row = 0; row < response.getItems().length(); row++) {
                    PriceWidgetItem value = response.getItems().get(row);
                    Log.debug("row " + row + " " + value.string());
                    Price price = new Price();
                    price.setDate(RazorWidget.DF.parse(value.getFromdate()));
                    price.setTodate(RazorWidget.DF.parse(value.getTodate()));
                    price.setValue(value.getPrice());
                    price.setMinimum(value.getMinimum());
                    prices.add(price);
                }
                priceGrid.setValue(prices);
            }
        }
    });
}

From source file:net.cbtltd.client.widget.price.PriceWidget.java

private void getJsonpProductNameIds(String productid) {

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.NAMEID + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productid;

    loader.setVisible(true);//www.  j a  v  a  2 s .co  m
    jsonp.requestObject(url, new AsyncCallback<NameIdWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.nameid_json.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(NameIdWidgetItems response) {
            loader.setVisible(false);
            if (response != null && response.getItems() != null && response.getItems().length() > 0) {
                ArrayList<NameId> items = new ArrayList<NameId>();
                for (int index = 0; index < response.getItems().length(); index++) {
                    items.add(new NameId(response.getItems().get(index).getName(),
                            response.getItems().get(index).getId()));
                }
                productField.setItems(items);
                getJsonpPrice();
            }
        }
    });
}

From source file:net.cbtltd.client.widget.quote.QuoteWidget.java

private void getJsonpQuote() {
    if (productField.noValue() || fromtodateField.noValue() || fromtodateField.noTovalue()
            || fromtodateField.isEndBeforeStart() || currencyField.noValue()) {
        return;//w ww  .j  a v  a 2s. c o  m
    }

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.QUOTE + "&pos=" + pos + "&productid="
            + productField.getValue() + "&fromdate=" + RazorWidget.DF.format(fromtodateField.getValue())
            + "&todate=" + RazorWidget.DF.format(fromtodateField.getTovalue()) + "&currency="
            + currencyField.getValue();

    loader.setVisible(true);
    jsonp.requestObject(url, new AsyncCallback<QuoteWidgetItem>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.widget_quote.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(QuoteWidgetItem response) {
            loader.setVisible(false);
            //availableField.setVisible(response != null);
            if (response == null) {
                AbstractField.addMessage(Level.ERROR, CONSTANTS.priceError(), fromtodateField);
            } else {
                setFields(response.getPrice(), response.getQuote(), response.getCurrency(),
                        response.getDeposit(), response.getAvailable());
            }
        }
    });
}

From source file:net.cbtltd.client.widget.review.ReviewWidget.java

private void getJsonpReview() {
    if (productField.noValue()) {
        return;//from   w  w w .j av  a2 s .c  om
    }

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.REVIEW + "&pos=" + pos + "&productid="
            + productField.getValue() + "&rows=" + RazorWidget.getRows();

    loader.setVisible(true);
    jsonp.requestObject(url, new AsyncCallback<ReviewWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.widget_review.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(ReviewWidgetItems response) {
            loader.setVisible(false);
            if (response == null || response.getItems() == null || response.getItems().length() == 0) {
                AbstractField.addMessage(Level.ERROR, CONSTANTS.reviewError(), productField);
            } else {
                final ArrayList<RateNote> notes = new ArrayList<RateNote>();
                for (int row = 0; row < response.getItems().length(); row++) {
                    ReviewWidgetItem value = response.getItems().get(row);
                    Log.debug("row " + row + " " + value.string());
                    final RateNote note = new RateNote();
                    note.setDate(RazorWidget.DF.parse(value.getDate().trim()));
                    note.setRating(value.getRating());
                    note.setNotes(value.getNotes());
                    notes.add(note);
                }
                renderNotes(notes);
            }
        }
    });
}

From source file:net.cbtltd.client.widget.review.ReviewWidget.java

private void getJsonpProductNameids(String productid) {

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.NAMEID + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productid;

    loader.setVisible(true);//w ww.j  av  a  2  s .  c om
    jsonp.requestObject(url, new AsyncCallback<NameIdWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.nameid_json.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(NameIdWidgetItems response) {
            loader.setVisible(false);
            if (response != null && response.getItems() != null && response.getItems().length() > 0) {
                ArrayList<NameId> items = new ArrayList<NameId>();
                for (int index = 0; index < response.getItems().length(); index++) {
                    items.add(new NameId(response.getItems().get(index).getName(),
                            response.getItems().get(index).getId()));
                }
                productField.setItems(items);
                getJsonpReview();
            }
        }
    });
}

From source file:net.cbtltd.client.widget.route.RouteWidget.java

private void getJsonpProduct() {

    if (productField.noValue() || fromtextField.noValue()) {
        return;//w  w  w.  jav a2  s .c  o m
    }

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.PRODUCT + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productField.getValue();

    loader.setVisible(true);
    jsonp.requestObject(url, new AsyncCallback<ProductWidgetItem>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            AbstractField.addMessage(Level.ERROR, CONSTANTS.fromtextError(), fromtextField);
        }

        @Override
        public void onSuccess(ProductWidgetItem response) {
            loader.setVisible(false);
            if (response == null) {
                AbstractField.addMessage(Level.ERROR, CONSTANTS.productError(), productField);
            } else {
                routeField.setValue("From: " + fromtextField.getText() + " to "
                        + AbstractField.LF.format(response.getLatitude()) + ", "
                        + AbstractField.LF.format(response.getLongitude()));
            }
        }
    });
}

From source file:net.cbtltd.client.widget.route.RouteWidget.java

private void getJsonpProductNameIds(String productid) {

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    String url = HOSTS.jsonUrl() + "?service=" + JSONRequest.NAMEID + "&pos=" + pos + "&model="
            + NameId.Type.Product.name() + "&id=" + productid;

    loader.setVisible(true);/*  w  ww .j  a v a2 s  .  co m*/
    jsonp.requestObject(url, new AsyncCallback<NameIdWidgetItems>() {

        @Override
        public void onFailure(Throwable x) {
            loader.setVisible(false);
            throw new RuntimeException(Error.product_json.getMessage() + " " + x.getMessage());
        }

        @Override
        public void onSuccess(NameIdWidgetItems response) {
            loader.setVisible(false);
            if (response != null && response.getItems() != null && response.getItems().length() > 0) {
                ArrayList<NameId> items = new ArrayList<NameId>();
                for (int index = 0; index < response.getItems().length(); index++) {
                    items.add(new NameId(response.getItems().get(index).getName(),
                            response.getItems().get(index).getId()));
                }
                productField.setItems(items);
            }
        }
    });
}