Search in sources :

Example 6 with SafeHtmlBuilder

use of com.google.gwtexpui.safehtml.client.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class IncludedInBox method formatList.

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(", ");
        }
    }
    return html;
}
Also used : SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)

Example 7 with SafeHtmlBuilder

use of com.google.gwtexpui.safehtml.client.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class Labels method renderUsers.

private Widget renderUsers(LabelInfo label, Set<Integer> removable) {
    Map<Integer, List<ApprovalInfo>> m = new HashMap<>(4);
    int approved = 0;
    int rejected = 0;
    for (ApprovalInfo ai : Natives.asList(label.all())) {
        if (ai.value() != 0) {
            List<ApprovalInfo> l = m.get(Integer.valueOf(ai.value()));
            if (l == null) {
                l = new ArrayList<>(label.all().length());
                m.put(Integer.valueOf(ai.value()), l);
            }
            l.add(ai);
            if (isRejected(label, ai)) {
                rejected = ai.value();
            } else if (isApproved(label, ai)) {
                approved = ai.value();
            }
        }
    }
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    for (Integer v : sort(m.keySet(), approved, rejected)) {
        if (!html.isEmpty()) {
            html.br();
        }
        String val = LabelValue.formatValue(v.shortValue());
        html.openSpan();
        html.setAttribute("title", label.valueText(val));
        if (v.intValue() == approved) {
            html.setStyleName(style.label_ok());
        } else if (v.intValue() == rejected) {
            html.setStyleName(style.label_reject());
        }
        html.append(val).append(" ");
        html.append(formatUserList(style, m.get(v), removable, label.name(), null));
        html.closeSpan();
    }
    return html.toBlockWidget();
}
Also used : ApprovalInfo(com.google.gerrit.client.info.ChangeInfo.ApprovalInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)

Example 8 with SafeHtmlBuilder

use of com.google.gwtexpui.safehtml.client.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class Reviewers method addReviewer.

private void addReviewer(final String reviewer, boolean confirmed) {
    if (reviewer.isEmpty()) {
        return;
    }
    ChangeApi.reviewers(changeId.get()).post(PostInput.create(reviewer, confirmed), new GerritCallback<PostResult>() {

        @Override
        public void onSuccess(PostResult result) {
            if (result.confirm()) {
                askForConfirmation(result.error());
            } else if (result.error() != null) {
                UIObject.setVisible(error, true);
                error.setInnerText(result.error());
            } else {
                UIObject.setVisible(error, false);
                error.setInnerText("");
                suggestBox.setText("");
                if (result.reviewers() != null && result.reviewers().length() > 0) {
                    updateReviewerList();
                }
            }
        }

        private void askForConfirmation(String text) {
            new ConfirmationDialog(Util.C.approvalTableAddManyReviewersConfirmationDialogTitle(), new SafeHtmlBuilder().append(text), new ConfirmationCallback() {

                @Override
                public void onOk() {
                    addReviewer(reviewer, true);
                }
            }).center();
        }

        @Override
        public void onFailure(Throwable err) {
            if (isSigninFailure(err)) {
                new NotSignedInDialog().center();
            } else {
                UIObject.setVisible(error, true);
                error.setInnerText(err instanceof StatusCodeException ? ((StatusCodeException) err).getEncodedResponse() : err.getMessage());
            }
        }
    });
}
Also used : ConfirmationCallback(com.google.gerrit.client.ConfirmationCallback) NotSignedInDialog(com.google.gerrit.client.NotSignedInDialog) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) NativeString(com.google.gerrit.client.rpc.NativeString) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder) ConfirmationDialog(com.google.gerrit.client.ConfirmationDialog)

Example 9 with SafeHtmlBuilder

use of com.google.gwtexpui.safehtml.client.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class Hashtags method formatHashtags.

private SafeHtmlBuilder formatHashtags(JsArrayString hashtags) {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    Iterator<String> itr = Natives.asList(hashtags).iterator();
    while (itr.hasNext()) {
        String hashtagName = itr.next();
        html.openSpan().setAttribute(DATA_ID, hashtagName).setStyleName(style.hashtagName()).openAnchor().setAttribute("href", "#" + PageLinks.toChangeQuery("hashtag:\"" + hashtagName + "\"")).setAttribute("role", "listitem").openSpan().setStyleName(style.hashtagIcon()).append(new ImageResourceRenderer().render(Gerrit.RESOURCES.hashtag())).closeSpan().append(" ").append(hashtagName).closeAnchor();
        if (canEdit) {
            html.openElement("button").setAttribute("title", "Remove hashtag").setAttribute("onclick", REMOVE + "(event)").append("×").closeElement("button");
        }
        html.closeSpan();
        if (itr.hasNext()) {
            html.append(' ');
        }
    }
    return html;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder) ImageResourceRenderer(com.google.gwt.user.client.ui.ImageResourceRenderer)

Example 10 with SafeHtmlBuilder

use of com.google.gwtexpui.safehtml.client.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class CopyableLabel method embedMovie.

private void embedMovie() {
    if (copier == null && flashEnabled && !text.isEmpty() && UserAgent.Flash.isInstalled()) {
        final String flashVars = "text=" + URL.encodeQueryString(getText());
        final SafeHtmlBuilder h = new SafeHtmlBuilder();
        h.openElement("div");
        h.setStyleName(ClippyResources.I.css().swf());
        h.openElement("object");
        h.setWidth(SWF_WIDTH);
        h.setHeight(SWF_HEIGHT);
        h.setAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");
        h.paramElement("movie", swfUrl());
        h.paramElement("FlashVars", flashVars);
        h.openElement("embed");
        h.setWidth(SWF_WIDTH);
        h.setHeight(SWF_HEIGHT);
        h.setAttribute("wmode", "transparent");
        h.setAttribute("type", "application/x-shockwave-flash");
        h.setAttribute("src", swfUrl());
        h.setAttribute("FlashVars", flashVars);
        h.closeSelf();
        h.closeElement("object");
        h.closeElement("div");
        if (swf != null) {
            getElement().removeChild(swf);
        }
        DOM.appendChild(getElement(), swf = SafeHtml.parse(h));
    }
}
Also used : SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)

Aggregations

SafeHtmlBuilder (com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)16 ConfirmationCallback (com.google.gerrit.client.ConfirmationCallback)3 ConfirmationDialog (com.google.gerrit.client.ConfirmationDialog)3 RevisionInfo (com.google.gerrit.client.info.ChangeInfo.RevisionInfo)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NotSignedInDialog (com.google.gerrit.client.NotSignedInDialog)1 ActionButton (com.google.gerrit.client.actions.ActionButton)1 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 AvatarInfo (com.google.gerrit.client.info.AccountInfo.AvatarInfo)1 ActionInfo (com.google.gerrit.client.info.ActionInfo)1 ApprovalInfo (com.google.gerrit.client.info.ChangeInfo.ApprovalInfo)1 CommitInfo (com.google.gerrit.client.info.ChangeInfo.CommitInfo)1 NativeString (com.google.gerrit.client.rpc.NativeString)1 FancyFlexTableImpl (com.google.gerrit.client.ui.FancyFlexTableImpl)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Element (com.google.gwt.dom.client.Element)1 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)1 CellFormatter (com.google.gwt.user.client.ui.HTMLTable.CellFormatter)1 ImageResourceRenderer (com.google.gwt.user.client.ui.ImageResourceRenderer)1