Example usage for com.google.gwt.core.client JsArrayInteger get

List of usage examples for com.google.gwt.core.client JsArrayInteger get

Introduction

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

Prototype

public final native int get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:org.opennms.features.topology.app.internal.gwt.client.handler.DragObject.java

License:Open Source License

public int getCurrentY() {
    JsArrayInteger position = D3.getMouse(m_containerElement);
    return (int) (position.get(1) / m_transform.getScale().get(1));
}

From source file:org.rstudio.core.client.dom.impl.DomUtilsIE10Impl.java

License:Open Source License

public Rectangle getCursorBounds(Document doc) {
    JsArrayInteger result = getSelectionBoundsInternal(doc);
    return new Rectangle(result.get(0), result.get(1), result.get(2), result.get(3));
}

From source file:org.rstudio.core.client.dom.impl.DomUtilsIE10Impl.java

License:Open Source License

public int[] getSelectionOffsets(Element container) {
    if (!isSelectionInElement(container))
        return null;

    JsArrayInteger results = getSelectionOffsetsJs(container);
    if (results == null)
        return null;
    else/*  w ww  . j a v a2  s . co m*/
        return new int[] { results.get(0), results.get(1) };
}

From source file:org.rstudio.core.client.dom.WindowEx.java

License:Open Source License

public final Point getScrollPosition() {
    JsArrayInteger pos = getScrollPositionInternal();
    return new Point(pos.get(0), pos.get(1));
}

From source file:org.rstudio.studio.client.common.spelling.SpellingService.java

License:Open Source License

