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: GeoJSON/JSON wizard additional settings page #1054

Merged
merged 3 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 @@ -100,4 +100,11 @@
version="0.0.0"
unpack="false"/>

<plugin
id="eu.esdihumboldt.hale.io.json.ui"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
7 changes: 7 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.json.ui/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.json.ui/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>eu.esdihumboldt.hale.io.json.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
30 changes: 30 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.json.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JSON Schema/Instance I/O UI
Bundle-SymbolicName: eu.esdihumboldt.hale.io.json.ui;singleton:=true
Bundle-Version: 5.1.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.6.0",
org.eclipse.ui;bundle-version="3.6.2",
eu.esdihumboldt.hale.io.json;bundle-version="5.1.0",
eu.esdihumboldt.hale.ui.util
Import-Package: com.google.common.io;version="9.0.0",
eu.esdihumboldt.hale.common.core.io,
eu.esdihumboldt.hale.common.core.io.impl,
eu.esdihumboldt.hale.common.core.io.supplier,
eu.esdihumboldt.hale.common.instance.io,
eu.esdihumboldt.hale.common.schema,
eu.esdihumboldt.hale.common.schema.model,
eu.esdihumboldt.hale.common.schema.persist,
eu.esdihumboldt.hale.ui,
eu.esdihumboldt.hale.ui.common.definition.selector,
eu.esdihumboldt.hale.ui.io,
eu.esdihumboldt.hale.ui.io.config,
eu.esdihumboldt.hale.ui.io.instance,
eu.esdihumboldt.hale.ui.service.schema,
eu.esdihumboldt.hale.ui.util.io,
eu.esdihumboldt.hale.ui.util.selector,
eu.esdihumboldt.util
Export-Package: eu.esdihumboldt.hale.io.json.ui
Bundle-Vendor: data harmonisation panel
Automatic-Module-Name: eu.esdihumboldt.hale.io.json.ui
4 changes: 4 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.json.ui/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
15 changes: 15 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.json.ui/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="eu.esdihumboldt.hale.ui.io.config">
<configPage
class="eu.esdihumboldt.hale.io.json.ui.TypeSelectionPage"
order="0">
<provider
ref="eu.esdihumboldt.hale.io.json.reader">
</provider>
</configPage>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
/*
* Copyright (c) 2021 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 <http://www.gnu.org/licenses/>.
*
* Contributors:
emanuelaepure10 marked this conversation as resolved.
Show resolved Hide resolved
* wetransform GmbH <http://www.wetransform.to>
*/

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

import java.io.InputStream;
import java.net.URI;
import java.util.List;

import javax.xml.namespace.QName;

import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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 eu.esdihumboldt.hale.common.core.io.IOProvider;
import eu.esdihumboldt.hale.common.core.io.Value;
import eu.esdihumboldt.hale.common.core.io.supplier.LocatableInputSupplier;
import eu.esdihumboldt.hale.common.instance.io.InstanceReader;
import eu.esdihumboldt.hale.common.schema.model.TypeDefinition;
import eu.esdihumboldt.hale.io.json.JsonInstanceReader;
import eu.esdihumboldt.hale.io.json.internal.JsonReadMode;
import eu.esdihumboldt.hale.ui.HaleWizardPage;
import eu.esdihumboldt.hale.ui.common.definition.selector.TypeDefinitionSelector;
import eu.esdihumboldt.hale.ui.io.IOWizardPage;
import eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage;
import eu.esdihumboldt.hale.ui.io.instance.InstanceReaderConfigurationPage;
import eu.esdihumboldt.hale.ui.util.viewer.EnumContentProvider;

