package org.openlca.app.editors.reports;

import org.openlca.app.App;
import org.openlca.app.editors.reports.model.Report;
import org.openlca.app.editors.reports.model.ReportCalculator;
import org.openlca.app.editors.reports.model.ReportSection;
import org.openlca.core.model.Project;

public final class Reports {

	private Reports() {
	}

	public static void createAndOpen(Project project) {
		final Report report = new Report();
		createDefaultSections(report);
		if (project == null) {
			report.setTitle("No project");
			ReportEditor.open(report);
			return;
		}
		report.setProject(project);
		report.setTitle(project.getName());
		App.run("Calculate results",
				new ReportCalculator(project, report),
				() -> ReportEditor.open(report));
	}

	private static void createDefaultSections(Report report) {
		String[] headers = { "Introduction", "Functional Unit",
				"System boundaries", "Impact assessment method", "Results",
				"Assumptions and uncertainties", "Discussion and conclusions" };
		for (String header : headers) {
			ReportSection section = new ReportSection();
			section.setTitle(header);
			section.setText("TODO: add some text here");
			report.getSections().add(section);
		}
	}
}

@@ -262,25 +262,131 @@
 lca.
-core.model.Projec
+app.editors.reports.model.ReportVariant;%0Aimport org.openlca.core.model.Project;%0Aimport org.openlca.core.model.ProjectVarian
 t;%0A%0A
@@ -736,16 +736,51 @@
 ame());%0A
+%09%09createVariants(project, report);%0A
 %09%09App.ru
@@ -845,16 +845,16 @@
 eport),%0A
-
 %09%09%09%09() -
@@ -887,16 +887,385 @@
 ));%0A%09%7D%0A%0A
+%09private static void createVariants(Project project, Report report) %7B%0A%09%09if (project == null)%0A%09%09%09return;%0A%09%09for (ProjectVariant variant : project.getVariants()) %7B%0A%09%09%09ReportVariant reportVariant = new ReportVariant();%0A%09%09%09reportVariant.setName(variant.getName());%0A%09%09%09reportVariant.setUserFriendlyName(variant.getName());%0A%09%09%09report.getVariants().add(reportVariant);%0A%09%09%7D%0A%09%7D%0A%0A
 %09private

create default report variants