Skip to content

Commit

Permalink
feat: type selection broken on custom export config
Browse files Browse the repository at this point in the history
CSV: Add a warning label to CSV dialog telling that feature types without data are not selectable.
XSL: remove the button "Ignore feature types without data" and add intro the checkbox table disabled from selection elements that don't have any data for export.

ING-3987
  • Loading branch information
emanuelaepure10 committed Aug 18, 2023
1 parent 019cb4e commit bb6c66e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 greyLabel = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
separatorLabel.setForeground(greyLabel);

page.pack();

// wait for selected type
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package eu.esdihumboldt.hale.io.xls.ui;

import java.util.ArrayList;
import java.util.Collection;
import java.util.NoSuchElementException;
import java.util.Set;

import javax.xml.namespace.QName;

Expand All @@ -25,23 +25,31 @@
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.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
Expand All @@ -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;

Expand Down Expand Up @@ -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));
Expand All @@ -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 greyLabel = PlatformUI.getWorkbench().getDisplay()
.getSystemColor(SWT.COLOR_DARK_GRAY);
separatorLabel.setForeground(greyLabel);

table = new Table(chooseFeatureTypes, SWT.CHECK | SWT.MULTI | SWT.SCROLL_PAGE);
table.setHeaderVisible(false);
table.setLinesVisible(false);
Expand All @@ -138,25 +140,63 @@ public String getText(Object element) {
});
featureTypeTable.setContentProvider(ArrayContentProvider.getInstance());

Collection<? extends TypeDefinition> relevantTypes = getWizard().getProvider()
.getTargetSchema().getMappingRelevantTypes();

ArrayList<QName> 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 instanceService = PlatformUI.getWorkbench()
.getService(InstanceService.class);

Set<TypeDefinition> instanceSourceTypes = instanceService
.getInstanceTypes(DataSet.SOURCE);
if (instanceSourceTypes.contains(element)) {
return false;
}

Set<TypeDefinition> instanceTransformedTypes = instanceService
.getInstanceTypes(DataSet.TRANSFORMED);
if (instanceTransformedTypes.contains(element)) {
return false;
}
return true;
}
});

page.layout();
page.pack();
}
Expand All @@ -173,9 +213,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) {
Expand Down Expand Up @@ -204,4 +241,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<Instance> instanceIterator = instances.iterator();) {
Instance instance = null;
try {
instance = instanceIterator.next();
Iterable<QName> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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<Instance> in a try block because is closable
// -
Expand All @@ -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;
}

Expand Down

0 comments on commit bb6c66e

Please sign in to comment.