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

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

Introduction

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

Prototype

public final native <T extends JavaScriptObject> T getObject(int index) ;

Source Link

Document

Gets the JavaScriptObject at a given index.

Usage

From source file:com.ait.toolkit.node.dev.debug.TearOff.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public JavaScriptReturningFunction<T> call(JavaScriptFunctionArguments args) {
    final int dispId = Integer.valueOf(args.get(1).toString());
    return new JavaScriptReturningFunctionWrapper<T>() {
        @Override/*from  ww  w.j  a va2 s.  c  o m*/
        public T call(JavaScriptFunctionArguments args) {
            Object[] newArgs = new Object[args.length() + 2];
            newArgs[0] = dispId;
            newArgs[1] = getNativeFunction();
            for (int i = 0; i < paramCount; i++) {
                newArgs[i + 2] = args.get(0);
            }
            JsArrayMixed array = getStatic().apply(newArgs).cast();
            if (array.getBoolean(0)) {
                JavaScriptUtils.throwJavaScriptObject(array.getObject(1));
                //won't get here
                throw new RuntimeException("Error");
            } else {
                return (T) array.getObject(1);
            }
        }
    }.getNativeFunction();
}

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();
                }/* w  w w  .  j av a2  s .c o  m*/
                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.CodeMirrorDocument.java

License:Open Source License

public CodeMirrorDocument(final CMDocumentOverlay documentOverlay, final CodeMirrorOverlay codeMirror,
        final HasCursorActivityHandlers hasCursorActivityHandlers) {
    this.documentOverlay = documentOverlay;
    this.hasCursorActivityHandlers = hasCursorActivityHandlers;

    codeMirror.on(this.documentOverlay, CHANGE, new EventHandlers.EventHandlerMixedParameters() {
        @Override//from w  w  w. j a v  a  2 s  .c o  m
        public void onEvent(final JsArrayMixed params) {

            // first parameter is editor instance, second is the change
            final CMChangeEventOverlay change = params.getObject(1);
            fireDocumentChangeEvent(change);
        }
    });
    codeMirror.on(this.documentOverlay, BEFORE_CHANGE, new EventHandlers.EventHandlerMixedParameters() {
        @Override
        public void onEvent(final JsArrayMixed params) {

            // first parameter is editor instance, second is the change
            final CMBeforeChangeEventOverlay change = params.getObject(1);
            // undo/redo changes are not modifiable
            if (change.hasUpdate()) {
                fireTextChangeEvent(change);
            }
        }
    });
}

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

License:Open Source License

@Override
public HandlerRegistration addGutterClickHandler(GutterClickHandler handler) {
    if (!gutterClickHandlerAdded) {
        gutterClickHandlerAdded = true;/*from  ww w.  j  a  va 2s  .co  m*/
        this.editorOverlay.on(GUTTER_CLICK, new EventHandlers.EventHandlerMixedParameters() {

            @Override
            public void onEvent(final JsArrayMixed params) {
                // param 0 is codemirror instance
                final int line = Double.valueOf(params.getNumber(1)).intValue();
                final String gutterId = params.getString(2);
                // param 3 is click event
                final JsMouseEvent event = params.getObject(3).cast();
                fireGutterClickEvent(line, gutterId, event);
            }
        });
    }
    return addHandler(handler, GutterClickEvent.TYPE);
}

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

License:Open Source License

@Override
public void addGutterItem(final int line, final String gutterId, final Element element,
        final LineNumberingChangeCallback lineCallback) {
    // condition reversed from the other methods here
    if (GUTTER_MAP.isProtectedLogical(gutterId)) {
        return;/*  www .  j  a v  a  2 s .  co  m*/
    }
    this.editorOverlay.setGutterMarker(line, GUTTER_MAP.logicalToCm(gutterId), element);
    this.codeMirror.on(editorOverlay, EventTypes.CHANGE, new EventHandlerMixedParameters() {
        @Override
        public void onEvent(final JsArrayMixed params) {
            // 0->editor, 1->event object
            final CMChangeEventOverlay event = params.getObject(1);
            final JsArrayString newText = event.getText();
            final CMPositionOverlay from = event.getFrom();
            final CMPositionOverlay to = event.getTo();

            // if the first character of the line is not included, the (potential) line
            // numbering change only starts at the following line.
            int changeStart = from.getLine() + 1;

            int removedCount = 0;
            if (from.getLine() != to.getLine()) {
                // no lines were removed
                // don't count first line yet
                removedCount = Math.abs(from.getLine() - to.getLine()) - 1;
                if (from.getCharacter() == 0) {
                    // start of first line is included, 'to' is on another line, so the line is deleted
                    removedCount = removedCount + 1;
                    changeStart = changeStart - 1;
                }
                // if 'to' is at the end of the line, the line is _not_ removed, just emptied
            }
            // else no lines were removed

            final int addedCount = newText.length() - 1;

            // only call back if there is a change in the lines
            if (removedCount > 0 || addedCount > 0) {
                LOG.fine("Line change from l." + changeStart + " removed " + removedCount + " added "
                        + addedCount);
                lineCallback.onLineNumberingChange(changeStart, removedCount, addedCount);
            }
        }

    });
}

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

