<commit_before>package org.openlca.app.viewers.table;

import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.openlca.app.Messages;
import org.openlca.app.resources.ImageType;
import org.openlca.app.util.Numbers;
import org.openlca.app.util.UI;
import org.openlca.app.viewers.table.modify.CheckBoxCellModifier;
import org.openlca.app.viewers.table.modify.TextCellModifier;
import org.openlca.app.viewers.table.modify.IModelChangedListener.ModelChangeType;
import org.openlca.core.model.Unit;
import org.openlca.core.model.UnitGroup;

import com.google.common.base.Objects;

public class UnitViewer extends AbstractTableViewer<Unit> {

	private interface LABEL {

		String CONVERSION_FACTOR = Messages.Units_ConversionFactor;
		String DESCRIPTION = Messages.Common_Description;
		String FORMULA = Messages.Units_Formula;
		String IS_REFERENCE = Messages.Units_IsReference;
		String NAME = Messages.Common_Name;
		String SYNONYMS = Messages.Units_Synonyms;

	}

	private static final String[] COLUMN_HEADERS = { LABEL.NAME,
			LABEL.DESCRIPTION, LABEL.SYNONYMS, LABEL.CONVERSION_FACTOR,
			LABEL.FORMULA, LABEL.IS_REFERENCE };

	private UnitGroup unitGroup;

	public UnitViewer(Composite parent) {
		super(parent);
		getCellModifySupport().support(LABEL.NAME, new NameModifier());
		getCellModifySupport().support(LABEL.DESCRIPTION,
				new DescriptionModifier());
		getCellModifySupport().support(LABEL.SYNONYMS, new SynonymsModifier());
		getCellModifySupport().support(LABEL.CONVERSION_FACTOR,
				new ConversionFactorModifier());
		getCellModifySupport().support(LABEL.IS_REFERENCE,
				new ReferenceModifier());
		getViewer().refresh(true);
	}

	public void setInput(UnitGroup unitGroup) {
		super.setInput(unitGroup.getUnits().toArray(
				new Unit[unitGroup.getUnits().size()]));
		this.unitGroup = unitGroup;
		getViewer().refresh(true);
	}

	@Override
	protected IBaseLabelProvider getLabelProvider() {
		return new UnitLabelProvider();
	}

	@Override
	protected String[] getColumnHeaders() {
		return COLUMN_HEADERS;
	}

	@OnCreate
	protected void onCreate() {
		Unit unit = new Unit();
		unit.setName("newUnit");
		unit.setConversionFactor(1d);
		fireModelChanged(ModelChangeType.CREATE, unit);<commit_msg>Fixed null pointer<commit_after>package org.openlca.app.viewers.table;

import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.openlca.app.Messages;
import org.openlca.app.resources.ImageType;
import org.openlca.app.util.Numbers;
import org.openlca.app.util.UI;
import org.openlca.app.viewers.table.modify.CheckBoxCellModifier;
import org.openlca.app.viewers.table.modify.IModelChangedListener.ModelChangeType;
import org.openlca.app.viewers.table.modify.TextCellModifier;
import org.openlca.core.model.Unit;
import org.openlca.core.model.UnitGroup;

import com.google.common.base.Objects;

public class UnitViewer extends AbstractTableViewer<Unit> {

	private interface LABEL {

		String CONVERSION_FACTOR = Messages.Units_ConversionFactor;
		String DESCRIPTION = Messages.Common_Description;
		String FORMULA = Messages.Units_Formula;
		String IS_REFERENCE = Messages.Units_IsReference;
		String NAME = Messages.Common_Name;
		String SYNONYMS = Messages.Units_Synonyms;

	}

	private static final String[] COLUMN_HEADERS = { LABEL.NAME,
			LABEL.DESCRIPTION, LABEL.SYNONYMS, LABEL.CONVERSION_FACTOR,
			LABEL.FORMULA, LABEL.IS_REFERENCE };

	private UnitGroup unitGroup;

	public UnitViewer(Composite parent) {
		super(parent);
		getCellModifySupport().support(LABEL.NAME, new NameModifier());
		getCellModifySupport().support(LABEL.DESCRIPTION,
				new DescriptionModifier());
		getCellModifySupport().support(LABEL.SYNONYMS, new SynonymsModifier());
		getCellModifySupport().support(LABEL.CONVERSION_FACTOR,
				new ConversionFactorModifier());
		getCellModifySupport().support(LABEL.IS_REFERENCE,
				new ReferenceModifier());
		getViewer().refresh(true);
	}

	public void setInput(UnitGroup unitGroup) {
		this.unitGroup = unitGroup;
		if (unitGroup == null)
			setInput(new Unit[0]);
		else
			setInput(unitGroup.getUnits().toArray(
					new Unit[unitGroup.getUnits().size()]));
		getViewer().refresh(true);
	}

	@Override
	protected IBaseLabelProvider getLabelProvider() {
		return new UnitLabelProvider();
	}

	@Override
	protected String[] getColumnHeaders() {
		return COLUMN_HEADERS;
	}

	@OnCreate
	protected void onCreate() {
		Unit unit = new Unit();
		unit.setName("newUnit");
		unit.setConversionFactor(1d);
		fireModelChanged(ModelChangeType.CREATE, unit);
{'fraction_non_alphanumeric': 0.10920559826532623, 'fraction_numerical': 0.0005913660555884093, 'mean_word_length': 5.894021739130435, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5009564', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1676, 'n_words': 269}