/**
* Configuration page for selecting the feature type for GeoJSON/JSON instances.
*
* @author Emanuela Epure
*/
@SuppressWarnings("restriction")
public class TypeSelectionPage extends InstanceReaderConfigurationPage {

private Composite page;
private Button forceUsageOfDefaultSelectedType;
private TypeDefinitionSelector selectorFeatureTypes;
private ComboViewer readModeOrderCombo;
private Label setTypeLabel;

/**
* default constructor
*/
public TypeSelectionPage() {
super("selectType");

setTitle("Feature type");
setDescription("Select the Feature types matching your data.");
}

/**
* @see AbstractConfigurationPage#enable()
*/
@Override
public void enable() {
// nothing
}

/**
* @see AbstractConfigurationPage#disable()
*/
@Override
public void disable() {
// do nothing
}

/**
* Set default options to the checkbox based on if the user navigated from
* single file import or multiple file import.
*/
private void setDefaultOptions() {
// Set the selection to the first element
final ISelection defaultValue = new StructuredSelection(JsonReadMode.auto);
readModeOrderCombo.setSelection(defaultValue);

forceUsageOfDefaultSelectedType.setSelection(false);
selectorFeatureTypes.setSelection(StructuredSelection.EMPTY);
}

/**
* Validate the current selection. {@link #onShowPage(boolean)} must have been
* called first to set {@link #lastType}.
*/
protected void validateSelection() {
TypeDefinition selected = selectorFeatureTypes.getSelectedObject();
ISelection readModeOrderComboSelection = readModeOrderCombo.getSelection();
boolean forceSelection = forceUsageOfDefaultSelectedType.getSelection();

if (!readModeOrderComboSelection.isEmpty()) {
if ((selected != null && forceSelection) || (selected == null && !forceSelection)) {
setPageComplete(true);
setMessage("All the types will be mapped automatically to the selected feature types",
DialogPage.INFORMATION);
} else {
setPageComplete(false);
setMessage("Select one feature type", DialogPage.INFORMATION);
}
} else {
setPageComplete(false);
setMessage("Select the most appropriate read mode", DialogPage.INFORMATION);
}

return;
}

/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
this.page = page;
page.setLayout(new GridLayout(2, false));
GridData layoutData = new GridData();
layoutData.widthHint = 200;

Group autodetectOrderGroup = new Group(page, SWT.NONE);
autodetectOrderGroup.setText("Choose the most appropriate read mode:");
GridLayoutFactory.swtDefaults().numColumns(1).applyTo(autodetectOrderGroup);
GridDataFactory.fillDefaults().grab(true, false).applyTo(autodetectOrderGroup);

readModeOrderCombo = new ComboViewer(autodetectOrderGroup);
GridDataFactory.fillDefaults().grab(true, false).applyTo(readModeOrderCombo.getControl());
readModeOrderCombo.setContentProvider(EnumContentProvider.getInstance());
readModeOrderCombo.setLabelProvider(new LabelProvider() {

@Override
public String getText(Object element) {
if (element instanceof JsonReadMode) {
return ((JsonReadMode) element).getLabel();
}
return super.getText(element);
}

});
readModeOrderCombo.setInput(JsonReadMode.class);
readModeOrderCombo.addSelectionChangedListener(new ISelectionChangedListener() {

@Override
public void selectionChanged(SelectionChangedEvent event) {
validateSelection();
}
});

// add some space
new Label(page, SWT.NONE);
new Label(page, SWT.NONE);

forceUsageOfDefaultSelectedType = new Button(page, SWT.CHECK);
forceUsageOfDefaultSelectedType
.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).span(2, 1).create());
forceUsageOfDefaultSelectedType.setText("Force usage of the default type to be used for all instances");

forceUsageOfDefaultSelectedType.addSelectionListener(new SelectionListener() {

@Override
public void widgetSelected(SelectionEvent e) {
if (!forceUsageOfDefaultSelectedType.getSelection()) {
setMessage("All the types will be mapped automatically to the selected feature type.",
DialogPage.INFORMATION);
selectorFeatureTypes.setSelection(StructuredSelection.EMPTY);
}
// reload the selector as sometimes in Mac it doesn't
// reflect the change.
selectorFeatureTypes.getControl().requestLayout();
validateSelection();
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
// default selection is false.
selectorFeatureTypes.getControl().setEnabled(true);

}
});

setTypeLabel = new Label(page, SWT.NONE);
setTypeLabel.setText("Feature type:");

page.layout();
page.pack();

setPageComplete(false);
}

/**
* @see HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
super.onShowPage(firstShow);

if (firstShow) {
selectorFeatureTypes = new TypeDefinitionSelector(page, "Select the corresponding feature type",
getWizard().getProvider().getSourceSchema(), null);
selectorFeatureTypes.getControl()
.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

selectorFeatureTypes.addSelectionChangedListener(new ISelectionChangedListener() {

@Override
public void selectionChanged(SelectionChangedEvent event) {
validateSelection();
selectorFeatureTypes.getControl().requestLayout();
}
});

setDefaultOptions();
}
}

/**
* @see IOWizardPage#updateConfiguration(IOProvider)
*/
@Override
public boolean updateConfiguration(InstanceReader provider) {
JsonInstanceReader jsonInstanceReader = (JsonInstanceReader) provider;

if (readModeOrderCombo.getSelection() != null) {
jsonInstanceReader.setReadMode((JsonReadMode)readModeOrderCombo.getElementAt(0));
}

jsonInstanceReader.setForceDefaultType(forceUsageOfDefaultSelectedType.getSelection());

// make sure if the selection box is empty and autoDetect is not checked
// then the user should be able to finish the wizard.
if ((!forceUsageOfDefaultSelectedType.getSelection() && selectorFeatureTypes.getSelectedObject() == null)
|| (forceUsageOfDefaultSelectedType.getSelection()
&& selectorFeatureTypes.getSelectedObject() != null)) {
if (selectorFeatureTypes.getSelectedObject() != null) {
QName name = selectorFeatureTypes.getSelectedObject().getName();
jsonInstanceReader.setDefaultType(name);
}
} else {
return false;
}

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ private JsonReadMode(String label) {
this.label = label;
}

/**
* @return the label
*/
public String getLabel() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Label is a public property, so you could have just accessed it directly.

return label;
}

}