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

import java.util.Map;
import java.util.Map.Entry;
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.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.Hyperlink;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;

public class TitleWidget {


	private LayoutContainer lc;
	private EntityMetadata entityMetadata;

	public TitleWidget(EntityBundle bundle, String entityTypeDisplay,
			IconsImageBundle iconsImageBundle, boolean canEdit,
			boolean readOnly, SynapseJSNIUtils synapseJSNIUtils) {
		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()));

	    // 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);
		}

	    // Metadata
	    lc.add(createMetadata(bundle.getEntity(), iconsImageBundle));

	    lc.layout();
	}

	public Widget asWidget() {
		return lc;
	}

	public void setVersions(Versionable entity, TreeMap<Long, String> latestVersions) {
		entityMetadata.clearPreviousVersions();
		if (latestVersions == null || latestVersions.size() < 1) {
			InlineLabel notFound = new InlineLabel(DisplayConstants.ERROR_VERSIONS_NOT_FOUND);
			entityMetadata.addToPreviousVersions(notFound);
			return;
		}

		boolean first = true;
		for (Entry<Long, String> entry : latestVersions.entrySet()) {
			StringBuilder label = new StringBuilder();
			label.append(entry.getValue().toString());
			label.append(" [");
			label.append(entry.getKey().toString());
			label.append("]");

			if (first) {
				label.append(" (latest)");
			}

			if (!entity.getVersionNumber().equals(entry.getKey())) {
				StringBuilder target = new StringBuilder("Synapse:");
				target.append(entity.getId());
				if (!first) {
					target.append("/version/");
					target.append(entry.getKey());
				}

				Hyperlink anchor = new Hyperlink(label.toString(),
						target.toString());
				anchor.setStyleName("link");

				entityMetadata.addToPreviousVersions(anchor);
			} else {
				InlineLabel widget = new InlineLabel(label.toString());
				widget.addStyleName(entityMetadata.getStyle().currentVersion());
				entityMetadata.addToPreviousVersions(widget);
			}
			first = false;

		}
	}

	public void clear() {
		lc.clearState();
		lc.removeAll();
	}
<commit_msg>Switch to getting link targets the correct way<commit_after>package org.sagebionetworks.web.client.widget.entity;

import java.util.Map;
import java.util.Map.Entry;
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.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.Hyperlink;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;

public class TitleWidget {


	private LayoutContainer lc;
	private EntityMetadata entityMetadata;

	public TitleWidget(EntityBundle bundle, String entityTypeDisplay,
			IconsImageBundle iconsImageBundle, boolean canEdit,
			boolean readOnly, SynapseJSNIUtils synapseJSNIUtils) {
		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()));

	    // 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);
		}

	    // Metadata
	    lc.add(createMetadata(bundle.getEntity(), iconsImageBundle));

	    lc.layout();
	}

	public Widget asWidget() {
		return lc;
	}

	public void setVersions(Versionable entity, TreeMap<Long, String> latestVersions) {
		entityMetadata.clearPreviousVersions();
		if (latestVersions == null || latestVersions.size() < 1) {
			InlineLabel notFound = new InlineLabel(DisplayConstants.ERROR_VERSIONS_NOT_FOUND);
			entityMetadata.addToPreviousVersions(notFound);
			return;
		}

		boolean first = true;
		for (Entry<Long, String> entry : latestVersions.entrySet()) {
			StringBuilder label = new StringBuilder();
			label.append(entry.getValue().toString());
			label.append(" [");
			label.append(entry.getKey().toString());
			label.append("]");

			if (first) {
				label.append(" (latest)");
			}

			if (!entity.getVersionNumber().equals(entry.getKey())) {
				String historyTokenNoHash = DisplayUtils.
				   getSynapseHistoryTokenNoHash(entity.getId(),
				                                (first ? null : entry.getKey()));

				Hyperlink anchor = new Hyperlink(label.toString(), historyTokenNoHash);
				anchor.setStyleName("link");

				entityMetadata.addToPreviousVersions(anchor);
			} else {
				InlineLabel widget = new InlineLabel(label.toString());
				widget.addStyleName(entityMetadata.getStyle().currentVersion());
				entityMetadata.addToPreviousVersions(widget);
			}
			first = false;

		}
	}

	public void clear() {
		lc.clearState();
		lc.removeAll();
	}

{'fraction_non_alphanumeric': 0.13355006501950586, 'fraction_numerical': 0.0031209362808842654, 'mean_word_length': 5.055905511811024, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '4266660', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2391, 'n_words': 385}