public void checkSpelling(List<String> words, final ServerRequestCallback<SpellCheckerResult> callback) {
    // results to return
    final SpellCheckerResult spellCheckerResult = new SpellCheckerResult();

    // only send words to the server that aren't in the cache
    final ArrayList<String> wordsToCheck = new ArrayList<String>();
    for (int i = 0; i < words.size(); i++) {
        String word = words.get(i);
        Boolean isCorrect = previousResults_.get(word);
        if (isCorrect != null) {
            if (isCorrect)
                spellCheckerResult.getCorrect().add(word);
            else/*from  w  ww .  j a v  a  2s  .c  o m*/
                spellCheckerResult.getIncorrect().add(word);
        } else {
            wordsToCheck.add(word);
        }
    }

    // if there are no words to check then return
    if (wordsToCheck.size() == 0) {
        callback.onResponseReceived(spellCheckerResult);
        return;
    }

    // hit the server
    server_.checkSpelling(JsUtil.toJsArrayString(wordsToCheck), new ServerRequestCallback<JsArrayInteger>() {

        @Override
        public void onResponseReceived(JsArrayInteger result) {
            // get misspelled indexes
            ArrayList<Integer> misspelledIndexes = new ArrayList<Integer>();
            for (int i = 0; i < result.length(); i++)
                misspelledIndexes.add(result.get(i));

            // determine correct/incorrect status and populate result & cache
            for (int i = 0; i < wordsToCheck.size(); i++) {
                String word = wordsToCheck.get(i);
                if (misspelledIndexes.contains(i)) {
                    spellCheckerResult.getIncorrect().add(word);
                    previousResults_.put(word, false);
                } else {
                    spellCheckerResult.getCorrect().add(word);
                    previousResults_.put(word, true);
                }
            }

            // return result
            callback.onResponseReceived(spellCheckerResult);
        }

        @Override
        public void onError(ServerError error) {
            callback.onError(error);
        }
    });
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionCache.java

License:Open Source License

private Completions narrow(String line, String substring, Completions original) {
    // no need to narrow when line + substring are equivalent
    if (line.equals(substring))
        return original;

    // Construct the new completion token by taking the original
    // completion token, and adding the delta between the new line and
    // the original completion line used.
    String token = original.getToken() + line.substring(substring.length());

    // Extract the vector elements of the completion string
    JsArrayString completions = original.getCompletions();
    JsArrayString packages = original.getPackages();
    JsArrayBoolean quote = original.getQuote();
    JsArrayInteger type = original.getType();
    JsArrayString meta = original.getMeta();

    // Now, generate narrowed versions of the above
    final JsVectorString completionsNarrow = JsVectorString.createVector().cast();
    final JsVectorString packagesNarrow = JsVectorString.createVector().cast();
    final JsVectorBoolean quoteNarrow = JsVectorBoolean.createVector().cast();
    final JsVectorInteger typeNarrow = JsVectorInteger.createVector().cast();
    final JsVectorString metaNarrow = JsVectorString.createVector().cast();

    for (int i = 0, n = completions.length(); i < n; i++) {
        boolean isSubsequence = StringUtil.isSubsequence(completions.get(i), token, true);
        if (isSubsequence) {
            completionsNarrow.push(completions.get(i));
            packagesNarrow.push(packages.get(i));
            quoteNarrow.push(quote.get(i));
            typeNarrow.push(type.get(i));
            metaNarrow.push(meta.get(i));
        }/*from w w  w  .j  a v  a 2s.  co  m*/
    }

    // Finally, sort these based on score
    List<Integer> indices = new ArrayList<Integer>();
    for (int i = 0, n = completionsNarrow.size(); i < n; i++)
        indices.add(i);

    // Sort our indices vector
    Collections.sort(indices, new Comparator<Integer>() {
        @Override
        public int compare(Integer lhs, Integer rhs) {
            int lhsType = typeNarrow.get(lhs);
            int rhsType = typeNarrow.get(rhs);

            String lhsName = completionsNarrow.get(lhs);
            String rhsName = completionsNarrow.get(rhs);

            int lhsScore = CodeSearchOracle.scoreMatch(lhsName, token, false);
            int rhsScore = CodeSearchOracle.scoreMatch(rhsName, token, false);

            if (lhsType == RCompletionType.ARGUMENT)
                lhsType -= 3;
            if (rhsType == RCompletionType.ARGUMENT)
                rhsType -= 3;

            if (lhsScore == rhsScore)
                return lhsName.compareTo(rhsName);

            return lhsScore < rhsScore ? -1 : 1;
        }
    });

    // Finally, re-arrange our vectors.
    final JsVectorString completionsSorted = JsVectorString.createVector().cast();
    final JsVectorString packagesSorted = JsVectorString.createVector().cast();
    final JsVectorBoolean quoteSorted = JsVectorBoolean.createVector().cast();
    final JsVectorInteger typeSorted = JsVectorInteger.createVector().cast();
    final JsVectorString metaSorted = JsVectorString.createVector().cast();

    for (int i = 0, n = indices.size(); i < n; i++) {
        int index = indices.get(i);
        completionsSorted.push(completionsNarrow.get(index));
        packagesSorted.push(packagesNarrow.get(index));
        quoteSorted.push(quoteNarrow.get(index));
        typeSorted.push(typeNarrow.get(index));
        metaSorted.push(metaNarrow.get(index));
    }

    // And return the completion result
    return Completions.createCompletions(token, completionsSorted.cast(), packagesSorted.cast(),
            quoteSorted.cast(), typeSorted.cast(), metaSorted.cast(), original.getGuessedFunctionName(),
            original.getExcludeOtherCompletions(), original.getOverrideInsertParens(), original.isCacheable(),
            original.getHelpHandler(), original.getLanguage());
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.java

License:Open Source License

private void fillCompletionResult(Completions response, boolean implicit,
        ServerRequestCallback<CompletionResult> callback) {
    JsArrayString comp = response.getCompletions();
    JsArrayString pkgs = response.getPackages();
    JsArrayBoolean quote = response.getQuote();
    JsArrayInteger type = response.getType();
    ArrayList<QualifiedName> newComp = new ArrayList<QualifiedName>();
    for (int i = 0; i < comp.length(); i++) {
        newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i)));
    }/*  w  ww  .  j av a2s . c om*/

    CompletionResult result = new CompletionResult(response.getToken(), newComp,
            response.getGuessedFunctionName(), response.getSuggestOnAccept(),
            response.getOverrideInsertParens());

    if (response.isCacheable()) {
        cachedCompletions_.put("", result);
    }

    if (!implicit || result.completions.size() != 0)
        callback.onResponseReceived(result);

}

From source file:org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.java

License:Open Source License

