Search in sources :

Example 16 with SafeHtmlBuilder

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

the class Labels method formatUserList.

static SafeHtml formatUserList(ChangeScreen.Style style, Collection<? extends AccountInfo> in, Set<Integer> removable, String label, Map<Integer, VotableInfo> votable) {
    List<AccountInfo> users = new ArrayList<>(in);
    Collections.sort(users, new Comparator<AccountInfo>() {

        @Override
        public int compare(AccountInfo a, AccountInfo b) {
            String as = name(a);
            String bs = name(b);
            if (as.isEmpty()) {
                return 1;
            } else if (bs.isEmpty()) {
                return -1;
            }
            return as.compareTo(bs);
        }

        private String name(AccountInfo a) {
            if (a.name() != null) {
                return a.name();
            } else if (a.email() != null) {
                return a.email();
            }
            return "";
        }
    });
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    Iterator<? extends AccountInfo> itr = users.iterator();
    while (itr.hasNext()) {
        AccountInfo ai = itr.next();
        AvatarInfo img = ai.avatar(AvatarInfo.DEFAULT_SIZE);
        String name;
        if (ai.name() != null) {
            name = ai.name();
        } else if (ai.email() != null) {
            name = ai.email();
        } else {
            name = Integer.toString(ai._accountId());
        }
        String votableCategories = "";
        if (votable != null) {
            VotableInfo vi = votable.get(ai._accountId());
            if (vi != null) {
                Set<String> s = vi.votableLabels();
                if (!s.isEmpty()) {
                    StringBuilder sb = new StringBuilder(Util.C.votable());
                    sb.append(" ");
                    for (Iterator<String> it = vi.votableLabels().iterator(); it.hasNext(); ) {
                        sb.append(it.next());
                        if (it.hasNext()) {
                            sb.append(", ");
                        }
                    }
                    votableCategories = sb.toString();
                }
            }
        }
        html.openSpan().setAttribute("role", "listitem").setAttribute(DATA_ID, ai._accountId()).setAttribute("title", getTitle(ai, votableCategories)).setStyleName(style.label_user());
        if (label != null) {
            html.setAttribute(DATA_VOTE, label);
        }
        if (img != null) {
            html.openElement("img").setStyleName(style.avatar()).setAttribute("src", img.url());
            if (img.width() > 0) {
                html.setAttribute("width", img.width());
            }
            if (img.height() > 0) {
                html.setAttribute("height", img.height());
            }
            html.closeSelf();
        }
        html.append(name);
        if (removable.contains(ai._accountId())) {
            html.openElement("button");
            if (label != null) {
                html.setAttribute("title", Util.M.removeVote(label)).setAttribute("onclick", REMOVE_VOTE + "(event)");
            } else {
                html.setAttribute("title", Util.M.removeReviewer(name)).setAttribute("onclick", REMOVE_REVIEWER + "(event)");
            }
            html.append("×").closeElement("button");
        }
        html.closeSpan();
        if (itr.hasNext()) {
            html.append(' ');
        }
    }
    return html;
}
Also used : AvatarInfo(com.google.gerrit.client.info.AccountInfo.AvatarInfo) ArrayList(java.util.ArrayList) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder) AccountInfo(com.google.gerrit.client.info.AccountInfo)

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