Search in sources :

Example 6 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class CellInfo method getName.

private String getName(CellType cellType, boolean fullName) {
    Iterator<? extends Entity> iterator;
    ListMultimap<String, ? extends Entity> entities;
    PropertyDefinition child = null;
    switch(cellType) {
        case SOURCE:
            if ((entities = getCell().getSource()) == null)
                return null;
            iterator = entities.values().iterator();
            break;
        case TARGET:
            if ((entities = getCell().getTarget()) == null)
                return null;
            iterator = entities.values().iterator();
            break;
        default:
            return null;
    }
    StringBuffer sb = new StringBuffer();
    while (iterator.hasNext()) {
        Entity entity = iterator.next();
        if (fullName) {
            for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
                child = childContext.getChild().asProperty();
                if (child != null) {
                    sb.append(child.getDisplayName());
                    sb.append(".");
                }
            }
            sb.append(entity.getDefinition().getDefinition().getDisplayName());
            sb.append(",\n");
        } else {
            sb.append(entity.getDefinition().getDefinition().getDisplayName());
            sb.append(", ");
        }
    }
    String result = sb.toString();
    if (fullName)
        return result.substring(0, result.lastIndexOf(",\n"));
    else
        return result.substring(0, result.lastIndexOf(","));
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Example 7 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity 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 8 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class SequentialIDParameterPage method validateValue.

/**
 * Validates if the given value is valid for the target property.
 *
 * @param value the value to validate
 * @return if the value is valid
 */
protected boolean validateValue(String value) {
    Cell cell = getWizard().getUnfinishedCell();
    List<? extends Entity> targets = cell.getTarget().get(null);
    if (!targets.isEmpty()) {
        Entity entity = targets.get(0);
        Definition<?> def = entity.getDefinition().getDefinition();
        if (def instanceof PropertyDefinition) {
            TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
            Validator validator = propertyType.getConstraint(ValidationConstraint.class).getValidator();
            // TODO conversion to binding needed?
            String error = validator.validate(value);
            // update the example decoration
            if (error == null) {
                exampleDecoration.hide();
            } else {
                exampleDecoration.setDescriptionText(error);
                exampleDecoration.show();
            }
            return error == null;
        }
    }
    // no validation possible
    return true;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) Cell(eu.esdihumboldt.hale.common.align.model.Cell) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Validator(eu.esdihumboldt.util.validator.Validator) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 9 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class AlignmentViewContentProvider method getElements.

/**
 * @see eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider#getElements(java.lang.Object)
 */
@Override
public Object[] getElements(Object input) {
    // check if the input is a (incomplete) type cell
    if (input instanceof Cell) {
        Cell cell = (Cell) input;
        Entity source = CellUtil.getFirstEntity(cell.getSource());
        Entity target = CellUtil.getFirstEntity(cell.getTarget());
        if ((source == null || source instanceof Type) && (target == null || target instanceof Type))
            return getEdges((Cell) input);
    }
    return super.getElements(input);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Type(eu.esdihumboldt.hale.common.align.model.Type) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 10 with Entity

use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.

the class GenericParameterPage method onShowPage.

/**
 * @see HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    Cell cell = getWizard().getUnfinishedCell();
    // update variables as they could have changed
    if (!AlignmentUtil.isTypeCell(cell)) {
        Set<PropertyEntityDefinition> variables = new HashSet<PropertyEntityDefinition>();
        for (Entity e : cell.getSource().values()) {
            // Cell is no type cell, so entities are Properties.
            variables.add(((Property) e).getDefinition());
        }
        for (Pair<AttributeEditor<?>, Button> pair : inputFields.values()) pair.getFirst().setVariables(variables);
    }
    updateState();
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Button(org.eclipse.swt.widgets.Button) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) Cell(eu.esdihumboldt.hale.common.align.model.Cell) HashSet(java.util.HashSet)

Aggregations

Entity (eu.esdihumboldt.hale.common.align.model.Entity)64 Cell (eu.esdihumboldt.hale.common.align.model.Cell)25 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)21 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)14 ArrayList (java.util.ArrayList)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)9 List (java.util.List)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 HashSet (java.util.HashSet)6 Locale (java.util.Locale)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4