Skip to content

Commit

Permalink
feat: update header, when to create the content in the TypeSelectionPage
Browse files Browse the repository at this point in the history
Remove unnecessary files.
Update TypeSelection by creating the elements in the createContent method, update header.

ING-3128
  • Loading branch information
emanuelaepure10 committed Aug 22, 2023
1 parent 9ffbafd commit de11a2c
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 187 deletions.
7 changes: 0 additions & 7 deletions io/plugins/MANIFEST.MF

This file was deleted.

14 changes: 8 additions & 6 deletions io/plugins/eu.esdihumboldt.hale.io.json.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ui
Bundle-Name: JSON Schema/Instance I/O UI
Bundle-SymbolicName: eu.esdihumboldt.hale.io.json.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.ui;bundle-version="3.7.0",
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
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.google.common.io;version="9.0.0",
eu.esdihumboldt.hale.common.core.io,
eu.esdihumboldt.hale.common.core.io.impl,
Expand All @@ -25,4 +25,6 @@ Import-Package: com.google.common.io;version="9.0.0",
eu.esdihumboldt.hale.ui.util.io,
eu.esdihumboldt.hale.ui.util.selector,
eu.esdihumboldt.util
Automatic-Module-Name: eu.esdihumboldt.hale.io.json.ui.singleton.true
Export-Package: eu.esdihumboldt.hale.io.json.ui
Bundle-Vendor: data harmonisation panel
Automatic-Module-Name: eu.esdihumboldt.hale.io.json.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
* 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
Expand All @@ -10,12 +10,15 @@
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
* 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;
Expand All @@ -24,7 +27,6 @@
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
Expand All @@ -40,10 +42,11 @@

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.ui.util.EnumJSONAutoOrderTypes;
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;
Expand Down Expand Up @@ -91,117 +94,15 @@ public void disable() {
// do nothing
}

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

page.setLayout(new GridLayout(2, false));
GridData layoutData = new GridData();
layoutData.widthHint = 200;

if (firstShow) {

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 EnumJSONAutoOrderTypes) {
return ((EnumJSONAutoOrderTypes) element).getJsonModeOrder();
}
return super.getText(element);
}

});
readModeOrderCombo.setInput(EnumJSONAutoOrderTypes.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:");

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) {
TypeDefinition selectedObject = selectorFeatureTypes.getSelectedObject();
if (selectedObject == null) {
forceUsageOfDefaultSelectedType.setSelection(false);
} else {
forceUsageOfDefaultSelectedType.setSelection(true);

setTypeLabel.getParent().layout();
}
validateSelection();
selectorFeatureTypes.getControl().requestLayout();
}
});

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

setDefaultOptions();
setPageComplete(false);
}

/**
* 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);
}
Expand Down Expand Up @@ -238,20 +139,117 @@ protected void validateSelection() {
@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) {
provider.setParameter(JsonInstanceReader.PARAM_READ_MODE, Value.of(readModeOrderCombo.getSelection()));
jsonInstanceReader.setReadMode((JsonReadMode)readModeOrderCombo.getElementAt(0));
}
provider.setParameter(JsonInstanceReader.PARAM_FORCE_DEFAULT_TYPE,
Value.of(forceUsageOfDefaultSelectedType.getSelection()));

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.
Expand All @@ -260,7 +258,7 @@ public boolean updateConfiguration(InstanceReader provider) {
&& selectorFeatureTypes.getSelectedObject() != null)) {
if (selectorFeatureTypes.getSelectedObject() != null) {
QName name = selectorFeatureTypes.getSelectedObject().getName();
provider.setParameter(JsonInstanceReader.PARAM_FORCE_DEFAULT_TYPE, Value.of(name.toString()));
jsonInstanceReader.setDefaultType(name);
}
} else {
return false;
Expand Down

This file was deleted.

Loading

0 comments on commit de11a2c

Please sign in to comment.