Search in sources :

Example 1 with AvatarInfo

use of com.google.gerrit.client.info.AccountInfo.AvatarInfo in project gerrit by GerritCodeReview.

the class AvatarImage method setAccount.

public void setAccount(AccountInfo account, int size, boolean addPopup) {
    if (account == null) {
        setVisible(false);
    } else if (isGerritServer(account)) {
        setVisible(true);
        setResource(Gerrit.RESOURCES.gerritAvatar26());
    } else if (account.hasAvatarInfo()) {
        setVisible(false);
        AvatarInfo info = account.avatar(size);
        if (info != null) {
            setWidth(info.width() > 0 ? info.width() + "px" : "");
            setHeight(info.height() > 0 ? info.height() + "px" : "");
            setUrl(info.url());
            popup(account, addPopup);
        } else if (account.email() != null) {
            loadAvatar(account, size, addPopup);
        }
    } else if (account.email() != null) {
        loadAvatar(account, size, addPopup);
    } else {
        setVisible(false);
    }
}
Also used : AvatarInfo(com.google.gerrit.client.info.AccountInfo.AvatarInfo)

Example 2 with AvatarInfo

use of com.google.gerrit.client.info.AccountInfo.AvatarInfo 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

AvatarInfo (com.google.gerrit.client.info.AccountInfo.AvatarInfo)2 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 SafeHtmlBuilder (com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)1 ArrayList (java.util.ArrayList)1