Skip to content

Package: EMFFormsSpreadsheetFileExporterImpl

EMFFormsSpreadsheetFileExporterImpl

nameinstructionbranchcomplexitylinemethod
EMFFormsSpreadsheetFileExporterImpl()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
render(File, Collection, EObject, VViewModelProperties)
M: 55 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.spreadsheet.file;
15:
16: import java.io.File;
17: import java.io.FileOutputStream;
18: import java.io.IOException;
19: import java.util.Collection;
20:
21: import org.apache.poi.ss.usermodel.Workbook;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecp.view.spi.model.VViewModelProperties;
24: import org.eclipse.emfforms.spi.common.report.ReportService;
25: import org.eclipse.emfforms.spi.spreadsheet.core.EMFFormsSpreadsheetReport;
26: import org.eclipse.emfforms.spi.spreadsheet.core.transfer.EMFFormsSpreadsheetExporter;
27: import org.eclipse.emfforms.spi.spreadsheet.file.EMFFormsSpreadsheetFileExporter;
28: import org.osgi.framework.BundleContext;
29: import org.osgi.framework.FrameworkUtil;
30: import org.osgi.framework.ServiceReference;
31:
32: /**
33: * Class for exporting data to a workbook based on the provided File.
34: *
35: * @author Eugen Neufeld
36: *
37: */
38: public class EMFFormsSpreadsheetFileExporterImpl implements EMFFormsSpreadsheetFileExporter {
39:
40:         @Override
41:         public void render(File file, Collection<EObject> domainObjects, EObject viewEobject,
42:                 VViewModelProperties properties) {
43:                 final Workbook workbook = EMFFormsSpreadsheetExporter.INSTANCE.render(domainObjects, viewEobject, properties);
44:
45:                 final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
46:                 final ServiceReference<ReportService> serviceReference = bundleContext.getServiceReference(ReportService.class);
47:                 final ReportService reportService = bundleContext.getService(serviceReference);
48:
49:                 FileOutputStream outputStream = null;
50:                 try {
51:                         outputStream = new FileOutputStream(file);
52:                         workbook.write(outputStream);
53:                 } catch (final IOException ex) {
54:                         reportService.report(new EMFFormsSpreadsheetReport(ex, 4));
55:                 } finally {
56:                         try {
57:                                 outputStream.close();
58:                         } catch (final IOException ex) {
59:                                 reportService.report(new EMFFormsSpreadsheetReport(ex, 4));
60:                         }
61:                 }
62:                 bundleContext.ungetService(serviceReference);
63:         }
64:
65: }