Search in sources :

Example 61 with Entity

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

the class SourceTargetTypeSelector method setSelection.

/**
 * Sets the selection according to the given cell.<br>
 * If the cell is a property cell, it will select the types whom the
 * properties belong to.<br>
 * If <code>cell</code> is <code>null</code> the selected types aren't
 * changed, but is an existing type cell was selected, that selection is
 * undone.
 *
 * @param cell the cell to set the selection to
 */
private void setSelection(Cell cell) {
    if (cell != null) {
        // in case of a real join cell there are multiple source types
        if (cell.getSource() == null || cell.getSource().isEmpty())
            sourceTypeSelector.setSelection(StructuredSelection.EMPTY);
        else if (cell.getSource().size() > 1)
            sourceTypeSelector.showText("<multiple types>");
        else {
            Entity source = CellUtil.getFirstEntity(cell.getSource());
            ISelection selection = new StructuredSelection(AlignmentUtil.getTypeEntity(source.getDefinition()));
            sourceTypeSelector.setSelection(selection);
        }
        // target can only be one or none
        Entity target = CellUtil.getFirstEntity(cell.getTarget());
        ISelection selection = (target == null) ? StructuredSelection.EMPTY : new StructuredSelection(AlignmentUtil.getTypeEntity(target.getDefinition()));
        targetTypeSelector.setSelection(selection);
    }
    if (cell != null && AlignmentUtil.isTypeCell(cell) && cell.getId() != null) {
        // a real type cell
        selectedCell = cell;
        String label;
        String functionId = cell.getTransformationIdentifier();
        FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, HaleUI.getServiceProvider());
        if (function != null)
            label = functionLabels.getText(function);
        else
            label = functionId;
        selectCellButton.setText(label);
        sourceTypeSelector.getControl().setEnabled(false);
        targetTypeSelector.getControl().setEnabled(false);
    } else {
        selectedCell = null;
        selectCellButton.setText("Select cell");
        sourceTypeSelector.getControl().setEnabled(true);
        targetTypeSelector.getControl().setEnabled(true);
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 62 with Entity

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

the class ReplaceFunctionWizardContribution method getSelection.

/**
 * @see SchemaSelectionFunctionContribution#getSelection()
 */
@Override
public SchemaSelection getSelection() {
    // derive a schema selection from the cell
    DefaultSchemaSelection sel = new DefaultSchemaSelection();
    Cell orgCell = getOriginalCell();
    if (orgCell != null) {
        if (orgCell.getSource() != null) {
            for (Entity source : getOriginalCell().getSource().values()) {
                sel.addSourceItem(source.getDefinition());
            }
        }
        if (orgCell.getTarget() != null) {
            for (Entity target : getOriginalCell().getTarget().values()) {
                sel.addTargetItem(target.getDefinition());
            }
        }
    }
    return sel;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 63 with Entity

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

the class EntityDefinitionServiceImpl method replace.

/**
 * Creates a new ListMultimap with all occurrences of originalDef replaced
 * by newDef. newDef must be a sibling of originalDef.
 *
 * @param entities the original list
 * @param originalDef the entity definition to be replaced
 * @param newDef the entity definition to use
 * @return a new list
 */
private ListMultimap<String, ? extends Entity> replace(ListMultimap<String, ? extends Entity> entities, EntityDefinition originalDef, EntityDefinition newDef) {
    ListMultimap<String, Entity> newList = ArrayListMultimap.create();
    for (Entry<String, ? extends Entity> entry : entities.entries()) {
        EntityDefinition entryDef = entry.getValue().getDefinition();
        Entity newEntry;
        if (AlignmentUtil.isParent(originalDef, entryDef)) {
            if (entry.getValue() instanceof Type) {
                // entry is a Type, so the changed Definition must be a
                // Type, too.
                newEntry = new DefaultType((TypeEntityDefinition) newDef);
            } else if (entry.getValue() instanceof Property) {
                // entry is a Property, check changed Definition.
                if (originalDef.getPropertyPath().isEmpty()) {
                    // Type changed.
                    newEntry = new DefaultProperty(new PropertyEntityDefinition(newDef.getType(), entryDef.getPropertyPath(), entryDef.getSchemaSpace(), newDef.getFilter()));
                } else {
                    // Some element of the property path changed.
                    List<ChildContext> newPath = new ArrayList<ChildContext>(entryDef.getPropertyPath());
                    int lastIndexOfChangedDef = newDef.getPropertyPath().size() - 1;
                    newPath.set(lastIndexOfChangedDef, newDef.getPropertyPath().get(lastIndexOfChangedDef));
                    newEntry = new DefaultProperty(new PropertyEntityDefinition(entryDef.getType(), newPath, entryDef.getSchemaSpace(), entryDef.getFilter()));
                }
            } else {
                throw new IllegalStateException("Entity is neither a Type nor a Property.");
            }
        } else {
            newEntry = entry.getValue();
        }
        newList.put(entry.getKey(), newEntry);
    }
    return newList;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 64 with Entity

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

the class EntityDefinitionServiceImpl method addMissingEntityContexts.

/**
 * Add missing contexts for the given entities
 *
 * @param entities the entities
 * @return all entity definitions for which new contexts have been added
 */
private Collection<EntityDefinition> addMissingEntityContexts(Iterable<? extends Entity> entities) {
    Collection<EntityDefinition> addedContexts = new ArrayList<EntityDefinition>();
    for (Entity entity : entities) {
        EntityDefinition entityDef = entity.getDefinition();
        addContexts(entityDef, addedContexts);
    }
    return addedContexts;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ArrayList(java.util.ArrayList)

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