<commit_before>package org.openlca.app.editors.systems;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.openlca.app.App;
import org.openlca.app.M;
import org.openlca.app.components.FileSelection;
import org.openlca.app.db.Cache;
import org.openlca.app.rcp.images.Images;
import org.openlca.app.util.FileType;
import org.openlca.app.util.UI;
import org.openlca.app.viewers.combo.AllocationMethodViewer;
import org.openlca.app.viewers.combo.ImpactMethodViewer;
import org.openlca.core.database.IDatabase;
import org.openlca.core.model.AllocationMethod;
import org.openlca.core.model.ProductSystem;
import org.openlca.core.model.descriptors.BaseDescriptor;
import org.openlca.io.xls.systems.SystemExport;
import org.openlca.io.xls.systems.SystemExportConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SystemExportDialog extends WizardDialog {

	private static class SystemExportWizard extends Wizard {

		private Logger log = LoggerFactory.getLogger(getClass());

		private class SystemExportWizardPage extends WizardPage {

			private AllocationMethodViewer allocationMethodViewer;
			private FileSelection directorySelection;
			private ImpactMethodViewer impactMethodViewer;

			protected SystemExportWizardPage() {
				super("SystemExportWizardPage");
				setImageDescriptor(Images.descriptor(FileType.EXCEL));
				setTitle(M.ProductSystemExcelExport);
				setDescription(M.ProductSystemExcelExportMessage);
				setPageComplete(false);
			}

			private Group createGroup(String label, Composite parent, int cols) {
				Group group = new Group(parent, SWT.NONE);
				UI.gridLayout(group, cols);
				UI.gridData(group, true, false);
				group.setText(label);
				return group;
			}

			@Override
			public void createControl(Composite parent) {
				Composite composite = new Composite(parent, SWT.NONE);
				UI.gridLayout(composite, 1);

				Group methodGroup = createGroup(M.Methods, composite, 1);
				UI.formLabel(methodGroup, M.AllocationMethod);
				allocationMethodViewer = new AllocationMethodViewer(
						methodGroup, AllocationMethod.values());
				UI.formLabel(methodGroup, M.ImpactAssessmentMethod);
				impactMethodViewer = new ImpactMethodViewer(methodGroup);
				impactMethodViewer.setInput(database);

				Group fileGroup = createGroup(M.ExportDirectory,
						composite, 1);
				directorySelection = new FileSelection(fileGroup);
				directorySelection.setSelectDirectory(true);
				directorySelection
						.addSelectionListener(new SelectionListener() {

							@Override
							public void widgetSelected(SelectionEvent e) {
								setPageComplete(directorySelection.getFile() != null);
							}

							@Override
							public void widgetDefaultSelected(SelectionEvent e) {
								setPageComplete(directorySelection.getFile() != null);
							}
						});
				setControl(composite);
			}

			private AllocationMethod getAllocationMethod() {
				return allocationMethodViewer.getSelected();
			}

			private BaseDescriptor getImpactMethod() {
				return impactMethodViewer.getSelected();
			}

			private File getDirectory() {
				return directorySelection.getFile();
			}

		}

		private IDatabase database;
		private ProductSystem productSystem;
		private SystemExportWizardPage page = new SystemExportWizardPage();

		private SystemExportWizard(ProductSystem productSystem,
				IDatabase database) {
			this.productSystem = productSystem;
			this.database = database;
			setNeedsProgressMonitor(true);
		}

		@Override
		public void addPages() {
			addPage(page);
		}

		@Override
		public boolean performFinish() {
			boolean errorOccured = false;
			final AllocationMethod allocation = page.getAllocationMethod();
			final BaseDescriptor impactMethod = page.getImpactMethod();
			final File directory = page.getDirectory();
			try {
				getContainer().run(true, true, new IRunnableWithProgress() {

					@Override
					public void run(IProgressMonitor monitor)
							throws InvocationTargetException,
							InterruptedException {
						monitor.beginTask(M.Export,
								IProgressMonitor.UNKNOWN);
						SystemExportConfig conf = new SystemExportConfig(
								productSystem, database, App.getSolver());
						conf.setAllocationMethod(allocation);
						conf.setEntityCache(Cache.getEntityCache());
						conf.setImpactMethod(impactMethod);
						conf.setMatrixCache(Cache.getMatrixCache());
						conf.setOlcaVersion(App.getVersion());
						SystemExport export = new SystemExport(conf);
						try {
							export.exportTo(directory);
						} catch (IOException e) {
							throw new InvocationTargetException(e);
						} finally {
							monitor.done();
						}
					}
				});
			} catch (Exception e) {
				errorOccured = true;
				log.error("Error while exporting system", e);
			}
			return !errorOccured;
		}
	}

	public SystemExportDialog(ProductSystem productSystem, IDatabase database) {
		super(UI.shell(), new SystemExportWizard(productSystem, database));
	}
}
<commit_msg>the Excel export of product<commit_after>package org.openlca.app.editors.systems;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.openlca.app.App;
import org.openlca.app.M;
import org.openlca.app.components.FileSelection;
import org.openlca.app.rcp.images.Images;
import org.openlca.app.util.FileType;
import org.openlca.app.util.UI;
import org.openlca.app.viewers.combo.AllocationMethodViewer;
import org.openlca.app.viewers.combo.ImpactMethodViewer;
import org.openlca.core.database.IDatabase;
import org.openlca.core.model.AllocationMethod;
import org.openlca.core.model.ProductSystem;
import org.openlca.io.xls.systems.SystemExport;
import org.openlca.io.xls.systems.SystemExportConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SystemExportDialog extends WizardDialog {

	private static class SystemExportWizard extends Wizard {

		private Logger log = LoggerFactory.getLogger(getClass());

		private class SystemExportWizardPage extends WizardPage {

			private AllocationMethodViewer allocationCombo;
			private FileSelection fileChooser;
			private ImpactMethodViewer impactCombo;

			protected SystemExportWizardPage() {
				super("SystemExportWizardPage");
				setImageDescriptor(Images.descriptor(FileType.EXCEL));
				setTitle(M.ProductSystemExcelExport);
				setDescription(M.ProductSystemExcelExportMessage);
				setPageComplete(false);
			}

			private Group createGroup(String label, Composite parent, int cols) {
				Group group = new Group(parent, SWT.NONE);
				UI.gridLayout(group, cols);
				UI.gridData(group, true, false);
				group.setText(label);
				return group;
			}

			@Override
			public void createControl(Composite parent) {
				Composite comp = new Composite(parent, SWT.NONE);
				UI.gridLayout(comp, 1);

				Group mgroup = createGroup(M.Methods, comp, 1);
				UI.formLabel(mgroup, M.AllocationMethod);
				allocationCombo = new AllocationMethodViewer(
						mgroup, AllocationMethod.values());
				UI.formLabel(mgroup, M.ImpactAssessmentMethod);
				impactCombo = new ImpactMethodViewer(mgroup);
				impactCombo.setInput(db);

				Group fgroup = createGroup(
						M.ExportDirectory, comp, 1);
				fileChooser = new FileSelection(fgroup);
				fileChooser.setSelectDirectory(true);
				fileChooser.addSelectionListener(new SelectionListener() {

					@Override
					public void widgetSelected(SelectionEvent e) {
						setPageComplete(fileChooser.getFile() != null);
					}

					@Override
					public void widgetDefaultSelected(SelectionEvent e) {
						setPageComplete(fileChooser.getFile() != null);
					}
				});
				setControl(comp);
			}
		}

		private IDatabase db;
		private ProductSystem system;
		private SystemExportWizardPage page = new SystemExportWizardPage();

		private SystemExportWizard(ProductSystem productSystem,
				IDatabase database) {
			this.system = productSystem;
			this.db = database;
			setNeedsProgressMonitor(true);
		}

		@Override
		public void addPages() {
			addPage(page);
		}

		@Override
		public boolean performFinish() {
			try {
				getContainer().run(true, true, monitor -> {
					monitor.beginTask(M.Export,
							IProgressMonitor.UNKNOWN);
					SystemExportConfig conf = new SystemExportConfig(
							system, db);
					conf.allocationMethod = page.allocationCombo.getSelected();
					conf.impactMethod = page.impactCombo.getSelected();
					conf.olcaVersion = App.getVersion();
					SystemExport export = new SystemExport(conf);
					try {
						export.exportTo(page.fileChooser.getFile());
					} catch (IOException e) {
						throw new InvocationTargetException(e);
					}
				});
				return true;
			} catch (Exception e) {
				log.error("Error while exporting system", e);
				return false;
			}
		}
	}

	public SystemExportDialog(ProductSystem system, IDatabase db) {
		super(UI.shell(), new SystemExportWizard(system, db));
	}
}

{'fraction_non_alphanumeric': 0.09798478305572692, 'fraction_numerical': 0.0010281719103434094, 'mean_word_length': 4.344505494505494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2497693', 'n_tokens_mistral': 3515, 'n_tokens_neox': 2849, 'n_words': 551}