Example usage for com.google.gwt.core.client JsArrayMixed length

List of usage examples for com.google.gwt.core.client JsArrayMixed length

Introduction

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

Prototype

public final native int length() ;

Source Link

Document

Gets the length of the array.

Usage

From source file:com.arcbees.analytics.client.ClientAnalytics.java

License:Apache License

public void fallback(JsArrayMixed arguments) {
    if ("send".equals(arguments.getString(0))) {
        JSONObject jsonOptions = new JSONObject(arguments.getObject(arguments.length() - 1));
        StringBuilder url = new StringBuilder();
        url.append(fallbackPath).append("?");
        url.append(ProtocolTranslator.getFieldName("hitType")).append("=")
                .append(URL.encodeQueryString(arguments.getString(1)));

        for (String key : jsonOptions.keySet()) {
            if (!"hitCallback".equals(key)) {
                JSONValue jsonValue = jsonOptions.get(key);
                String strValue = "";
                if (jsonValue.isBoolean() != null) {
                    strValue = jsonValue.isBoolean().booleanValue() + "";
                } else if (jsonValue.isNumber() != null) {
                    strValue = jsonValue.isNumber().doubleValue() + "";
                } else if (jsonValue.isString() != null) {
                    strValue = jsonValue.isString().stringValue();
                }/*from www. ja va2s.  c om*/
                url.append("&").append(ProtocolTranslator.getFieldName(key)).append("=")
                        .append(URL.encodeQueryString(strValue));
            }
        }
        try {
            RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url.toString());
            requestBuilder.setCallback(new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    // TODO call hitcallback if needed.
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    // TODO Auto-generated method stub
                }
            });
            requestBuilder.send();
        } catch (RequestException e) {
        }
    }
}

From source file:org.eclipse.che.ide.editor.codemirror.client.ShowCompletion.java

License:Open Source License

public void showCompletionProposals() {
    if (!editorWidget.getEditorOverlay().hasShowHint()) {
        // no support for hints
        return;// w w  w  .j a v a  2 s . c om
    }
    final CMHintFunctionOverlay hintAuto = CMHintFunctionOverlay.createFromName(editorWidget.getCodeMirror(),
            "auto");
    final CMHintResultsOverlay result = hintAuto.apply(editorWidget.getEditorOverlay());
    if (result != null) {
        final List<String> proposals = new ArrayList<>();
        final JsArrayMixed list = result.getList();
        int nonStrings = 0;
        //jsarray aren't iterable
        for (int i = 0; i < list.length(); i++) {
            if (result.isString(i)) {
                proposals.add(result.getCompletionItemAsString(i));
            } else {
                nonStrings++;
            }
        }
        LOG.info("CM Completion returned " + list.length() + " items, of which " + nonStrings
                + " were not strings.");

        showCompletionProposals(proposals, result.getFrom(), result.getTo());
    }
}

From source file:org.eclipse.che.plugin.gdb.ide.configuration.GdbConfigurationPagePresenter.java

License:Open Source License

private void setHostsList(final Promise<RecipeDescriptor>[] recipePromises, final List<MachineDto> machines) {
    Promises.all(recipePromises).then(new Operation<JsArrayMixed>() {
        @Override// w ww .j  ava  2  s .  c  om
        public void apply(JsArrayMixed recipes) throws OperationException {
            Map<String, String> hosts = new HashMap<>();

            for (int i = 0; i < recipes.length(); i++) {
                String recipeJson = recipes.getObject(i).toString();
                RecipeDescriptor recipeDescriptor = dtoFactory.createDtoFromJson(recipeJson,
                        RecipeDescriptor.class);

                String script = recipeDescriptor.getScript();

                String host;
                try {
                    Map<String, String> m = JsonHelper.toMap(script);
                    host = m.containsKey("host") ? m.get("host") : "localhost";
                } catch (Exception e) {
                    host = "localhost";
                }
                String description = host + " (" + machines.get(i).getConfig().getName() + ")";
                hosts.put(host, description);
            }

            view.setHostsList(hosts);
        }
    });
}

From source file:org.gwtopenmaps.openlayers.client.layer.Layer.java

License:Apache License

