diff --git a/io/features/eu.esdihumboldt.hale.io.feature.core.ui/feature.xml b/io/features/eu.esdihumboldt.hale.io.feature.core.ui/feature.xml index f13f749971..9fa91c523b 100644 --- a/io/features/eu.esdihumboldt.hale.io.feature.core.ui/feature.xml +++ b/io/features/eu.esdihumboldt.hale.io.feature.core.ui/feature.xml @@ -100,4 +100,11 @@ version="0.0.0" unpack="false"/> + + diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/.classpath b/io/plugins/eu.esdihumboldt.hale.io.json.ui/.classpath new file mode 100644 index 0000000000..81fe078c20 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/.project b/io/plugins/eu.esdihumboldt.hale.io.json.ui/.project new file mode 100644 index 0000000000..f51a88c17d --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/.project @@ -0,0 +1,28 @@ + + + eu.esdihumboldt.hale.io.json.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/.settings/org.eclipse.jdt.core.prefs b/io/plugins/eu.esdihumboldt.hale.io.json.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..62ef3488cc --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/META-INF/MANIFEST.MF b/io/plugins/eu.esdihumboldt.hale.io.json.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..adfc92786c --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/build.properties b/io/plugins/eu.esdihumboldt.hale.io.json.ui/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/plugin.xml b/io/plugins/eu.esdihumboldt.hale.io.json.ui/plugin.xml new file mode 100644 index 0000000000..15d90b0631 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/plugin.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/io/plugins/eu.esdihumboldt.hale.io.json.ui/src/eu/esdihumboldt/hale/io/json/ui/TypeSelectionPage.java b/io/plugins/eu.esdihumboldt.hale.io.json.ui/src/eu/esdihumboldt/hale/io/json/ui/TypeSelectionPage.java new file mode 100644 index 0000000000..6310492854 --- /dev/null +++ b/io/plugins/eu.esdihumboldt.hale.io.json.ui/src/eu/esdihumboldt/hale/io/json/ui/TypeSelectionPage.java @@ -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 . + * + * Contributors: + * wetransform GmbH + */ + +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; + } + +} diff --git a/io/plugins/eu.esdihumboldt.hale.io.json/src/eu/esdihumboldt/hale/io/json/internal/JsonReadMode.java b/io/plugins/eu.esdihumboldt.hale.io.json/src/eu/esdihumboldt/hale/io/json/internal/JsonReadMode.java index 5a7a61e475..74662de743 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.json/src/eu/esdihumboldt/hale/io/json/internal/JsonReadMode.java +++ b/io/plugins/eu.esdihumboldt.hale.io.json/src/eu/esdihumboldt/hale/io/json/internal/JsonReadMode.java @@ -45,4 +45,11 @@ private JsonReadMode(String label) { this.label = label; } + /** + * @return the label + */ + public String getLabel() { + return label; + } + }