Skip to content

Commit

Permalink
feat: update CSV ViewerFilter and remove unused method in the XLS
Browse files Browse the repository at this point in the history
Update CSV InstanceExportConfigurationPage with the same approach used by XLS for finding which feature types has data or not.
Remove unused method from XLSInstanceExportConfigurationPage

ING-3987
  • Loading branch information
emanuelaepure10 committed Aug 22, 2023
1 parent 6e9dafe commit 47059a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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;
Expand All @@ -29,7 +31,6 @@
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 @@ -50,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 @@ -115,7 +121,8 @@ protected void createContent(Composite page) {
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);
Color greyLabel = PlatformUI.getWorkbench().getDisplay()
.getSystemColor(SWT.COLOR_DARK_GRAY);
separatorLabel.setForeground(greyLabel);

page.pack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@

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

import java.util.NoSuchElementException;
import java.util.Set;

import javax.xml.namespace.QName;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
Expand All @@ -43,9 +40,6 @@
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;
Expand Down Expand Up @@ -241,31 +235,4 @@ 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;
}

}

0 comments on commit 47059a1

Please sign in to comment.