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

import java.util.Map;
import java.util.TreeMap;

import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.Versionable;
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.IconsImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.model.EntityBundle;

import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

public class EntityViewUtils {

	public static Widget createTitleWidget(EntityBundle bundle, String entityTypeDisplay, IconsImageBundle iconsImageBundle, boolean canEdit, boolean readOnly, SynapseJSNIUtils synapseJSNIUtils) {
		LayoutContainer lc = new LayoutContainer();
		lc.setAutoWidth(true);
		lc.setAutoHeight(true);

		SafeHtmlBuilder shb = new SafeHtmlBuilder();
		shb.appendHtmlConstant("<h2>")
		.appendHtmlConstant(AbstractImagePrototype.create(DisplayUtils.getSynapseIconForEntity(bundle.getEntity(), DisplayUtils.IconSize.PX24, iconsImageBundle)).getHTML()) 
		.appendHtmlConstant("&nbsp;")
		.appendEscaped(bundle.getEntity().getName())
		.appendHtmlConstant("&nbsp;(")
		.appendEscaped(bundle.getEntity().getId())
		.appendHtmlConstant(")")		
		.appendHtmlConstant("</h2>");		
		lc.add(new HTML(shb.toSafeHtml()));  
		
	    // Metadata
	    lc.add(createMetadata(bundle.getEntity()));
	    // the headers for description and property
	   	  
		if(canEdit && readOnly) {
			HTML roContainer = new HTML("<h4 class=\"colored\"> " + DisplayConstants.READ_ONLY + " " +AbstractImagePrototype.create(iconsImageBundle.help16()).getHTML() + "</h4>");
			roContainer.setWidth("100px");			
			
			Map<String, String> optionsMap = new TreeMap<String, String>();
			optionsMap.put("title", DisplayConstants.WHY_VERSION_READ_ONLY_MODE);
			optionsMap.put("data-placement", "right");
			DisplayUtils.addTooltip(synapseJSNIUtils, roContainer, optionsMap);
			lc.add(roContainer);
		}

	    
	    lc.layout();
		return lc;
	}

	/*
	 * Private Methods
	 */

	/**
	 * Basic meata data about this entity
	 * @param entity
	 * @return
	 */
	private static Html createMetadata(Entity entity) {
		SafeHtmlBuilder builder = new SafeHtmlBuilder();
		builder.appendHtmlConstant("<div style=\"font-size: 80%\">");
		builder.appendHtmlConstant("Added by: ");
		builder.appendEscaped(entity.getCreatedBy());
		builder.appendHtmlConstant(" on: ");
		builder.appendEscaped(String.valueOf(entity.getCreatedOn()));
		builder.appendHtmlConstant("<br/>Last updated by: ");
		builder.appendEscaped(entity.getModifiedBy());
		builder.appendHtmlConstant(" on: ");
		builder.appendEscaped(String.valueOf(entity.getModifiedOn()));
		builder.appendHtmlConstant("<br/>");
		if(entity instanceof Versionable){
			Versionable vb = (Versionable) entity;
			builder.appendHtmlConstant("Version: ");
			builder.appendEscaped(vb.getVersionLabel());
			builder.appendHtmlConstant(" (");
			builder.append(vb.getVersionNumber());
			builder.appendHtmlConstant(")");
		}
		builder.appendHtmlConstant("</div>");		
		
	    return new Html(builder.toSafeHtml().asString());
	}	

	
}
<commit_msg>Refactor getMetadata to use widgets instead of SafeHtml<commit_after>package org.sagebionetworks.web.client.widget.entity;

import java.util.Map;
import java.util.TreeMap;

import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.Versionable;
import org.sagebionetworks.web.client.DisplayConstants;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.IconsImageBundle;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.model.EntityBundle;

import com.extjs.gxt.ui.client.widget.Html;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;

public class EntityViewUtils {

	public static Widget createTitleWidget(EntityBundle bundle, String entityTypeDisplay, IconsImageBundle iconsImageBundle, boolean canEdit, boolean readOnly, SynapseJSNIUtils synapseJSNIUtils) {
		LayoutContainer lc = new LayoutContainer();
		lc.setAutoWidth(true);
		lc.setAutoHeight(true);

		SafeHtmlBuilder shb = new SafeHtmlBuilder();
		shb.appendHtmlConstant("<h2>")
		.appendHtmlConstant(AbstractImagePrototype.create(DisplayUtils.getSynapseIconForEntity(bundle.getEntity(), DisplayUtils.IconSize.PX24, iconsImageBundle)).getHTML()) 
		.appendHtmlConstant("&nbsp;")
		.appendEscaped(bundle.getEntity().getName())
		.appendHtmlConstant("&nbsp;(")
		.appendEscaped(bundle.getEntity().getId())
		.appendHtmlConstant(")")		
		.appendHtmlConstant("</h2>");		
		lc.add(new HTML(shb.toSafeHtml()));  
		
	    // Metadata
	    lc.add(createMetadata(bundle.getEntity()));
	    // the headers for description and property
	   	  
		if(canEdit && readOnly) {
			HTML roContainer = new HTML("<h4 class=\"colored\"> " + DisplayConstants.READ_ONLY + " " +AbstractImagePrototype.create(iconsImageBundle.help16()).getHTML() + "</h4>");
			roContainer.setWidth("100px");			
			
			Map<String, String> optionsMap = new TreeMap<String, String>();
			optionsMap.put("title", DisplayConstants.WHY_VERSION_READ_ONLY_MODE);
			optionsMap.put("data-placement", "right");
			DisplayUtils.addTooltip(synapseJSNIUtils, roContainer, optionsMap);
			lc.add(roContainer);
		}

	    
	    lc.layout();
		return lc;
	}

	/*
	 * Private Methods
	 */

	/**
	 * Basic meta data about this entity
	 * @param entity
	 * @return
	 */
	private static Widget createMetadata(Entity entity) {
		FlowPanel panel = new FlowPanel();
		panel.getElement().setAttribute("style", "font-size: 80%;");

		InlineLabel label = new InlineLabel();
		label.setText("Added by: " + entity.getCreatedBy() + " on: "
				+ String.valueOf(entity.getCreatedOn()));
		panel.add(label);

		panel.add(new InlineHTML("<br />"));

		label = new InlineLabel();
		label.setText("Last updated by: " + entity.getModifiedBy() + " on: "
				+ String.valueOf(entity.getModifiedOn()));
		panel.add(label);

		if (entity instanceof Versionable) {
			Versionable vb = (Versionable) entity;

			panel.add(new InlineHTML("<br />"));
			label = new InlineLabel();
			StringBuilder sb = new StringBuilder();
			sb.append("Version: ");
			sb.append(vb.getVersionLabel());
			sb.append(" (");
			sb.append(vb.getVersionNumber());
			sb.append(")");

			if (vb.getVersionComment() != null) {
				sb.append(" - ");
				sb.append(vb.getVersionComment());
			}
			label.setText(sb.toString());
			panel.add(label);
		}

		return panel;
	}
	
}

{'fraction_non_alphanumeric': 0.14125874125874127, 'fraction_numerical': 0.0036363636363636364, 'mean_word_length': 5.009243697478992, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6443204', 'n_tokens_mistral': 2476, 'n_tokens_neox': 2256, 'n_words': 358}