use of eu.esdihumboldt.hale.io.csv.PropertyTypeFactory in project hale by halestudio.
the class DefaultSchemaTypePage method update.
/**
* Update all fields (should be called if page is initialized or the
* selection of input (file or table) has been changed
*/
protected void update() {
int length = 0;
// the header is not valid so clear all content
if (header == null || header.length == 0) {
// clear properties
clearPage();
return;
}
if (secondRow == null || secondRow.length == 0) {
secondRow = header;
}
if (header.length != 0) {
length = header.length;
}
// dispose all property names if the read configuration has been changed
if (lastSecondRow != null && !Arrays.equals(header, lastSecondRow)) {
for (TypeNameField properties : fields) {
properties.dispose();
properties.getTextControl(group).dispose();
properties.getLabelControl(group).dispose();
}
for (ComboViewer combViewer : comboFields) {
combViewer.getCombo().dispose();
}
fields.clear();
comboFields.clear();
}
if (!Arrays.equals(header, lastSecondRow)) {
for (int i = 0; i < length; i++) {
final TypeNameField propField;
final ComboViewer cv;
validSel.add(true);
propField = new TypeNameField("properties", Integer.toString(i + 1), group);
fields.add(propField);
propField.setEmptyStringAllowed(false);
propField.setErrorMessage("Please enter a valid Property Name");
propField.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
HashSet<String> hs = new HashSet<String>();
if (event.getProperty().equals(StringFieldEditor.VALUE)) {
for (TypeNameField field : fields) {
if (!hs.add(field.getStringValue())) {
valid = false;
break;
} else {
valid = true;
}
}
}
if (event.getProperty().equals(StringFieldEditor.IS_VALID)) {
isValid = (Boolean) event.getNewValue();
}
setPageComplete(isValid());
}
});
propField.setStringValue(header[i].replace(" ", ""));
cv = new ComboViewer(group);
comboFields.add(cv);
cv.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
int i = comboFields.indexOf(event.getSource());
PropertyTypeFactory actualSelection = ((PropertyTypeFactory) ((IStructuredSelection) cv.getSelection()).getFirstElement());
try {
actualSelection.createExtensionObject().convertFromField(secondRow[i]);
validSel.set(i, true);
} catch (Exception e) {
validSel.set(i, false);
}
if (validSel.contains(false)) {
int j = validSel.indexOf(false) + 1;
setMessage("Your selection in field # " + j + " is not valid!", WARNING);
} else {
setMessage(null);
}
}
});
cv.setContentProvider(ArrayContentProvider.getInstance());
cv.setLabelProvider(new LabelProvider() {
/**
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if (element instanceof PropertyTypeFactory) {
return ((PropertyTypeFactory) element).getDisplayName();
}
return super.getText(element);
}
});
Collection<PropertyTypeFactory> elements = PropertyTypeExtension.getInstance().getFactories();
cv.setInput(elements);
PropertyTypeFactory defaultSelection = PropertyTypeExtension.getInstance().getFactory("java.lang.String");
if (defaultSelection != null) {
cv.setSelection(new StructuredSelection(defaultSelection));
} else if (!elements.isEmpty()) {
cv.setSelection(new StructuredSelection(elements.iterator().next()));
}
}
}
group.setLayout(new GridLayout(3, false));
lastSecondRow = header;
group.layout();
sc.layout();
// setPageComplete(sfe.isValid() && isValid && valid);
}
Aggregations