/**
 * Gets the contents of the given {@link JsArrayMixed} as a double array.
 *
 * @param o {@link JsArrayMixed}/*from  ww  w . j  a v a  2  s  . co m*/
 * @return double[] if the array is not null, else null
 */
private static double[] getDoubleArray(JsArrayMixed o) {
    if (o != null) {
        double[] a = new double[o.length()];
        for (int i = 0; i < o.length(); i++) {
            a[i] = o.getNumber(i);
        }
        return a;
    } else {
        return null;
    }
}

From source file:org.primordion.xholon.base.Xholon.java

License:Open Source License

public void processReceivedMessage(IMessage msg) {
    if ((msg.getSignal() == ISignal.SIGNAL_XHOLON_CONSOLE_REQ) && (this.getActionList() != null)) {
        this.doAction((String) msg.getData());
    } else if (msg.getSignal() == ISignal.SIGNAL_BPLEX) {
        // ex (using Dev Tools): var bait = temp1; bait["FishingRodbplex"].msg(-12, ["FishingRodbplex"], bait);
        // ex: var bait = temp1; bait["FishingRodbplex"].msg(-12, {bplexName:"FishingRodbplex"}, bait);
        Object data = msg.getData();
        if (data == null) {
            return;
        }//from  w w  w  .  ja v  a2s.c om
        String clogStr = "bplex msg sender:" + msg.getSender() + " this:" + this.getName();
        String bplexName = null;
        if (data instanceof JavaScriptObject) {
            clogStr += " datatype:JavaScriptObject";
            JavaScriptObject jso = (JavaScriptObject) data;
            bplexName = (String) getJsoPropertyValue(jso, "bplexName");
            if (bplexName == null) {
                // this may be a JavaScript Array
                JsArrayMixed marr = jso.cast();
                if (marr.length() == 0) {
                    return;
                }
                bplexName = marr.getString(0);
                if (marr.length() > 1) {
                    // TODO the msg might contain a second nested message, or some other IXholon(s) or Object(s)
                    //anode = (Object)marr.getObject(1);
                }
                clogStr += " Array";
            } else {
                clogStr += " Object";
            }
        } else if (data instanceof Object[]) {
            clogStr += " datatype:Java Object[]";
            Object[] oarr = (Object[]) data;
            if (oarr.length == 0) {
                return;
            }
            bplexName = (String) oarr[0];
        } else {
            return;
        }
        consoleLog(clogStr);
        //this.setColor("indigo"); // this works
        if (msg.getSender() != this) {
            // send to next node in the bplex
            if (bplexName != null) {
                IXholon nextBplexNode = getPortNative(this, bplexName);
                if (nextBplexNode != null) {
                    // send the same message contents to the next node in the bplex
                    nextBplexNode.sendMessage(msg.getSignal(), data, msg.getSender());
                }
            }
        }
    } else {
        forwardMessage(msg);
    }
}

From source file:org.waveprotocol.wave.client.gadget.renderer.Controller.java

License:Apache License

/**
 * Generic callback relay that is called from the JS callback function.
 * Receives the RPC arguments to be processed in gwt.
 *
 * @param service the name of the RPC service called from the gadget.
 * @param gadgetId the name of the gadget that initiated the RPC call.
 * @param serviceCallback JS callback function to return service result or
 *        null if not needed./*from  w w w .jav a  2 s. c  om*/
 * @param arguments RPC call arguments.
 */
@SuppressWarnings("unused") // Used in registerService native method.
private void callback(String service, String gadgetId, JavaScriptFunction serviceCallback,
        JsArrayMixed arguments) {
    StringBuilder builder = null;
    if (TO_LOG) {
        builder = new StringBuilder();
        builder.append(service + " from " + gadgetId);
        if (arguments != null) {
            for (int index = 0; index < arguments.length(); ++index) {
                builder.append(" arg" + (index + 1) + ":'" + arguments.getString(index) + "'");
            }
        }
        log(builder.toString());
    }
    if (callbackMap.containsKey(gadgetId) && serviceMap.containsKey(service)) {
        serviceMap.get(service).callService(callbackMap.get(gadgetId), serviceCallback, arguments);
    }
}