<commit_before>package org.openlca.app.results;

import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.openlca.app.Messages;
import org.openlca.app.components.ContributionImage;
import org.openlca.app.db.Cache;
import org.openlca.app.util.Actions;
import org.openlca.app.util.Controls;
import org.openlca.app.util.Labels;
import org.openlca.app.util.Numbers;
import org.openlca.app.util.TableClipboard;
import org.openlca.app.util.Tables;
import org.openlca.app.util.UI;
import org.openlca.app.viewers.combo.ImpactCategoryViewer;
import org.openlca.core.model.descriptors.FlowDescriptor;
import org.openlca.core.results.ContributionItem;
import org.openlca.core.results.ContributionResultProvider;
import org.openlca.core.results.ContributionSet;
import org.openlca.core.results.Contributions;

/**
 * Shows the contributions of flows to an LCIA result.
 */
public class FlowImpactPage extends FormPage {

	private final static String[] COLUMN_LABELS = { Messages.Contribution,
			Messages.Flow, Messages.Category, Messages.SubCategory,
			Messages.Amount, Messages.Unit };

	private ContributionResultProvider<?> result;
	private ImpactCategoryViewer impactCombo;
	private TableViewer table;
	private Spinner spinner;
	private double cutOff = 1;

	public FlowImpactPage(FormEditor editor,
			ContributionResultProvider<?> result) {
		super(editor, "FlowImpactPage", Messages.FlowContributions);
		this.result = result;
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		FormToolkit toolkit = managedForm.getToolkit();
		ScrolledForm form = UI.formHeader(managedForm,
				Messages.FlowContributions);
		Composite body = UI.formBody(form, toolkit);
		Composite composite = toolkit.createComposite(body);
		UI.gridLayout(composite, 1);
		UI.gridData(composite, true, true);
		makeSelectionElements(toolkit, composite);
		makeTable(composite);
		form.reflow(true);
		impactCombo.selectFirst();
	}

	private void makeSelectionElements(FormToolkit toolkit, Composite parent) {
		Composite composite = toolkit.createComposite(parent);
		UI.gridData(composite, true, false);
		UI.gridLayout(composite, 5);
		UI.formLabel(composite, toolkit, Messages.ImpactCategory);
		createImpactViewer(composite);
		UI.formLabel(composite, toolkit, Messages.Cutoff);
		spinner = new Spinner(composite, SWT.BORDER);
		spinner.setValues(1, 0, 10000, 2, 1, 100);
		toolkit.adapt(spinner);
		toolkit.createLabel(composite, "%");
		Controls.onSelect(spinner, (e) -> {
			cutOff = spinner.getSelection();
			table.refresh();
		});
	}

	private void createImpactViewer(Composite parent) {
		impactCombo = new ImpactCategoryViewer(parent);
		impactCombo.setInput(result.getImpactDescriptors());
		impactCombo.addSelectionChangedListener((impact) -> {
			ContributionSet<FlowDescriptor> contributions = result
					.getFlowContributions(impact);
			List<ContributionItem<FlowDescriptor>> items = contributions
					.getContributions();
			Contributions.sortDescending(items);
			table.setInput(items);
		});
	}

	private void makeTable(Composite parent) {
		table = Tables.createViewer(parent, COLUMN_LABELS);
		table.setLabelProvider(new FlowImpactLabelProvider());
		table.setFilters(new ViewerFilter[] { new CutOffFilter() });
		Tables.bindColumnWidths(table.getTable(), new double[] { 0.1, 0.3, 0.2,
				0.2, 0.1, 0.1 });
		Actions.bind(table, TableClipboard.onCopy(table));
	}

