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);
}
}
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;
}
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;
}
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;
}
Aggregations