Search in sources :

Example 1 with SpellingType

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;
}
Also used : SpellingType(eu.esdihumboldt.cst.functions.inspire.SpellingType) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue)

Example 2 with SpellingType

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());
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) SpellingType(eu.esdihumboldt.cst.functions.inspire.SpellingType) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ModifyListener(org.eclipse.swt.events.ModifyListener) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 3 with SpellingType

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;
}
Also used : SpellingType(eu.esdihumboldt.cst.functions.inspire.SpellingType)

Aggregations

SpellingType (eu.esdihumboldt.cst.functions.inspire.SpellingType)3 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 ArrayList (java.util.ArrayList)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1