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

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

Introduction

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

Prototype

public final native String get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:com.google.gerrit.client.change.IncludedInBox.java

License:Apache License

private SafeHtml formatList(JsArrayString l) {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    int size = l.length();
    for (int i = 0; i < size; i++) {
        html.openSpan().addStyleName(style.includedInElement()).append(l.get(i)).closeSpan();
        if (i < size - 1) {
            html.append(", ");
        }/*  ww w .  j  a  va 2s. co m*/
    }
    return html;
}

From source file:com.google.gerrit.client.change.QuickApprove.java

License:Apache License

void set(ChangeInfo info, String commit, ReplyAction action) {
    if (!info.hasPermittedLabels() || !info.status().isOpen()) {
        // Quick approve needs at least one label on an open change.
        setVisible(false);//from w  w  w . j  a v  a2  s  . co  m
        return;
    }
    if (info.revision(commit).isEdit() || info.revision(commit).draft()) {
        setVisible(false);
        return;
    }

    String qName = null;
    String qValueStr = null;
    short qValue = 0;

    int index = info.getMissingLabelIndex();
    if (index != -1) {
        LabelInfo label = Natives.asList(info.allLabels().values()).get(index);
        JsArrayString values = info.permittedValues(label.name());
        String s = values.get(values.length() - 1);
        short v = LabelInfo.parseValue(s);
        if (v > 0 && s.equals(label.maxValue())) {
            qName = label.name();
            qValueStr = s;
            qValue = v;
        }
    }

    if (qName != null) {
        changeId = info.legacyId();
        revision = commit;
        input = ReviewInput.create();
        input.drafts(DraftHandling.PUBLISH_ALL_REVISIONS);
        input.label(qName, qValue);
        replyAction = action;
        setText(qName + qValueStr);
        setVisible(true);
    } else {
        setVisible(false);
    }
}

From source file:com.google.gerrit.client.change.ReplyBox.java

License:Apache License

private void renderLabels(List<String> names, NativeMap<LabelInfo> all, NativeMap<JsArrayString> permitted) {
    TreeSet<Short> values = new TreeSet<>();
    List<LabelAndValues> labels = new ArrayList<>(permitted.size());
    for (String id : names) {
        JsArrayString p = permitted.get(id);
        if (p != null) {
            if (!all.containsKey(id)) {
                continue;
            }//from   w ww .  ja  va2 s  . co  m
            Set<Short> a = new TreeSet<>();
            for (int i = 0; i < p.length(); i++) {
                a.add(LabelInfo.parseValue(p.get(i)));
            }
            labels.add(new LabelAndValues(all.get(id), a));
            values.addAll(a);
        }
    }
    List<Short> columns = new ArrayList<>(values);

    labelsTable.resize(1 + labels.size(), 2 + values.size());
    for (int c = 0; c < columns.size(); c++) {
        labelsTable.setText(0, 1 + c, LabelValue.formatValue(columns.get(c)));
        labelsTable.getCellFormatter().setStyleName(0, 1 + c, style.label_value());
    }

    List<LabelAndValues> checkboxes = new ArrayList<>(labels.size());
    int row = 1;
    for (LabelAndValues lv : labels) {
        if (isCheckBox(lv.info.valueSet())) {
            checkboxes.add(lv);
        } else {
            renderRadio(row++, columns, lv);
        }
    }
    for (LabelAndValues lv : checkboxes) {
        renderCheckBox(row++, lv);
    }
}

From source file:com.google.gerrit.client.changes.PublishCommentScreen.java

License:Apache License

private void initLabel(String labelName, Panel body) {
    if (!change.has_permitted_labels()) {
        return;/*from  w  w  w  . j a  v a2  s . com*/
    }
    JsArrayString nativeValues = change.permitted_values(labelName);
    if (nativeValues == null || nativeValues.length() == 0) {
        return;
    }
    List<String> values = new ArrayList<String>(nativeValues.length());
    for (int i = 0; i < nativeValues.length(); i++) {
        values.add(nativeValues.get(i));
    }
    Collections.reverse(values);
    LabelInfo label = change.label(labelName);

    body.add(new SmallHeading(label.name() + ":"));

    VerticalPanel vp = new VerticalPanel();
    vp.setStyleName(Gerrit.RESOURCES.css().labelList());

    Short prior = null;
    if (label.all() != null) {
        for (ApprovalInfo app : Natives.asList(label.all())) {
            if (app._account_id() == Gerrit.getUserAccount().getId().get()) {
                prior = app.value();
                break;
            }
        }
    }

    for (String value : values) {
        ValueRadioButton b = new ValueRadioButton(label, value);
        SafeHtml buf = new SafeHtmlBuilder().append(b.format());
        buf = commentLinkProcessor.apply(buf);
        SafeHtml.set(b, buf);

        if (lastState != null && patchSetId.equals(lastState.patchSetId)
                && lastState.approvals.containsKey(label.name())) {
            b.setValue(lastState.approvals.get(label.name()) == value);
        } else {
            b.setValue(b.parseValue() == (prior != null ? prior : 0));
        }

        approvalButtons.add(b);
        vp.add(b);
    }
    body.add(vp);
}

