diff --git a/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/CommonInstanceExportConfigurationPage.java b/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/CommonInstanceExportConfigurationPage.java
new file mode 100644
index 0000000000..c68eea2b23
--- /dev/null
+++ b/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/CommonInstanceExportConfigurationPage.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2014 Data Harmonisation Panel
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution. If not, see .
+ *
+ * Contributors:
+ * Data Harmonisation Panel
+ */
+
+package eu.esdihumboldt.hale.io.csv.ui;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.esdihumboldt.hale.common.core.io.Value;
+import eu.esdihumboldt.hale.common.instance.io.InstanceWriter;
+import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants;
+import eu.esdihumboldt.hale.ui.io.IOWizard;
+import eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage;
+
+/**
+ * Configuration page for exporting of instances
+ *
+ * @author Emanuela Epure
+ */
+public class CommonInstanceExportConfigurationPage
+ extends AbstractConfigurationPage> {
+
+ protected Button solveNestedProperties;
+ protected Button useSchema;
+ protected Composite page;
+
+ /**
+ * @param title
+ *
+ */
+ public CommonInstanceExportConfigurationPage(String title) {
+ super(title);
+ setTitle("Additonal Export Options");
+ setDescription("Select if nested properties should be solved and a type");
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage#enable()
+ */
+ @Override
+ public void enable() {
+ // not required
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage#disable()
+ */
+ @Override
+ public void disable() {
+ // not required
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.ui.io.IOWizardPage#updateConfiguration(eu.esdihumboldt.hale.common.core.io.IOProvider)
+ */
+ @Override
+ public boolean updateConfiguration(InstanceWriter provider) {
+ provider.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES,
+ Value.of(solveNestedProperties.getSelection()));
+ provider.setParameter(InstanceTableIOConstants.USE_SCHEMA,
+ Value.of(useSchema.getSelection()));
+ return true;
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createContent(Composite page) {
+ this.page = page;
+
+ page.setLayout(new GridLayout(1, false));
+
+ solveNestedProperties = new Button(page, SWT.CHECK);
+ solveNestedProperties.setText("Solve nested properties");
+ solveNestedProperties.setSelection(true);
+
+ useSchema = new Button(page, SWT.CHECK);
+ useSchema.setText("Use the source schema for the order of the exported columns");
+ useSchema.setSelection(true);
+ }
+
+}
diff --git a/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/InstanceExportConfigurationPage.java b/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/InstanceExportConfigurationPage.java
index f8529bb8fd..a30d08fb84 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/InstanceExportConfigurationPage.java
+++ b/io/plugins/eu.esdihumboldt.hale.io.csv.ui/src/eu/esdihumboldt/hale/io/csv/ui/InstanceExportConfigurationPage.java
@@ -21,8 +21,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
@@ -34,8 +32,6 @@
import eu.esdihumboldt.hale.common.schema.model.TypeDefinition;
import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants;
import eu.esdihumboldt.hale.ui.common.definition.selector.TypeDefinitionSelector;
-import eu.esdihumboldt.hale.ui.io.IOWizard;
-import eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage;
import eu.esdihumboldt.hale.ui.service.instance.InstanceService;
/**
@@ -43,13 +39,9 @@
*
* @author Patrick Lieb
*/
-public class InstanceExportConfigurationPage
- extends AbstractConfigurationPage> {
+public class InstanceExportConfigurationPage extends CommonInstanceExportConfigurationPage {
- private Button solveNestedProperties;
- private Button useSchema;
private TypeDefinitionSelector typeSelector;
- private Composite page;
private final ViewerFilter validTypesToSelect = new ViewerFilter() {
@@ -102,10 +94,7 @@ public void disable() {
*/
@Override
public boolean updateConfiguration(InstanceWriter provider) {
- provider.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES,
- Value.of(solveNestedProperties.getSelection()));
- provider.setParameter(InstanceTableIOConstants.USE_SCHEMA,
- Value.of(useSchema.getSelection()));
+ super.updateConfiguration(provider);
provider.setParameter(InstanceTableIOConstants.EXPORT_TYPE,
Value.of(typeSelector.getSelectedObject().getName().toString()));
return true;
@@ -116,17 +105,7 @@ public boolean updateConfiguration(InstanceWriter provider) {
*/
@Override
protected void createContent(Composite page) {
- this.page = page;
-
- page.setLayout(new GridLayout(1, false));
-
- solveNestedProperties = new Button(page, SWT.CHECK);
- solveNestedProperties.setText("Solve nested properties");
- solveNestedProperties.setSelection(true);
-
- useSchema = new Button(page, SWT.CHECK);
- useSchema.setText("Use the source schema for the order of the exported columns");
- useSchema.setSelection(true);
+ super.createContent(page);
final Label label = new Label(page, SWT.NONE);
label.setText("Choose your Type you want to export:");
diff --git a/io/plugins/eu.esdihumboldt.hale.io.csv/src/eu/esdihumboldt/hale/io/csv/InstanceTableIOConstants.java b/io/plugins/eu.esdihumboldt.hale.io.csv/src/eu/esdihumboldt/hale/io/csv/InstanceTableIOConstants.java
index 0b547d15b7..1ebaaa38b0 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.csv/src/eu/esdihumboldt/hale/io/csv/InstanceTableIOConstants.java
+++ b/io/plugins/eu.esdihumboldt.hale.io.csv/src/eu/esdihumboldt/hale/io/csv/InstanceTableIOConstants.java
@@ -45,4 +45,9 @@ public class InstanceTableIOConstants {
*/
public static final String EXPORT_TYPE = "selectedExportType";
+ /**
+ * Parameter for exporting empty feature types to XLS Export
+ */
+ public static final String EXPORT_IGNORE_EMPTY_FEATURETYPES = "ignoreEmptyFeaturetypes";
+
}
diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/XLSInstanceIOTest.java b/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/XLSInstanceIOTest.java
index 46b2017485..a09d9c9581 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/XLSInstanceIOTest.java
+++ b/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/XLSInstanceIOTest.java
@@ -18,11 +18,13 @@
import eu.esdihumboldt.hale.common.instance.model.InstanceCollection;
import eu.esdihumboldt.hale.common.instance.model.InstanceUtil;
import eu.esdihumboldt.hale.common.schema.model.Schema;
+import eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace;
import eu.esdihumboldt.hale.common.test.TestUtil;
import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants;
import eu.esdihumboldt.hale.io.csv.reader.CommonSchemaConstants;
import eu.esdihumboldt.hale.io.xls.reader.XLSInstanceReader;
import eu.esdihumboldt.hale.io.xls.reader.XLSSchemaReader;
+import eu.esdihumboldt.hale.io.xls.test.writer.XLSInstanceWriterTestUtil;
import eu.esdihumboldt.hale.io.xls.writer.XLSInstanceWriter;
import junit.framework.TestCase;
@@ -57,10 +59,20 @@ public void test() {
IContentType contentType = HalePlatform.getContentTypeManager()
.getContentType("eu.esdihumboldt.hale.io.xls.xls");
writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.USE_SCHEMA, Value.of(true));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES,
+ Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of("ItemType"));
+
File tempDir = Files.createTempDir();
File tempFile = new File(tempDir, "data.xls");
writer.setInstances(instances);
try {
+ Schema schema = XLSInstanceWriterTestUtil.createExampleSchema();
+ DefaultSchemaSpace ss = new DefaultSchemaSpace();
+ ss.addSchema(schema);
+ writer.setTargetSchema(ss);
+
// write instances to a temporary XLS file
writer.setTarget(new FileIOSupplier(tempFile));
writer.setContentType(contentType);
diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/writer/XLSInstanceWriterTest.java b/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/writer/XLSInstanceWriterTest.java
index 88437eb27b..2a90b88ce2 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/writer/XLSInstanceWriterTest.java
+++ b/io/plugins/eu.esdihumboldt.hale.io.xls.test/src/eu/esdihumboldt/hale/io/xls/test/writer/XLSInstanceWriterTest.java
@@ -19,6 +19,7 @@
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,7 +42,9 @@
import eu.esdihumboldt.hale.common.core.io.report.IOReport;
import eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier;
import eu.esdihumboldt.hale.common.instance.model.InstanceCollection;
+import eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection;
import eu.esdihumboldt.hale.common.schema.model.Schema;
+import eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace;
import eu.esdihumboldt.hale.common.test.TestUtil;
import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants;
import eu.esdihumboldt.hale.io.xls.writer.XLSInstanceWriter;
@@ -93,10 +96,16 @@ public void testWriteSimpleSchemaColOrder() throws Exception {
.getContentType("eu.esdihumboldt.hale.io.xls.xls");
writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(true));
writer.setParameter(InstanceTableIOConstants.USE_SCHEMA, Value.of(true));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES,
+ Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of("city"));
File tmpFile = tmpFolder.newFile("excelTestWriteSimpleSchema.xls");
writer.setInstances(instance);
+ DefaultSchemaSpace ss = new DefaultSchemaSpace();
+ ss.addSchema(schema);
+ writer.setTargetSchema(ss);
// write instances to a temporary XLS file
writer.setTarget(new FileIOSupplier(tmpFile));
writer.setContentType(contentType);
@@ -114,6 +123,7 @@ public void testWriteSimpleSchemaColOrder() throws Exception {
checkSheetName(sheet, "city");
checkFirstDataRow(sheet, firstDataRow);
checkHeaderOrder(sheet, header);
+ tmpFolder.delete();
}
/**
@@ -123,7 +133,6 @@ public void testWriteSimpleSchemaColOrder() throws Exception {
*/
@Test
public void testWriteComplexSchema() throws Exception {
-
TransformationExample example = TransformationExamples
.getExample(TransformationExamples.SIMPLE_COMPLEX);
// alternative the data could be generated by iterating through the
@@ -139,10 +148,17 @@ public void testWriteComplexSchema() throws Exception {
.getContentType("eu.esdihumboldt.hale.io.xls.xls");
writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(true));
writer.setParameter(InstanceTableIOConstants.USE_SCHEMA, Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES,
+ Value.of(true));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of("person"));
File tmpFile = tmpFolder.newFile("excelTestWriteComplexSchema.xls");
writer.setInstances(example.getSourceInstances());
+ Schema schema = XLSInstanceWriterTestUtil.createExampleSchema();
+ DefaultSchemaSpace ss = new DefaultSchemaSpace();
+ ss.addSchema(schema);
+ writer.setTargetSchema(ss);
// write instances to a temporary XLS file
writer.setTarget(new FileIOSupplier(tmpFile));
writer.setContentType(contentType);
@@ -157,10 +173,9 @@ public void testWriteComplexSchema() throws Exception {
Sheet sheet = wb.getSheetAt(0);
checkHeader(sheet, header);
-
checkSheetName(sheet, "person");
-
checkFirstDataRow(sheet, firstDataRow);
+ tmpFolder.delete();
}
/**
@@ -172,7 +187,6 @@ public void testWriteComplexSchema() throws Exception {
*/
@Test
public void testWriteNotNestedProperties() throws Exception {
-
TransformationExample example = TransformationExamples
.getExample(TransformationExamples.SIMPLE_COMPLEX);
// alternative the data could be generated by iterating through the
@@ -186,10 +200,17 @@ public void testWriteNotNestedProperties() throws Exception {
.getContentType("eu.esdihumboldt.hale.io.xls.xls");
writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(false));
writer.setParameter(InstanceTableIOConstants.USE_SCHEMA, Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES,
+ Value.of(true));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of("person"));
File tmpFile = tmpFolder.newFile("excelNotNestedProperties.xls");
writer.setInstances(example.getSourceInstances());
+ Schema schema = XLSInstanceWriterTestUtil.createExampleSchema();
+ DefaultSchemaSpace ss = new DefaultSchemaSpace();
+ ss.addSchema(schema);
+ writer.setTargetSchema(ss);
// write instances to a temporary XLS file
writer.setTarget(new FileIOSupplier(tmpFile));
writer.setContentType(contentType);
@@ -205,8 +226,61 @@ public void testWriteNotNestedProperties() throws Exception {
checkHeader(sheet, header);
checkSheetName(sheet, "person");
-
checkFirstDataRow(sheet, firstDataRow);
+ tmpFolder.delete();
+ }
+
+ /**
+ * Test - write data for 2 example and create a common excel with multiple
+ * sheets
+ *
+ * @throws Exception , if an error occurs
+ */
+ @Test
+ public void testExportMultiFeatureToExcel() throws Exception {
+ ArrayList examples = new ArrayList<>();
+ TransformationExample example = TransformationExamples
+ .getExample(TransformationExamples.SIMPLE_COMPLEX);
+ TransformationExample example2 = TransformationExamples
+ .getExample(TransformationExamples.CARDINALITY_MERGE_1);
+ examples.add(example.getTargetInstances());
+ examples.add(example2.getTargetInstances());
+
+ // set instances to xls instance writer
+ XLSInstanceWriter writer = new XLSInstanceWriter();
+ IContentType contentType = HalePlatform.getContentTypeManager()
+ .getContentType("eu.esdihumboldt.hale.io.xls.xls");
+ writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.USE_SCHEMA, Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES,
+ Value.of(false));
+ writer.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of("person" + "," + "t1"));
+
+ File tmpFile = tmpFolder.newFile("excelWith2Sheets.xls");
+ // write instances to a temporary XLS file
+ writer.setTarget(new FileIOSupplier(tmpFile));
+ writer.setContentType(contentType);
+
+ Schema schema = XLSInstanceWriterTestUtil.createExampleSchema();
+ DefaultSchemaSpace ss = new DefaultSchemaSpace();
+ ss.addSchema(schema);
+ writer.setTargetSchema(ss);
+
+ InstanceCollection multiInstanceCollection = new MultiInstanceCollection(examples);
+ writer.setInstances(multiInstanceCollection);
+
+ IOReport report = writer.execute(null);
+ assertTrue(report.isSuccess());
+
+ Workbook wb;
+// https: // poi.apache.org/components/spreadsheet/quick-guide.html#FileInputStream
+ try (POIFSFileSystem fs = new POIFSFileSystem(tmpFile)) {
+ wb = new HSSFWorkbook(fs.getRoot(), true);
+ }
+ int sheetNumber = wb.getNumberOfSheets();
+ Sheet sheet = wb.getSheetAt(0);
+ assertEquals(1, sheetNumber);
+ tmpFolder.delete();
}
/**
diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/META-INF/MANIFEST.MF b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/META-INF/MANIFEST.MF
index 40e572fcee..0dae5efbab 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/META-INF/MANIFEST.MF
+++ b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/META-INF/MANIFEST.MF
@@ -5,7 +5,8 @@ Bundle-SymbolicName: eu.esdihumboldt.hale.io.xls.ui;singleton:=true
Bundle-Version: 5.1.0.qualifier
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
- eu.esdihumboldt.hale.ui
+ eu.esdihumboldt.hale.ui,
+ eu.esdihumboldt.hale.common.instance
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: de.fhg.igd.eclipse.util.extension,
de.fhg.igd.slf4jplus,
@@ -13,7 +14,10 @@ Import-Package: de.fhg.igd.eclipse.util.extension,
eu.esdihumboldt.hale.common.core.io.project.model,
eu.esdihumboldt.hale.common.core.io.supplier,
eu.esdihumboldt.hale.common.instance.io,
+ eu.esdihumboldt.hale.common.schema,
eu.esdihumboldt.hale.common.schema.io,
+ eu.esdihumboldt.hale.common.schema.model,
+ eu.esdihumboldt.hale.common.schema.model.constraint.type,
eu.esdihumboldt.hale.io.csv,
eu.esdihumboldt.hale.io.csv.ui,
eu.esdihumboldt.hale.io.xls,
diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml
index 6db1bee218..eac0b88b13 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml
+++ b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/plugin.xml
@@ -18,7 +18,7 @@
diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceExportConfigurationPage.java b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceExportConfigurationPage.java
new file mode 100644
index 0000000000..c236a7c263
--- /dev/null
+++ b/io/plugins/eu.esdihumboldt.hale.io.xls.ui/src/eu/esdihumboldt/hale/io/xls/ui/XLSInstanceExportConfigurationPage.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2023 wetransform GmbH
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution. If not, see .
+ *
+ * Contributors:
+ * wetransform GmbH
+ */
+
+package eu.esdihumboldt.hale.io.xls.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.PlatformUI;
+
+import eu.esdihumboldt.hale.common.core.io.Value;
+import eu.esdihumboldt.hale.common.instance.io.InstanceWriter;
+import eu.esdihumboldt.hale.common.schema.model.TypeDefinition;
+import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants;
+import eu.esdihumboldt.hale.io.csv.ui.CommonInstanceExportConfigurationPage;
+
+/**
+ * Configuration page for exporting Excel
+ *
+ * @author Emanuela Epure
+ */
+public class XLSInstanceExportConfigurationPage extends CommonInstanceExportConfigurationPage {
+
+ private CheckboxTableViewer featureTypeTable;
+ private Button selectAll = null;
+ private Button ignoreEmptyFeaturetypes = null;
+ private Group chooseFeatureTypes;
+ private Table table;
+
+ /**
+ *
+ */
+ public XLSInstanceExportConfigurationPage() {
+ super("xlsInstanceExport.configPage");
+ setTitle("Additonal Export Options");
+ setDescription("Select if nested properties should be solved and a type");
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.io.csv.ui.InstanceExportConfigurationPage#createContent(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createContent(Composite page) {
+ super.createContent(page);
+
+ GridDataFactory groupData = GridDataFactory.fillDefaults().grab(true, false);
+ chooseFeatureTypes = new Group(page, SWT.NONE);
+ chooseFeatureTypes.setLayout(new GridLayout(1, false));
+ chooseFeatureTypes.setText("Choose your Type you want to export");
+ groupData.applyTo(chooseFeatureTypes);
+
+ page.pack();
+
+ // wait for selected type
+ setPageComplete(false);
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.io.csv.ui.InstanceExportConfigurationPage#onShowPage(boolean)
+ */
+ @Override
+ protected void onShowPage(boolean firstShow) {
+ if (firstShow) {
+
+ ignoreEmptyFeaturetypes = new Button(chooseFeatureTypes, SWT.CHECK);
+ ignoreEmptyFeaturetypes.setText("Ignore feature types without data");
+ ignoreEmptyFeaturetypes
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+
+ ignoreEmptyFeaturetypes.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ }
+ });
+ ignoreEmptyFeaturetypes.setSelection(false);
+
+ selectAll = new Button(chooseFeatureTypes, SWT.CHECK);
+ selectAll.setText("Select all");
+ selectAll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+
+ selectAll.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ featureTypeTable.setAllChecked(((Button) e.getSource()).getSelection());
+ page.layout();
+ page.pack();
+ setPageComplete(validate());
+ }
+ });
+
+ table = new Table(chooseFeatureTypes, SWT.CHECK | SWT.MULTI | SWT.SCROLL_PAGE);
+ table.setHeaderVisible(false);
+ table.setLinesVisible(false);
+ table.setBackground(PlatformUI.getWorkbench().getDisplay()
+ .getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ GridDataFactory groupData = GridDataFactory.fillDefaults().grab(true, false);
+ groupData.applyTo(table);
+
+ featureTypeTable = new CheckboxTableViewer(table);
+ featureTypeTable.setLabelProvider(new LabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ return ((TypeDefinition) element).getDisplayName();
+ }
+
+ });
+ featureTypeTable.setContentProvider(ArrayContentProvider.getInstance());
+
+ Collection extends TypeDefinition> relevantTypes = getWizard().getProvider()
+ .getTargetSchema().getMappingRelevantTypes();
+
+ ArrayList tableContent = new ArrayList<>();
+ for (TypeDefinition typeDefinition : relevantTypes) {
+ tableContent.add(typeDefinition.getName());
+ }
+
+ featureTypeTable.setInput(relevantTypes);
+ featureTypeTable.addCheckStateListener(new ICheckStateListener() {
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ page.layout();
+ page.pack();
+ setPageComplete(validate());
+ }
+ });
+
+ page.layout();
+ page.pack();
+ }
+ }
+
+ private boolean validate() {
+ return (featureTypeTable.getCheckedElements().length > 0);
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.io.csv.ui.InstanceExportConfigurationPage#updateConfiguration(eu.esdihumboldt.hale.common.instance.io.InstanceWriter)
+ */
+ @Override
+ public boolean updateConfiguration(InstanceWriter provider) {
+ super.updateConfiguration(provider);
+
+ provider.setParameter(InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES,
+ Value.of(ignoreEmptyFeaturetypes.getSelection()));
+
+ Object[] elements = featureTypeTable.getCheckedElements();
+ String param = "";
+ for (Object el : elements) {
+ param = param + ((TypeDefinition) el).getName().toString() + ",";
+ }
+ provider.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of(param));
+
+ return true;
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage#enable()
+ */
+ @Override
+ public void enable() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage#disable()
+ */
+ @Override
+ public void disable() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls/plugin.xml b/io/plugins/eu.esdihumboldt.hale.io.xls/plugin.xml
index 8b93504b6e..21ede0dab9 100644
--- a/io/plugins/eu.esdihumboldt.hale.io.xls/plugin.xml
+++ b/io/plugins/eu.esdihumboldt.hale.io.xls/plugin.xml
@@ -92,6 +92,7 @@
+
+
+
+
+
+
0) {
+ workbook.removeSheetAt(0);
+ }
+ }
+
+ cellStyle = XLSCellStyles.getNormalStyle(workbook, false);
+ headerStyle = XLSCellStyles.getHeaderStyle(workbook);
+
+ String exportType = getParameter(InstanceTableIOConstants.EXPORT_TYPE).as(String.class);
+ ArrayList selectedFeatureTypes = new ArrayList<>();
+
+ if (exportType != null) {
+ String[] splitExportType = exportType.split(",");
+ for (String featureType : splitExportType) {
+
+ selectedFeatureTypes.add(QName.valueOf(featureType));
+ }
+
+ for (QName selectedTypeName : selectedFeatureTypes) {
+ // get all instances of the selected Type
+ InstanceCollection instances = getInstanceCollection(selectedTypeName);
+ addSheetByQName(solveNestedProperties, ignoreEmptyFeaturetypes, selectedTypeName,
+ instances);
+ }
+ }
+
+ try (FileOutputStream out = new FileOutputStream(getTarget().getLocation().getPath());) {
+ workbook.write(out);
+ }
- // get all instances of the selected Type
- InstanceCollection instances = getInstanceCollection(selectedTypeName);
- // use ResourceIterator in a try block because is closable -
+ reporter.setSuccess(true);
+ return reporter;
+ } // close try-iterator
+
+ /**
+ * @param solveNestedProperties : Solve nested properties
+ * @param ignoreEmptyFeaturetypes don't add empty feature types to excel
+ * @param selectedTypeName selected feature type
+ * @param instances InstanceCollection available
+ */
+ private void addSheetByQName(boolean solveNestedProperties, boolean ignoreEmptyFeaturetypes,
+ QName selectedTypeName, InstanceCollection instances) {
+
+ // use ResourceIterator in a try block because is closable
+ // -
// avoid infinite
// cleaning project after exporting data
try (ResourceIterator instanceIterator = instances.iterator();) {
@@ -107,53 +145,52 @@ else if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xlsx")) {
try {
instance = instanceIterator.next();
} catch (NoSuchElementException e) {
- reporter.error(
- new IOMessageImpl("There are no instances for the selected type.", e));
- return reporter;
+ if (!ignoreEmptyFeaturetypes) {
+ Sheet sheet = workbook.createSheet(selectedTypeName.getLocalPart());
+ sheet.createRow(0);
+ resizeSheet(sheet);
+ }
+ return;
}
- List remainingInstances = new ArrayList();
-
headerRowStrings = new ArrayList();
boolean useSchema = getParameter(InstanceTableIOConstants.USE_SCHEMA).as(Boolean.class,
true);
- // all instances with equal type definitions are stored in an extra
+ // all instances with equal type definitions are stored in an
+ // extra
// sheet
TypeDefinition definition = instance.getDefinition();
- Sheet sheet = wb.createSheet(definition.getDisplayName());
- Row headerRow = sheet.createRow(0);
- int rowNum = 1;
- Row row = sheet.createRow(rowNum++);
- writeRow(row, super.getPropertyMap(instance, headerRowStrings, useSchema,
- solveNestedProperties));
-
- while (instanceIterator.hasNext()) {
- Instance nextInst = instanceIterator.next();
- if (nextInst.getDefinition().equals(definition)) {
- row = sheet.createRow(rowNum++);
- writeRow(row, super.getPropertyMap(nextInst, headerRowStrings, useSchema,
- solveNestedProperties));
+ Sheet sheet;
+ try {
+ sheet = workbook.createSheet(definition.getDisplayName());
+
+ Row headerRow = sheet.createRow(0);
+ int rowNum = 1;
+ Row row = sheet.createRow(rowNum++);
+ writeRow(row, super.getPropertyMap(instance, headerRowStrings, useSchema,
+ solveNestedProperties));
+
+ while (instanceIterator.hasNext()) {
+ Instance nextInst = instanceIterator.next();
+ if (nextInst.getDefinition().equals(definition)) {
+ row = sheet.createRow(rowNum++);
+ writeRow(row, super.getPropertyMap(nextInst, headerRowStrings, useSchema,
+ solveNestedProperties));
+ }
}
- else
- remainingInstances.add(nextInst);
- }
- writeHeaderRow(headerRow, headerRowStrings);
- setCellStyle(sheet, headerRowStrings.size());
- resizeSheet(sheet);
-
- // write file and be sure to close resource with try-block
- try (FileOutputStream out = new FileOutputStream(
- getTarget().getLocation().getPath());) {
- wb.write(out);
+
+ writeHeaderRow(headerRow, headerRowStrings);
+ setCellStyle(sheet, headerRowStrings.size());
+ resizeSheet(sheet);
+ } catch (Exception e) {
+ return;
}
- reporter.setSuccess(true);
- return reporter;
}
- } // close try-iterator
+ }
@Override
public boolean isPassthrough() {