Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: type selection broken on custom export config #1052

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@

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

import java.util.Set;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
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;

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.TypeFilter;
import eu.esdihumboldt.hale.common.schema.model.TypeDefinition;
import eu.esdihumboldt.hale.io.csv.InstanceTableIOConstants;
import eu.esdihumboldt.hale.ui.common.definition.selector.TypeDefinitionSelector;
Expand All @@ -49,17 +51,22 @@ public class InstanceExportConfigurationPage extends CommonInstanceExportConfigu
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (!(element instanceof TypeDefinition))
return false;
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()) {

InstanceService instanceService = PlatformUI.getWorkbench()
.getService(InstanceService.class);

Set<TypeDefinition> instanceSourceTypes = instanceService
.getInstanceTypes(DataSet.SOURCE);
if (instanceSourceTypes.contains(element)) {
return true;
}
// select all type which has at least one transformed instance
if (!ins.getInstances(DataSet.TRANSFORMED)
.select(new TypeFilter((TypeDefinition) element)).isEmpty()) {

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

return false;
}
};
Expand Down Expand Up @@ -110,6 +117,14 @@ 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 +147,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,33 +15,35 @@

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

import java.util.ArrayList;
import java.util.Collection;

import javax.xml.namespace.QName;
import java.util.Set;

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.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.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 +54,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 +92,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 +107,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 +134,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 +207,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
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