<commit_before>package org.openlca.app.wizards.io;

import java.io.File;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.openlca.app.M;
import org.openlca.app.db.Database;
import org.openlca.app.navigation.Navigator;
import org.openlca.app.rcp.images.Icon;
import org.openlca.app.util.ErrorReporter;
import org.openlca.core.database.IDatabase;
import org.openlca.io.simapro.csv.input.SimaProCsvImport;

public class SimaProCsvImportWizard extends Wizard implements IImportWizard {

	private FileImportPage filePage;

	private File initialFile;

	public static void of(File file) {
		Wizards.forImport(
				"wizard.import.csv",
				(SimaProCsvImportWizard w) -> w.initialFile = file);
	}

	public SimaProCsvImportWizard() {
		setNeedsProgressMonitor(true);
		setWindowTitle(M.SimaProCSVImport);
		setDefaultPageImageDescriptor(
				Icon.IMPORT_ZIP_WIZARD.descriptor());
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
	}

	@Override
	public void addPages() {
		filePage = initialFile != null
				? new FileImportPage(initialFile)
				: new FileImportPage("csv");
		filePage.withMultiSelection = true;
		addPage(filePage);
	}

	@Override
	public boolean performFinish() {
		File[] files = filePage.getFiles();
		IDatabase db = Database.get();
		if (files == null || files.length == 0 || db == null)
			return false;
		var importer = new SimaProCsvImport(db, files);
		try {
			Database.getIndexUpdater().beginTransaction();
			getContainer().run(true, true, monitor -> {
				monitor.beginTask(M.Import, IProgressMonitor.UNKNOWN);
				ImportHandler handler = new ImportHandler(monitor);
				handler.run(importer);
			});
			Navigator.refresh();
		} catch (Exception e) {
			ErrorReporter.on("SimaPro CSV import failed", e);
		} finally {
			Database.getIndexUpdater().endTransaction();
		}
		return true;
	}<commit_msg>select flow mapping in SimaPro CSV imports<commit_after>package org.openlca.app.wizards.io;

import java.io.File;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.openlca.app.M;
import org.openlca.app.db.Database;
import org.openlca.app.navigation.Navigator;
import org.openlca.app.rcp.images.Icon;
import org.openlca.app.util.ErrorReporter;
import org.openlca.io.simapro.csv.input.SimaProCsvImport;

public class SimaProCsvImportWizard extends Wizard implements IImportWizard {

	private FileImportPage filePage;

	private File initialFile;

	public static void of(File file) {
		Wizards.forImport(
				"wizard.import.csv",
				(SimaProCsvImportWizard w) -> w.initialFile = file);
	}

	public SimaProCsvImportWizard() {
		setNeedsProgressMonitor(true);
		setWindowTitle(M.SimaProCSVImport);
		setDefaultPageImageDescriptor(
				Icon.IMPORT_ZIP_WIZARD.descriptor());
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
	}

	@Override
	public void addPages() {
		filePage = initialFile != null
				? new FileImportPage(initialFile)
				: new FileImportPage("csv");
		filePage.withMappingFile = true;
		filePage.withMultiSelection = true;
		addPage(filePage);
	}

	@Override
	public boolean performFinish() {
		File[] files = filePage.getFiles();
		var db = Database.get();
		if (files == null || files.length == 0 || db == null)
			return false;
		var importer = new SimaProCsvImport(db, files);
		if (filePage.flowMap != null) {
			importer.with(filePage.flowMap);
		}
		try {
			Database.getIndexUpdater().beginTransaction();
			getContainer().run(true, true, monitor -> {
				monitor.beginTask(M.Import, IProgressMonitor.UNKNOWN);
				var handler = new ImportHandler(monitor);
				handler.run(importer);
			});
			Navigator.refresh();
		} catch (Exception e) {
			ErrorReporter.on("SimaPro CSV import failed", e);
		} finally {
			Database.getIndexUpdater().endTransaction();
		}
		return true;
	}
{'fraction_non_alphanumeric': 0.11657032755298652, 'fraction_numerical': 0.0004816955684007707, 'mean_word_length': 4.720385674931129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3835450', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1376, 'n_words': 266}