public void getCompletions(final String token, final List<String> assocData, final List<Integer> dataType,
        final List<Integer> numCommas, final String functionCallString, final String chainDataName,
        final JsArrayString chainAdditionalArgs, final JsArrayString chainExcludeArgs,
        final boolean chainExcludeArgsFromObject, final String filePath, final String documentId,
        final boolean implicit, final ServerRequestCallback<CompletionResult> callback) {
    boolean isHelp = dataType.size() > 0 && dataType.get(0) == AutocompletionContext.TYPE_HELP;

    if (usingCache(token, isHelp, callback))
        return;//w w w .j  a  v a2  s  . c om

    doGetCompletions(token, assocData, dataType, numCommas, functionCallString, chainDataName,
            chainAdditionalArgs, chainExcludeArgs, chainExcludeArgsFromObject, filePath, documentId,
            new ServerRequestCallback<Completions>() {
                @Override
                public void onError(ServerError error) {
                    callback.onError(error);
                }

                @Override
                public void onResponseReceived(Completions response) {
                    cachedLinePrefix_ = token;
                    String token = response.getToken();

                    JsArrayString comp = response.getCompletions();
                    JsArrayString pkgs = response.getPackages();
                    JsArrayBoolean quote = response.getQuote();
                    JsArrayInteger type = response.getType();
                    ArrayList<QualifiedName> newComp = new ArrayList<QualifiedName>();

                    // Get function completions from the server
                    for (int i = 0; i < comp.length(); i++)
                        if (comp.get(i).endsWith(" = "))
                            newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i)));

                    // Try getting our own function argument completions
                    if (!response.getExcludeOtherCompletions()) {
                        addFunctionArgumentCompletions(token, newComp);
                        addScopedArgumentCompletions(token, newComp);
                    }

                    // Get variable completions from the current scope
                    if (!response.getExcludeOtherCompletions()) {
                        addScopedCompletions(token, newComp, "variable");
                        addScopedCompletions(token, newComp, "function");
                    }

                    // Get other server completions
                    for (int i = 0; i < comp.length(); i++)
                        if (!comp.get(i).endsWith(" = "))
                            newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i)));

                    // Get snippet completions. Bail if this isn't a top-level
                    // completion -- TODO is to add some more context that allows us
                    // to properly ascertain this.
                    if (isTopLevelCompletionRequest())
                        addSnippetCompletions(token, newComp);

                    // Remove duplicates
                    newComp = resolveDuplicates(newComp);

                    CompletionResult result = new CompletionResult(response.getToken(), newComp,
                            response.getGuessedFunctionName(), response.getSuggestOnAccept(),
                            response.getOverrideInsertParens());

                    if (response.isCacheable()) {
                        cachedCompletions_.put("", result);
                    }

                    callback.onResponseReceived(result);
                }
            });
}

From source file:org.rstudio.studio.client.workbench.views.output.find.model.FindResult.java

License:Open Source License

private ArrayList<Integer> getJavaArray(String property) {
    JsArrayInteger array = getArray(property);
    ArrayList<Integer> ints = new ArrayList<Integer>();
    for (int i = 0; i < array.length(); i++)
        ints.add(array.get(i));
    return ints;/*from  w  w w .  ja  v a  2s  . c o m*/
}

From source file:org.sigmah.offline.dao.CategoryTypeAsyncDAO.java

License:Open Source License

private <M> void loadCategoryElements(final CategoryTypeJS categoryTypeJS,
        final CategoryTypeDTO categoryTypeDTO, final RequestManager<M> requestManager,
        final Transaction transaction) {
    if (categoryTypeJS.getCategoryElements() != null) {
        categoryTypeDTO.setCategoryElementsDTO(new ArrayList<CategoryElementDTO>());

        final JsArrayInteger categoryElements = categoryTypeJS.getCategoryElements();
        final int size = categoryElements.length();

        for (int index = 0; index < size; index++) {
            categoryElementAsyncDAO.get(categoryElements.get(index),
                    new RequestManagerCallback<M, CategoryElementDTO>(requestManager) {
                        @Override
                        public void onRequestSuccess(CategoryElementDTO result) {
                            result.setParentCategoryDTO(categoryTypeDTO);
                            categoryTypeDTO.getCategoryElementsDTO().add(result);
                        }//from w  ww.j  a va2s  .c o  m
                    }, transaction);
        }
    }
}