use of eu.esdihumboldt.cst.functions.inspire.SpellingType in project hale by halestudio.
the class GeographicalNamePage method getConfiguration.
/**
* @see ParameterPage#getConfiguration()
*/
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
// page was built
if (namePronounciationIPA == null) {
return ArrayListMultimap.create();
}
ListMultimap<String, ParameterValue> configuration = ArrayListMultimap.create(10, 1);
if (spellings != null && spellings.size() != 0) {
for (SpellingType sp : spellings) {
String script = sp.getScript();
String trans = sp.getTransliteration();
configuration.put(PROPERTY_SCRIPT, new ParameterValue(script));
configuration.put(PROPERTY_TRANSLITERATION, new ParameterValue(trans));
}
}
configuration.put(PROPERTY_PRONUNCIATIONSOUNDLINK, new ParameterValue(namePronounciationSounds.getText()));
configuration.put(PROPERTY_PRONUNCIATIONIPA, new ParameterValue(namePronounciationIPA.getText()));
configuration.put(PROPERTY_LANGUAGE, new ParameterValue(nameLanguageText.getText()));
String sourceOfName = nameSourceText.getText();
if (SOURCE_OF_NAME_PROMT.equals(sourceOfName)) {
sourceOfName = "";
}
configuration.put(PROPERTY_SOURCEOFNAME, new ParameterValue(sourceOfName));
configuration.put(PROPERTY_NAMESTATUS, new ParameterValue(nameStatusCombo.getText()));
configuration.put(PROPERTY_NATIVENESS, new ParameterValue(nameNativenessCombo.getText()));
configuration.put(PROPERTY_GRAMMA_GENDER, new ParameterValue(nameGenderCombo.getText()));
configuration.put(PROPERTY_GRAMMA_NUMBER, new ParameterValue(nameNumberCombo.getText()));
return configuration;
}
use of eu.esdihumboldt.cst.functions.inspire.SpellingType in project hale by halestudio.
the class GeographicalNamePage method createSpellingGroup.
private void createSpellingGroup(Composite parent, PropertyFunctionDefinition function) {
// define Spelling Group composite
Group configurationGroup = new Group(parent, SWT.NONE);
configurationGroup.setText(SPELLING_GROUP_TEXT);
configurationGroup.setLayout(GridLayoutFactory.fillDefaults().create());
GridData configurationAreaGD = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
configurationAreaGD.grabExcessHorizontalSpace = true;
configurationAreaGD.grabExcessVerticalSpace = true;
configurationGroup.setLayoutData(configurationAreaGD);
configurationGroup.setSize(configurationGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT));
configurationGroup.setFont(parent.getFont());
final Composite configurationComposite = new Composite(configurationGroup, SWT.NONE);
GridData configurationLayoutData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
configurationLayoutData.grabExcessHorizontalSpace = true;
configurationComposite.setLayoutData(configurationLayoutData);
GridLayout spellingLayout = new GridLayout();
spellingLayout.numColumns = 2;
spellingLayout.makeColumnsEqualWidth = false;
spellingLayout.marginWidth = 0;
spellingLayout.marginHeight = 0;
spellingLayout.horizontalSpacing = 8;
configurationComposite.setLayout(spellingLayout);
// or get the known information about the cell to be edited
if (getSpellings() == null || getSpellings().size() == 0) {
spellings = new ArrayList<SpellingType>();
ListMultimap<String, ? extends Entity> source = getWizard().getUnfinishedCell().getSource();
if (source != null) {
for (Entity item : source.values()) {
int i = 0;
Definition<?> entity = item.getDefinition().getDefinition();
if (entity instanceof PropertyDefinition) {
SpellingType sp = new SpellingType((PropertyDefinition) entity);
// set the same script value if you had a value before
if (scripts != null && i < scripts.size()) {
sp.setScript(scripts.get(i));
} else {
// else set the default value
sp.setScript(ISO_CODE_ENG);
}
// before
if (trans != null && i < trans.size()) {
sp.setTransliteration(trans.get(i));
} else {
// else set the default value
sp.setTransliteration("");
}
spellings.add(sp);
}
i++;
}
}
} else {
// after initialization of the spellings
ArrayList<PropertyDefinition> temp = new ArrayList<PropertyDefinition>();
ArrayList<SpellingType> templist = getSpellings();
// we have to create a new spellings list because a live
// modification of the combo box input would occur an error
spellings = new ArrayList<SpellingType>();
for (int i = 0; i < templist.size(); i++) {
temp.add(templist.get(i).getProperty());
if (scripts != null && trans != null && i < scripts.size() && scripts.get(i) != null && i < trans.size() && trans.get(i) != null) {
templist.get(i).setScript(scripts.get(i));
templist.get(i).setTransliteration(trans.get(i));
}
}
for (Entity item : getWizard().getUnfinishedCell().getSource().values()) {
Definition<?> entity = item.getDefinition().getDefinition();
if (entity instanceof PropertyDefinition) {
PropertyDefinition propDef = (PropertyDefinition) entity;
for (SpellingType st : templist) {
// transliteration) to the new spellings list
if (propDef.equals(st.getProperty())) {
spellings.add(st);
}
}
// with default values
if (!temp.contains(propDef)) {
SpellingType sp = new SpellingType(propDef);
sp.setScript(ISO_CODE_ENG);
sp.setTransliteration("");
spellings.add(sp);
}
}
}
}
// Text
final Label nameSpellingTextLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingTextLabel.setText(SPELLING_TEXT_LABEL_TEXT);
this.nameSpellingText = new ComboViewer(configurationComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
this.nameSpellingText.getControl().setLayoutData(configurationLayoutData);
this.nameSpellingText.setContentProvider(ArrayContentProvider.getInstance());
this.nameSpellingText.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof SpellingType) {
return ((SpellingType) element).getProperty().getName().getLocalPart();
}
return super.getText(element);
}
});
this.nameSpellingText.setInput(spellings);
// default set selection to the first element on the list
if (!spellings.isEmpty()) {
this.activeSpelling = spellings.iterator().next();
this.nameSpellingText.setSelection(new StructuredSelection(activeSpelling));
}
// set active spelling
nameSpellingText.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
SpellingType selected = (SpellingType) ((IStructuredSelection) event.getSelection()).getFirstElement();
String script = ISO_CODE_ENG;
// $NON-NLS-1$
String transliteration = "";
activeSpelling = selected;
if (activeSpelling.getScript() != null && // $NON-NLS-1$
!activeSpelling.getScript().equals(""))
script = activeSpelling.getScript();
if (activeSpelling.getTransliteration() != null && // $NON-NLS-1$
!activeSpelling.getTransliteration().equals(""))
transliteration = activeSpelling.getTransliteration();
nameSpellingScript.setText(script);
nameSpellingTransliteration.setText(transliteration);
}
}
});
// Script
final Label nameSpellingScriptLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingScriptLabel.setText(SCRIPT_LABEL_TEXT);
configureParameterLabel(nameSpellingScriptLabel, PROPERTY_SCRIPT, function);
this.nameSpellingScript = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
this.nameSpellingScript.setLayoutData(configurationLayoutData);
this.nameSpellingScript.setEnabled(true);
this.nameSpellingScript.setTabs(0);
// $NON-NLS-1$
String script = "eng";
// read script from the active spelling
if (activeSpelling != null && activeSpelling.getScript() != null)
script = activeSpelling.getScript();
// set default value for script
this.nameSpellingScript.setText(script);
this.nameSpellingScript.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
activeSpelling.setScript(nameSpellingScript.getText());
}
});
// Transliteration
final Label nameSpellingTransliterationLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingTransliterationLabel.setText(TRANSLITERATION_LABEL_TEXT);
configureParameterLabel(nameSpellingTransliterationLabel, PROPERTY_TRANSLITERATION, function);
this.nameSpellingTransliteration = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
this.nameSpellingTransliteration.setLayoutData(configurationLayoutData);
this.nameSpellingTransliteration.setEnabled(true);
this.nameSpellingTransliteration.setTabs(0);
// read script from the active spelling
// $NON-NLS-1$
String transliteration = "";
if (activeSpelling != null && activeSpelling.getTransliteration() != null)
transliteration = activeSpelling.getTransliteration();
// set default value for transliteration
this.nameSpellingTransliteration.setText(transliteration);
this.nameSpellingTransliteration.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
activeSpelling.setTransliteration(nameSpellingTransliteration.getText());
}
});
}
use of eu.esdihumboldt.cst.functions.inspire.SpellingType in project hale by halestudio.
the class GeographicalNamePage method getActiveSpelling.
/**
* Returns a spelling assigned to source attribute name
*
* @param property the assigned source property definition
* @return the spelling assigned to property
*/
protected SpellingType getActiveSpelling(PropertyDefinition property) {
// 1. check if the spelling object already exists
Iterator<SpellingType> iterator = getSpellings().iterator();
SpellingType spelling;
SpellingType aSpelling = null;
while (iterator.hasNext()) {
spelling = iterator.next();
if (spelling.getProperty().equals(property)) {
aSpelling = spelling;
break;
}
}
// if active spelling does not exist
if (aSpelling == null) {
aSpelling = new SpellingType(property);
this.spellings.add(aSpelling);
}
return aSpelling;
}
Aggregations