	private class FlowImpactLabelProvider extends BaseLabelProvider implements<commit_msg>corrected scale in cut-off spinner in flow contributions page<commit_after>package org.openlca.app.results;

import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.openlca.app.Messages;
import org.openlca.app.components.ContributionImage;
import org.openlca.app.db.Cache;
import org.openlca.app.util.Actions;
import org.openlca.app.util.Controls;
import org.openlca.app.util.Labels;
import org.openlca.app.util.Numbers;
import org.openlca.app.util.TableClipboard;
import org.openlca.app.util.Tables;
import org.openlca.app.util.UI;
import org.openlca.app.viewers.combo.ImpactCategoryViewer;
import org.openlca.core.model.descriptors.FlowDescriptor;
import org.openlca.core.results.ContributionItem;
import org.openlca.core.results.ContributionResultProvider;
import org.openlca.core.results.ContributionSet;
import org.openlca.core.results.Contributions;

/**
 * Shows the contributions of flows to an LCIA result.
 */
public class FlowImpactPage extends FormPage {

	private final static String[] COLUMN_LABELS = { Messages.Contribution,
			Messages.Flow, Messages.Category, Messages.SubCategory,
			Messages.Amount, Messages.Unit };

	private ContributionResultProvider<?> result;
	private ImpactCategoryViewer impactCombo;
	private TableViewer table;
	private Spinner spinner;
	private double cutOff = 1;

	public FlowImpactPage(FormEditor editor,
			ContributionResultProvider<?> result) {
		super(editor, "FlowImpactPage", Messages.FlowContributions);
		this.result = result;
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		FormToolkit toolkit = managedForm.getToolkit();
		ScrolledForm form = UI.formHeader(managedForm,
				Messages.FlowContributions);
		Composite body = UI.formBody(form, toolkit);
		Composite composite = toolkit.createComposite(body);
		UI.gridLayout(composite, 1);
		UI.gridData(composite, true, true);
		makeSelectionElements(toolkit, composite);
		makeTable(composite);
		form.reflow(true);
		impactCombo.selectFirst();
	}

	private void makeSelectionElements(FormToolkit toolkit, Composite parent) {
		Composite composite = toolkit.createComposite(parent);
		UI.gridData(composite, true, false);
		UI.gridLayout(composite, 5);
		UI.formLabel(composite, toolkit, Messages.ImpactCategory);
		createImpactViewer(composite);
		UI.formLabel(composite, toolkit, Messages.Cutoff);
		spinner = new Spinner(composite, SWT.BORDER);
		spinner.setValues(1, 0, 100, 0, 1, 10);
		toolkit.adapt(spinner);
		toolkit.createLabel(composite, "%");
		Controls.onSelect(spinner, (e) -> {
			cutOff = spinner.getSelection();
			table.refresh();
		});
	}

	private void createImpactViewer(Composite parent) {
		impactCombo = new ImpactCategoryViewer(parent);
		impactCombo.setInput(result.getImpactDescriptors());
		impactCombo.addSelectionChangedListener((impact) -> {
			ContributionSet<FlowDescriptor> contributions = result
					.getFlowContributions(impact);
			List<ContributionItem<FlowDescriptor>> items = contributions
					.getContributions();
			Contributions.sortDescending(items);
			table.setInput(items);
		});
	}

	private void makeTable(Composite parent) {
		table = Tables.createViewer(parent, COLUMN_LABELS);
		table.setLabelProvider(new FlowImpactLabelProvider());
		table.setFilters(new ViewerFilter[] { new CutOffFilter() });
		Tables.bindColumnWidths(table.getTable(), new double[] { 0.1, 0.3, 0.2,
				0.2, 0.1, 0.1 });
		Actions.bind(table, TableClipboard.onCopy(table));
	}

	private class FlowImpactLabelProvider extends BaseLabelProvider implements
{'fraction_non_alphanumeric': 0.11334530221424297, 'fraction_numerical': 0.006343506882106523, 'mean_word_length': 5.782467532467533, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '2400193', 'n_tokens_mistral': 2889, 'n_tokens_neox': 2679, 'n_words': 477}