<commit_before>package org.sagebionetworks.web.client.widget.user;

import org.sagebionetworks.repo.model.UserProfile;
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.IconsImageBundle;
import org.sagebionetworks.web.client.SageImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.place.Profile;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class UserBadgeViewImpl extends LayoutContainer implements UserBadgeView {
	
	private Presenter presenter;
	SynapseJSNIUtils synapseJSNIUtils;
	GlobalApplicationState globalApplicationState;
	SageImageBundle sageImageBundle;
	IconsImageBundle iconsImageBundle;
	HorizontalPanel container;
	
	@Inject
	public UserBadgeViewImpl(SynapseJSNIUtils synapseJSNIUtils,
			GlobalApplicationState globalApplicationState,
			SageImageBundle sageImageBundle, IconsImageBundle iconsImageBundle) {
		this.synapseJSNIUtils = synapseJSNIUtils;
		this.globalApplicationState = globalApplicationState;
		this.sageImageBundle = sageImageBundle;
		this.iconsImageBundle = iconsImageBundle;
		
		container = new HorizontalPanel();
		this.add(container);
	}
	
	@Override
	public void setProfile(final UserProfile profile, Integer maxNameLength) {
		container.clear();
		if(profile == null)  throw new IllegalArgumentException("Profile is required");
		
		if(profile != null) {
			String displayName = DisplayUtils.getDisplayName(profile);
			String name = maxNameLength == null ? displayName : DisplayUtils.stubStrPartialWord(displayName, maxNameLength); 
			
			Widget nameWidget;
			final Anchor userAnchor = new Anchor();
			if(profile.getOwnerId() != null) {				
				userAnchor.setText(name);
				userAnchor.addStyleName("usernameLink");
				userAnchor.addClickHandler(new ClickHandler() {
					@Override
					public void onClick(ClickEvent event) {
						globalApplicationState.getPlaceChanger().goTo(new Profile(profile.getOwnerId()));
					}
				});
				nameWidget = userAnchor;
			} else {
				HTML html = new HTML(name);
				html.addStyleName("usernamelink");
				nameWidget = html;
			}
			//also add the username in a popup (in case this is a small view of the display name)
			DisplayUtils.addToolTip(nameWidget, DisplayUtils.getUserName(profile.getUserName(), false));
			Image profilePicture; 
			if (profile.getPic() != null && profile.getPic().getPreviewId() != null && profile.getPic().getPreviewId().length() > 0) {
				profilePicture = new Image();
				profilePicture.setUrl(DisplayUtils.createUserProfileAttachmentUrl(synapseJSNIUtils.getBaseProfileAttachmentUrl(), profile.getOwnerId(), profile.getPic().getPreviewId(), null));
			} else {
				profilePicture = new Image(sageImageBundle.defaultProfilePicture20().getSafeUri());
				profilePicture.setPixelSize(16,16);<commit_msg>remove tooltip unless the userbadge is abbreviated<commit_after>package org.sagebionetworks.web.client.widget.user;

import org.sagebionetworks.repo.model.UserProfile;
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.IconsImageBundle;
import org.sagebionetworks.web.client.SageImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.place.Profile;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class UserBadgeViewImpl extends LayoutContainer implements UserBadgeView {
	
	private Presenter presenter;
	SynapseJSNIUtils synapseJSNIUtils;
	GlobalApplicationState globalApplicationState;
	SageImageBundle sageImageBundle;
	IconsImageBundle iconsImageBundle;
	HorizontalPanel container;
	
	@Inject
	public UserBadgeViewImpl(SynapseJSNIUtils synapseJSNIUtils,
			GlobalApplicationState globalApplicationState,
			SageImageBundle sageImageBundle, IconsImageBundle iconsImageBundle) {
		this.synapseJSNIUtils = synapseJSNIUtils;
		this.globalApplicationState = globalApplicationState;
		this.sageImageBundle = sageImageBundle;
		this.iconsImageBundle = iconsImageBundle;
		
		container = new HorizontalPanel();
		this.add(container);
	}
	
	@Override
	public void setProfile(final UserProfile profile, Integer maxNameLength) {
		container.clear();
		if(profile == null)  throw new IllegalArgumentException("Profile is required");
		
		if(profile != null) {
			String displayName = DisplayUtils.getDisplayName(profile);
			String name = maxNameLength == null ? displayName : DisplayUtils.stubStrPartialWord(displayName, maxNameLength); 
			
			Widget nameWidget;
			final Anchor userAnchor = new Anchor();
			if(profile.getOwnerId() != null) {				
				userAnchor.setText(name);
				userAnchor.addStyleName("usernameLink");
				userAnchor.addClickHandler(new ClickHandler() {
					@Override
					public void onClick(ClickEvent event) {
						globalApplicationState.getPlaceChanger().goTo(new Profile(profile.getOwnerId()));
					}
				});
				nameWidget = userAnchor;
			} else {
				HTML html = new HTML(name);
				html.addStyleName("usernamelink");
				nameWidget = html;
			}
			//also add the username in a popup (in the case when the name shown does not show the entire display name)
			if (displayName.length() != name.length())
				DisplayUtils.addToolTip(nameWidget, displayName);
			Image profilePicture; 
			if (profile.getPic() != null && profile.getPic().getPreviewId() != null && profile.getPic().getPreviewId().length() > 0) {
				profilePicture = new Image();
				profilePicture.setUrl(DisplayUtils.createUserProfileAttachmentUrl(synapseJSNIUtils.getBaseProfileAttachmentUrl(), profile.getOwnerId(), profile.getPic().getPreviewId(), null));
			} else {
				profilePicture = new Image(sageImageBundle.defaultProfilePicture20().getSafeUri());
				profilePicture.setPixelSize(16,16);
{'fraction_non_alphanumeric': 0.10134328358208955, 'fraction_numerical': 0.00208955223880597, 'mean_word_length': 5.486931268151016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7593033', 'n_tokens_mistral': 2241, 'n_tokens_neox': 1982, 'n_words': 366}