Example usage for com.google.gwt.core.client JavaScriptObject cast

List of usage examples for com.google.gwt.core.client JavaScriptObject cast

Introduction

In this page you can find the example usage for com.google.gwt.core.client JavaScriptObject cast.

Prototype

@Override
@SuppressWarnings("unchecked")
public <T extends JavascriptObjectEquivalent> T cast() 

Source Link

Document

A helper method to enable cross-casting from any JavaScriptObject type to any other JavaScriptObject type.

Usage

From source file:com.google.api.explorer.client.base.ApiResponse.java

License:Apache License

/** Instantiates a response from the JS object representation of a response. */
public static ApiResponse fromData(JavaScriptObject data) {
    DynamicJso jso = data.cast();

    return new ApiResponse(jso);
}

From source file:com.google.gerrit.client.api.ActionContext.java

License:Apache License

private static GerritCallback<JavaScriptObject> wrap(final JavaScriptObject cb) {
    return new GerritCallback<JavaScriptObject>() {
        @Override// w  w w. j  av a  2s .  co m
        public void onSuccess(JavaScriptObject result) {
            if (NativeString.is(result)) {
                NativeString s = result.cast();
                ApiGlue.invoke(cb, s.asString());
            } else {
                ApiGlue.invoke(cb, result);
            }
        }
    };
}

From source file:com.google.gerrit.client.api.DefaultActions.java

License:Apache License

private static AsyncCallback<JavaScriptObject> callback(final String target) {
    return new GerritCallback<JavaScriptObject>() {
        @Override/*  w ww .  j  a  v a2  s .  c  o  m*/
        public void onSuccess(JavaScriptObject in) {
            UiResult result = asUiResult(in);
            if (result.alert() != null) {
                Window.alert(result.alert());
            }

            if (result.redirectUrl() != null && result.openWindow()) {
                Window.open(result.redirectUrl(), "_blank", null);
            } else if (result.redirectUrl() != null) {
                Location.assign(result.redirectUrl());
            } else {
                Gerrit.display(target);
            }
        }

        private UiResult asUiResult(JavaScriptObject in) {
            if (NativeString.is(in)) {
                String str = ((NativeString) in).asString();
                return str.isEmpty() ? UiResult.none() : UiResult.alert(str);
            }
            return in.cast();
        }
    };
}

From source file:com.google.speedtracer.client.BackgroundPage.java

License:Apache License

private void listenForExternalExtensions(final ExternalExtensionListener exListener) {
    // External extensions can also be used as data sources. Hook this up.
    Chrome.getExtension().getOnRequestExternalEvent().addListener(new RequestExternalEvent.Listener() {
        public void onRequestExternal(JavaScriptObject request, Sender sender, SendResponse sendResponse) {
            // Ensure the extension attempting to connect is not blacklisted.
            if (!ExternalExtensionDataInstance.isBlackListed(sender.getId())) {
                final ConnectRequest connectRequest = request.cast();
                final int browserId = connectRequest.getBrowserId();

                BrowserConnectionState connection = browserConnectionMap.get(browserId);

                if (connection == null) {
                    // If this is the first opened connection for this browser type,
                    // then we provision an entry for it in the browser map.
                    exListener.onBrowserConnected(browserId);
                }/* w  ww  .  j  av a2  s . co m*/

                final int tabId = connectRequest.getTabId();
                final String portName = ExternalExtensionDataInstance.SPEED_TRACER_EXTERNAL_PORT + browserId
                        + "-" + tabId;

                // So we will now begin listening for connections on a dedicated
                // port name for this browser/tab combo.
                Chrome.getExtension().getOnConnectExternalEvent()
                        .addListener(new ConnectExternalEvent.Listener() {
                            public void onConnectExternal(Port port) {
                                if (portName.equals(port.getName())) {
                                    // Provision a DataInstance and a TabDescription.
                                    DataInstance dataInstance = ExternalExtensionDataInstance.create(port);
                                    TabDescription tabDescription = TabDescription.create(tabId,
                                            connectRequest.getTitle(), connectRequest.getUrl());

                                    // Now remember the DataInstance and TabDescription, and
                                    // open a Monitor.
                                    exListener.onTabMonitorStarted(browserId, tabDescription, dataInstance);
                                }
                            }
                        });

                // Send a response that tells the external extension what port
                // name to connect to.
                sendResponse.invoke(ExternalExtensionDataInstance.createResponse(portName));
            }
        }
    });
}