From source file:com.google.gerrit.client.diff.DiffInfo.java

License:Apache License

private static void append(StringBuilder s, JsArrayString lines) {
    for (int i = 0; i < lines.length(); i++) {
        s.append(lines.get(i)).append('\n');
    }//from   ww  w .ja  va  2s.c  o  m
}

From source file:com.google.gerrit.client.info.GerritInfo.java

License:Apache License

public final List<UiType> webUis() {
    JsArrayString webUis = _webUis();
    List<UiType> result = new ArrayList<>(webUis.length());
    for (int i = 0; i < webUis.length(); i++) {
        UiType t = UiType.parse(webUis.get(i));
        if (t != null) {
            result.add(t);//from   w  ww  . j a  va2 s.co m
        }
    }
    return result;
}

From source file:com.google.gwt.gdata.sample.hellogdata.client.BloggerCreateBlogPostCommentDemo.java

License:Apache License

/**
 * Retrieve the Blogger posts feed using the Blogger service and
 * the posts feed uri for a given blog./*from  www .j  a va2s  .co  m*/
 * On success, identify the first post entry that is available
 * for commenting, this will be the post entry that we'll
 * reply to.
 * If no posts are available for commenting, display a message.
 * Otherwise extract the blog and post ID and call insertComment
 * to add a comment.
 * If the regular expression parsing of the blog and post IDs
 * fails, display a message.
 * 
 * @param postsFeedUri The posts feed uri for a given blog
 */
private void getPosts(String postsFeedUri) {
    showStatus("Loading posts feed...", false);
    service.getBlogPostFeed(postsFeedUri, new BlogPostFeedCallback() {
        public void onFailure(CallErrorException caught) {
            showStatus("An error occurred while retrieving the Blogger Posts " + "feed: " + caught.getMessage(),
                    true);
        }

        public void onSuccess(BlogPostFeed result) {
            PostEntry targetPost = null;
            // get the first public post
            for (PostEntry post : result.getEntries()) {
                if (post.getRepliesLink() != null) {
                    targetPost = post;
                    break;
                }
            }
            if (targetPost == null) {
                showStatus("The target blog contains no public posts.", false);
            } else {
                String postEntryId = targetPost.getId().getValue();
                JsArrayString match = regExpMatch("blog-(\\d+)\\.post-(\\d+)", postEntryId);
                if (match.length() > 1) {
                    insertComment(match.get(1), match.get(2));
                } else {
                    showStatus("Error parsing the blog post id.", true);
                }
            }
        }
    });
}

From source file:com.google.gwt.gdata.sample.hellogdata.client.FinanceRetrievePositionsDemo.java

License:Apache License

/**
 * Retrieve the portfolios feed using the Finance service and
 * the portfolios feed uri. In GData all get, insert, update
 * and delete methods always receive a callback defining
 * success and failure handlers.//from   w  ww.j  av  a  2 s  .c om
 * Here, the failure handler displays an error message while the
 * success handler obtains the first portfolio entry and its
 * ID and calls getPositions to retrieve the corresponding
 * positions feed.
 * 
 * @param portfoliosFeedUri The uri of the portfolios feed
 */
private void getPortfolios(String portfoliosFeedUri) {
    showStatus("Loading portfolios feed...", false);
    service.getPortfolioFeed(portfoliosFeedUri, new PortfolioFeedCallback() {
        public void onFailure(CallErrorException caught) {
            showStatus("An error occurred while retrieving the portfolios feed: " + caught.getMessage(), true);
        }

        public void onSuccess(PortfolioFeed result) {
            PortfolioEntry[] entries = result.getEntries();
            if (entries.length == 0) {
                showStatus("You have no portfolios.", false);
            } else {
                PortfolioEntry targetPortfolio = entries[0];
                String portfolioId = targetPortfolio.getId().getValue();
                JsArrayString match = regExpMatch("\\/(\\d+)$", portfolioId);
                if (match.length() > 1) {
                    portfolioId = match.get(1);
                } else {
                    showStatus("Error parsing the portfolio id.", true);
                }
                getPositions(portfolioId);
            }
        }
    });
}

From source file:com.google.mobile.trippy.web.client.db.JsoTrip.java

License:Apache License

public final HashSet<String> getContributorIds() {
    JsArrayString sArr = getContributorIds_();
    HashSet<String> arr = new HashSet<String>();
    for (int i = 0; i < sArr.length(); ++i) {
        arr.add(sArr.get(i));
    }//ww w  . j a va 2s.c om
    return arr;
}

From source file:com.google.mobile.trippy.web.client.db.JsoTrip.java

License:Apache License

public final HashSet<String> getViewerIds() {
    JsArrayString sArr = getViewerIds_();
    HashSet<String> arr = new HashSet<String>();
    for (int i = 0; i < sArr.length(); ++i) {
        arr.add(sArr.get(i));
    }//from  ww w  . jav a 2 s.c om
    return arr;
}