<commit_before>package de.darwinspl.feature.graphical.base.deltaecore.wrapper;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.deltaecore.feature.graphical.base.editor.DEGraphicalEditor;
import org.deltaecore.feature.graphical.base.util.DEGeometryUtil;
import org.deltaecore.feature.graphical.base.util.DEGraphicalEditorTheme;
import org.eclipse.draw2d.geometry.Rectangle;

import de.darwinspl.feature.graphical.base.deltaecore.wrapper.layouter.version.DwVersionLayouterManager;
import de.darwinspl.feature.graphical.base.deltaecore.wrapper.layouter.version.DwVersionTreeLayouter;
import eu.hyvar.evolution.HyName;
import eu.hyvar.evolution.util.HyEvolutionUtil;
import eu.hyvar.feature.HyFeature;
import eu.hyvar.feature.HyFeatureAttribute;
import eu.hyvar.feature.HyFeatureChild;
import eu.hyvar.feature.HyGroup;
import eu.hyvar.feature.HyGroupComposition;
import eu.hyvar.feature.HyGroupType;
import eu.hyvar.feature.HyGroupTypeEnum;
import eu.hyvar.feature.HyVersion;
import eu.hyvar.feature.util.HyFeatureModelWellFormednessException;
import eu.hyvar.feature.util.HyFeatureUtil;

public class DwGeometryUtil {
	public static int calculateFeatureWidth(HyFeature feature, Date date) {
		if(date == null) date = new Date();

		DEGraphicalEditorTheme theme = DEGraphicalEditor.getTheme();
		int rawFeatureWidth = theme.getFeatureMinimumWidth();

		//Label width
		HyName name = HyEvolutionUtil.getValidTemporalElement(feature.getNames(), date);
		String featureName = (name != null) ? name.getName() : "No Valid Name";
		int labelWidth = DEGeometryUtil.getTextWidth(featureName, theme.getFeatureFont());
		rawFeatureWidth = Math.max(rawFeatureWidth, labelWidth);

		//Version tree width
		if (!feature.getVersions().isEmpty()) {
			DwVersionTreeLayouter versionTreeLayouter = DwVersionLayouterManager.getLayouter(feature, date);

			if(versionTreeLayouter != null){
				Rectangle versionTreeBounds = versionTreeLayouter.getTreeBounds();
				int versionTreeWidth = versionTreeBounds.width; // + HyVersionTreeLayouter.getOffsetX();
				rawFeatureWidth = Math.max(rawFeatureWidth, versionTreeWidth);
			}
		}


		for(HyFeatureAttribute attribute : HyEvolutionUtil.getValidTemporalElements(feature.getAttributes(), date)){
			HyName attributeName = HyEvolutionUtil.getValidTemporalElement(attribute.getNames(), date);
			if(attributeName != null){
				int nameWidth = DEGeometryUtil.getTextWidth(name.getName(), theme.getFeatureFont());
				int typeWidth = DEGeometryUtil.getTextWidth("Boolean", theme.getFeatureFont());

				rawFeatureWidth = Math.max(rawFeatureWidth, nameWidth + typeWidth + 80);
			}
		}

		if(!feature.getParentOf().isEmpty()){
			HyFeatureChild child = HyEvolutionUtil.getValidTemporalElement(feature.getParentOf(), date);
			if(child != null){
				HyGroup group = child.getChildGroup();<commit_msg>Fix nullpointer exception with renaming of feature<commit_after>package de.darwinspl.feature.graphical.base.deltaecore.wrapper;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.deltaecore.feature.graphical.base.editor.DEGraphicalEditor;
import org.deltaecore.feature.graphical.base.util.DEGeometryUtil;
import org.deltaecore.feature.graphical.base.util.DEGraphicalEditorTheme;
import org.eclipse.draw2d.geometry.Rectangle;

import de.darwinspl.feature.graphical.base.deltaecore.wrapper.layouter.version.DwVersionLayouterManager;
import de.darwinspl.feature.graphical.base.deltaecore.wrapper.layouter.version.DwVersionTreeLayouter;
import eu.hyvar.evolution.HyName;
import eu.hyvar.evolution.util.HyEvolutionUtil;
import eu.hyvar.feature.HyFeature;
import eu.hyvar.feature.HyFeatureAttribute;
import eu.hyvar.feature.HyFeatureChild;
import eu.hyvar.feature.HyGroup;
import eu.hyvar.feature.HyGroupComposition;
import eu.hyvar.feature.HyGroupType;
import eu.hyvar.feature.HyGroupTypeEnum;
import eu.hyvar.feature.HyVersion;
import eu.hyvar.feature.util.HyFeatureModelWellFormednessException;
import eu.hyvar.feature.util.HyFeatureUtil;

public class DwGeometryUtil {
	public static int calculateFeatureWidth(HyFeature feature, Date date) {
		if(date == null) date = new Date();

		DEGraphicalEditorTheme theme = DEGraphicalEditor.getTheme();
		int rawFeatureWidth = theme.getFeatureMinimumWidth();

		//Label width
		HyName name = HyEvolutionUtil.getValidTemporalElement(feature.getNames(), date);
		String featureName = (name != null) ? name.getName() : "No Valid Name";
		int labelWidth = DEGeometryUtil.getTextWidth(featureName, theme.getFeatureFont());
		rawFeatureWidth = Math.max(rawFeatureWidth, labelWidth);

		//Version tree width
		if (!feature.getVersions().isEmpty()) {
			DwVersionTreeLayouter versionTreeLayouter = DwVersionLayouterManager.getLayouter(feature, date);

			if(versionTreeLayouter != null){
				Rectangle versionTreeBounds = versionTreeLayouter.getTreeBounds();
				int versionTreeWidth = versionTreeBounds.width; // + HyVersionTreeLayouter.getOffsetX();
				rawFeatureWidth = Math.max(rawFeatureWidth, versionTreeWidth);
			}
		}


		for(HyFeatureAttribute attribute : HyEvolutionUtil.getValidTemporalElements(feature.getAttributes(), date)){
			HyName attributeName = HyEvolutionUtil.getValidTemporalElement(attribute.getNames(), date);
			if(attributeName != null){
				int nameWidth = DEGeometryUtil.getTextWidth(attributeName.getName(), theme.getFeatureFont());
				int typeWidth = DEGeometryUtil.getTextWidth("Boolean", theme.getFeatureFont());

				rawFeatureWidth = Math.max(rawFeatureWidth, nameWidth + typeWidth + 80);
			}
		}

		if(!feature.getParentOf().isEmpty()){
			HyFeatureChild child = HyEvolutionUtil.getValidTemporalElement(feature.getParentOf(), date);
			if(child != null){
				HyGroup group = child.getChildGroup();
{'fraction_non_alphanumeric': 0.10798611111111112, 'fraction_numerical': 0.0010416666666666667, 'mean_word_length': 6.228356336260979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5716910', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1719, 'n_words': 285}