From source file:com.google.speedtracer.hintletengine.client.HintletEventRecordProcessor.java

License:Apache License

/**
 * Receive a new record of browser data and forward it to registered hintlets
 * //from   ww  w. jav a  2s.c  om
 * @param dataRecord record to send to all hintlets
 */
public void onEventRecord(JavaScriptObject dataRecord) {

    if (!DataBag.hasOwnProperty(dataRecord, "type")) {
        throw new IllegalArgumentException("Expecting an EventRecord. Getting " + JSON.stringify(dataRecord));
    }
    // TODO(haibinlu): make sure the type is valid
    EventRecord eventRecord = dataRecord.cast();
    // Calculate the time spent in each event/sub-event exclusive of children
    computeSelfTime(eventRecord);

    // Keep state for a network resource. NetworkEventDispatcher
    // will determine which events to save data from.
    HintletNetworkResources.getInstance().onEventRecord(eventRecord);
    for (HintletRule rule : rules) {
        rule.onEventRecord(eventRecord);
    }
}

From source file:com.gwittit.client.facebook.FacebookApi.java

License:Apache License

private void friendsGetGeneric(String method, JavaScriptObject params,
        final AsyncCallback<List<Long>> callback) {

    AsyncCallback<JavaScriptObject> ac = new AsyncCallback<JavaScriptObject>() {
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);//from w  w w.j  av a2  s . c om
        }

        public void onSuccess(JavaScriptObject jso) {
            if ("{}".equals(new JSONObject(jso).toString())) {
                callback.onSuccess(Collections.EMPTY_LIST);
            } else {
                JsArrayNumber jsArray = jso.cast();
                callback.onSuccess(Util.convertNumberArray(jsArray));
            }
        }
    };
    callMethod(method, params, ac);
}

From source file:com.gwittit.client.facebook.FacebookApi.java

License:Apache License

private <T extends JavaScriptObject> void callMethodRetObject(final String method,
        final JavaScriptObject params, final Class<T> entity, final AsyncCallback<T> callback) {

    callMethod(method, params, new Callback<JavaScriptObject>(callback) {
        public void onSuccess(JavaScriptObject jso) {
            T entity = (T) jso.cast();
            callback.onSuccess(entity);//  www  . j a va  2  s . c o m
        }
    });
}

From source file:com.gwittit.client.facebook.FacebookApi.java

License:Apache License

private <T extends JavaScriptObject> List<T> cast(Class<T> entity, JavaScriptObject jso) {
    if (jso == null) {
        return new ArrayList<T>();
    }//w w w .  ja  v a  2 s . c om
    List<T> result = new ArrayList<T>();

    JsArray<T> array = jso.cast();

    for (int i = 0; i < array.length(); i++) {
        result.add(array.get(i));
    }
    return result;
}

From source file:com.gwittit.client.facebook.FacebookApi.java

License:Apache License

protected void callbackError(AsyncCallback<JSONValue> callback, JavaScriptObject jso) {
    ErrorResponse er = jso.cast();
    callback.onFailure(new FacebookException(er));
}

From source file:com.gwtmodel.table.view.ewidget.polymer.IronSelectorPolymerCombo.java

License:Apache License

private String getV(JavaScriptObject o, Object oo) {
    String a = iSel.getAttrForSelected();
    String ss;/*from  w ww.ja v  a  2 s  .c om*/
    if (oo == null)
        ss = o.toString();
    else
        ss = oo.toString();
    if (!CUtil.EmptyS(a))
        return ss;
    // index
    if (!CUtil.OkInteger(ss))
        return ss;
    int i = CUtil.getNumb(ss);
    JsArray li = iSel.getItems();
    JavaScriptObject obj = li.get(i);
    Element ele = obj.cast();
    String in = ele.getInnerText();
    String sss = obj.getClass().getName();
    return in;
}