License:Open Source License

private void setupShowAdditionalInfo(final CMHintResultsOverlay data,
        final AdditionalInfoCallback additionalInfoCallback) {

    if (additionalInfoCallback != null) {
        final CodeMirrorOverlay codeMirror = editorWidget.getCodeMirror();
        final Element bodyElement = Elements.getBody();
        codeMirror.on(data, EventTypes.COMPLETION_SELECT, new EventHandlers.EventHandlerMixedParameters() {
            @Override//from  www  .ja  v a2  s .co m
            public void onEvent(final JsArrayMixed param) {
                // param 0 -> completion object (string or object)
                final CMCompletionObjectOverlay completionObject = param.getObject(0);
                // param 1 -> DOM node in the menu
                final JsElement itemElement = param.getObject(1);
                final ClientRect itemRect = itemElement.getBoundingClientRect();
                Element popup = itemElement;
                while (popup.getParentElement() != null && !popup.getParentElement().equals(bodyElement)) {
                    popup = popup.getParentElement();
                }
                final ClientRect popupRect = popup.getBoundingClientRect();
                final float pixelX = Math.max(itemRect.getRight(), popupRect.getRight());
                final float pixelY = itemRect.getTop();
                final Element info = getAdditionalInfo(completionObject);

                // there can be only one
                // remove any other body child with the additional info marker
                removeStaleInfoPopups(ADDITIONAL_INFO_MARKER);

                // Don't show anything if there is no additional info
                if (info == null) {
                    return;
                }

                final Element infoDisplayElement = additionalInfoCallback.onAdditionalInfoNeeded(pixelX, pixelY,
                        info);
                // set the additional info marker on the popup element
                infoDisplayElement.getClassList().add(ADDITIONAL_INFO_MARKER);
            }
        });

        // close the additional info along with the completion popup
        codeMirror.on(data, EventTypes.COMPLETION_CLOSE, new EventHandlers.EventHandlerNoParameters() {
            @Override
            public void onEvent() {
                delayedRemoveStaleInfoPopups(ADDITIONAL_INFO_MARKER);
            }
        });
    }
}

From source file:org.eclipse.che.ide.ext.github.client.importer.page.GithubImporterPagePresenter.java

License:Open Source License

protected List<GitHubRepository> toRepoList(JsArrayMixed arg) {
    return dtoFactory.createListDtoFromJson(arg.getObject(2).toString(), GitHubRepository.class);
}

From source file:org.eclipse.che.ide.ext.github.client.importer.page.GithubImporterPagePresenter.java

License:Open Source License

protected List<GitHubUser> toOrgList(JsArrayMixed arg) {
    List<GitHubUser> organizations = dtoFactory.createListDtoFromJson(arg.getObject(1).toString(),
            GitHubUser.class);
    organizations.add(dtoFactory.createDtoFromJson(arg.getObject(0).toString(), GitHubUser.class));
    return organizations;
}

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  ava2 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.primordion.xholon.service.timeline.TimelineViewerChapJSON.java

License:Open Source License

@Override
public IMessage processReceivedSyncMessage(IMessage msg) {
    Object response = null;/*from w  ww  .  ja  v a  2 s  .  c  o  m*/
    Object data = msg.getData();

    switch (msg.getSignal()) {
    case SIG_INITIALIZE_REQ: {
        // the data is an array of three items
        String outFileName = null;
        String modelName = null;
        Object root = null;
        if (data instanceof JavaScriptObject) {
            JavaScriptObject jso = (JavaScriptObject) data;
            JsArrayMixed arr = jso.cast();
            outFileName = arr.getString(0);
            modelName = arr.getString(1);
            root = (Object) arr.getObject(2);
        } else if (data instanceof Object[]) {
            Object[] iobj = (Object[]) data;
            outFileName = (String) (iobj[0]);
            modelName = (String) (iobj[1]);
            root = (Object) (iobj[2]);
        } else {
            break;
        }
        initialize(outFileName, modelName, (IXholon) root);
        break;
    }
    case SIG_PARAMETERS_REQ:
        // there are no parameters yet
        break;
    case SIG_CAPTURE_REQ: {
        Object dateTimeObj = null;
        String content = null;
        if (data instanceof JavaScriptObject) {
            JavaScriptObject jso = (JavaScriptObject) data;
            JsArrayMixed arr = jso.cast();
            // dateTimeObj can be a String or Date; for now assume it's a String
            dateTimeObj = arr.getString(0);
            content = arr.getString(1);
        } else if (data instanceof Object[]) {
            Object[] cobj = (Object[]) data;
            dateTimeObj = cobj[0];
            content = (String) (cobj[1]);
        }
        capture(dateTimeObj, content);
        break;
    }
    case SIG_DRAW_REQ:
        drawTimeline();
        break;
    default:
        return super.processReceivedSyncMessage(msg);
    }
    return new Message(SIG_PROCESS_RSP, response, this, msg.getSender());
}