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 a30d08fb84..2dcc6aec0b 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,6 +21,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.PlatformUI; @@ -110,6 +111,13 @@ protected void createContent(Composite page) { final Label label = new Label(page, SWT.NONE); label.setText("Choose your Type you want to export:"); + Label separatorLabel = new Label(page, SWT.NONE); + separatorLabel.setText("Warning! Feature types with no data are not selectable"); + + // Set the text colour of the label to yellow + Color yellow = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); + separatorLabel.setForeground(yellow); + page.pack(); // wait for selected type @@ -132,9 +140,6 @@ protected void onShowPage(boolean firstShow) { public void selectionChanged(SelectionChangedEvent event) { setPageComplete(!(event.getSelection().isEmpty())); if (typeSelector.getSelectedObject() != null) { - // TypeDefinition type = - // typeSelector.getSelectedObject(); - // label.getParent().layout(); page.layout(); page.pack(); } 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 1ebaaa38b0..0b547d15b7 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,9 +45,4 @@ 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 a09d9c9581..bb71444539 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 @@ -60,8 +60,6 @@ public void test() { .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(); 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 2a90b88ce2..ec3db25740 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 @@ -96,8 +96,6 @@ 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"); @@ -148,8 +146,6 @@ 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"); @@ -200,8 +196,6 @@ 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"); @@ -252,8 +246,6 @@ public void testExportMultiFeatureToExcel() 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(false)); writer.setParameter(InstanceTableIOConstants.EXPORT_TYPE, Value.of("person" + "," + "t1")); File tmpFile = tmpFolder.newFile("excelWith2Sheets.xls"); 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 index c236a7c263..371e6779d9 100644 --- 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 @@ -15,8 +15,7 @@ package eu.esdihumboldt.hale.io.xls.ui; -import java.util.ArrayList; -import java.util.Collection; +import java.util.NoSuchElementException; import javax.xml.namespace.QName; @@ -25,23 +24,32 @@ import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ICheckStateProvider; 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.graphics.Color; 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.Label; 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.instance.model.DataSet; +import eu.esdihumboldt.hale.common.instance.model.Instance; +import eu.esdihumboldt.hale.common.instance.model.InstanceCollection; +import eu.esdihumboldt.hale.common.instance.model.ResourceIterator; +import eu.esdihumboldt.hale.common.instance.model.TypeFilter; import eu.esdihumboldt.hale.common.schema.model.TypeDefinition; import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants; import eu.esdihumboldt.hale.io.csv.ui.CommonInstanceExportConfigurationPage; +import eu.esdihumboldt.hale.ui.service.instance.InstanceService; /** * Configuration page for exporting Excel @@ -52,7 +60,6 @@ public class XLSInstanceExportConfigurationPage extends CommonInstanceExportConf private CheckboxTableViewer featureTypeTable; private Button selectAll = null; - private Button ignoreEmptyFeaturetypes = null; private Group chooseFeatureTypes; private Table table; @@ -91,19 +98,6 @@ protected void createContent(Composite page) { 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)); @@ -119,6 +113,14 @@ public void widgetSelected(SelectionEvent e) { } }); + Label separatorLabel = new Label(page, SWT.NONE); + separatorLabel.setText("Warning! Feature types with no data are not selectable"); + + // Set the text colour of the label to yellow + Color yellow = PlatformUI.getWorkbench().getDisplay() + .getSystemColor(SWT.COLOR_DARK_GRAY); + separatorLabel.setForeground(yellow); + table = new Table(chooseFeatureTypes, SWT.CHECK | SWT.MULTI | SWT.SCROLL_PAGE); table.setHeaderVisible(false); table.setLinesVisible(false); @@ -138,25 +140,62 @@ public String getText(Object element) { }); featureTypeTable.setContentProvider(ArrayContentProvider.getInstance()); - Collection relevantTypes = getWizard().getProvider() - .getTargetSchema().getMappingRelevantTypes(); - - ArrayList tableContent = new ArrayList<>(); - for (TypeDefinition typeDefinition : relevantTypes) { - tableContent.add(typeDefinition.getName()); - } + featureTypeTable.setInput( + getWizard().getProvider().getTargetSchema().getMappingRelevantTypes()); - featureTypeTable.setInput(relevantTypes); featureTypeTable.addCheckStateListener(new ICheckStateListener() { @Override public void checkStateChanged(CheckStateChangedEvent event) { + // Programmatic action to toggle the state + selectAll.setSelection( + featureTypeTable.getCheckedElements().length == featureTypeTable + .getTable().getItemCount()); + page.layout(); page.pack(); setPageComplete(validate()); } }); + featureTypeTable.setCheckStateProvider(new ICheckStateProvider() { + + @Override + public boolean isChecked(Object element) { + if (!(element instanceof TypeDefinition)) + return false; + return checkboxState(element); + } + + @Override + public boolean isGrayed(Object element) { + if (!(element instanceof TypeDefinition)) + return false; + return checkboxState(element); + } + + /** + * @param element + * @return true if the button cannot be selected + */ + private boolean checkboxState(Object element) { + InstanceService ins = PlatformUI.getWorkbench() + .getService(InstanceService.class); + // select all source type which has at least one instance + if (!ins.getInstances(DataSet.SOURCE) + .select(new TypeFilter((TypeDefinition) element)).isEmpty()) { + return false; + } + // select all type which has at least one transformed + // instance + if (!ins.getInstances(DataSet.TRANSFORMED) + .select(new TypeFilter((TypeDefinition) element)).isEmpty()) { + return false; + } + return true; + } + }); + page.layout(); page.pack(); } @@ -173,9 +212,6 @@ private boolean validate() { 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) { @@ -204,4 +240,31 @@ public void disable() { } + /** + * @param instances InstanceCollection + * @return boolean true if the instance has at least one properties + */ + protected boolean extractedSelectableTypeDefinition(InstanceCollection instances) { + try (ResourceIterator instanceIterator = instances.iterator();) { + Instance instance = null; + try { + instance = instanceIterator.next(); + Iterable allProperties = instance.getPropertyNames(); + + for (QName qname : allProperties) { + + // get properties of the current instance + Object[] properties = instance.getProperty(qname); + if (properties != null && properties.length != 0) { + return true; + } + } + } catch (NoSuchElementException e) { + return false; + } + + } + return false; + } + } diff --git a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/writer/XLSInstanceWriter.java b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/writer/XLSInstanceWriter.java index 9a5e0b16f7..7189a40eb0 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/writer/XLSInstanceWriter.java +++ b/io/plugins/eu.esdihumboldt.hale.io.xls/src/eu/esdihumboldt/hale/io/xls/writer/XLSInstanceWriter.java @@ -74,9 +74,6 @@ protected IOReport execute(ProgressIndicator progress, IOReporter reporter) boolean solveNestedProperties = getParameter( InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES).as(Boolean.class, false); - boolean ignoreEmptyFeaturetypes = getParameter( - InstanceTableIOConstants.EXPORT_IGNORE_EMPTY_FEATURETYPES).as(Boolean.class, false); - // write xls file if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xls")) { workbook = new HSSFWorkbook(); @@ -114,8 +111,7 @@ else if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xlsx")) { for (QName selectedTypeName : selectedFeatureTypes) { // get all instances of the selected Type InstanceCollection instances = getInstanceCollection(selectedTypeName); - addSheetByQName(solveNestedProperties, ignoreEmptyFeaturetypes, selectedTypeName, - instances); + addSheetByQName(solveNestedProperties, selectedTypeName, instances); } } @@ -124,17 +120,17 @@ else if (getContentType().getId().equals("eu.esdihumboldt.hale.io.xls.xlsx")) { } 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) { + private void addSheetByQName(boolean solveNestedProperties, QName selectedTypeName, + InstanceCollection instances) { // use ResourceIterator in a try block because is closable // - @@ -145,11 +141,6 @@ private void addSheetByQName(boolean solveNestedProperties, boolean ignoreEmptyF try { instance = instanceIterator.next(); } catch (NoSuchElementException e) { - if (!ignoreEmptyFeaturetypes) { - Sheet sheet = workbook.createSheet(selectedTypeName.getLocalPart()); - sheet.createRow(0); - resizeSheet(sheet); - } return; }