use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class UserFallbackEntityResolver method resolveType.
/**
* Ask the user to select a replacement for a type.
*
* @param original the original entity
* @param candidate a candidate for the replacement
* @param schemaSpace the schema space
* @return the resolved type (may be the original)
*/
public static Type resolveType(TypeEntityDefinition original, @Nullable EntityDefinition candidate, SchemaSpaceID schemaSpace) {
ResolveCache cache = getCache();
TypeEntityDefinition replacement = cache.getReplacement(original);
if (replacement != null) {
// use cached replacement
return new DefaultType(replacement);
}
ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
final AtomicBoolean canceled;
final AtomicBoolean skipped = new AtomicBoolean(false);
if (ps.getTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(false)).as(Boolean.class)) {
canceled = new AtomicBoolean(true);
} else {
canceled = new AtomicBoolean(false);
}
final AtomicReference<EntityDefinition> result = new AtomicReference<>();
if (!canceled.get()) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
TypeEntityResolverDialog dlg = new TypeEntityResolverDialog(Display.getCurrent().getActiveShell(), schemaSpace, "Cell entity could not be resolved", candidate, false) {
@Override
public void create() {
super.create();
openTray(new ViewerEntityTray(original));
}
};
switch(dlg.open()) {
case Window.OK:
result.set(dlg.getObject());
break;
case Window.CANCEL:
// Don't try to resolve further entities
ps.setTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(true));
canceled.set(true);
break;
case TypeEntityResolverDialog.SKIP:
// skip this entity
skipped.set(true);
break;
default:
canceled.set(true);
}
}
});
}
EntityDefinition def = result.get();
if (canceled.get() || skipped.get()) {
// return the original so the cell is not lost
return new DefaultType(original);
} else if (def == null) {
// caller must take care about this
return null;
} else {
TypeEntityDefinition ted = (TypeEntityDefinition) def;
// make sure that the type is classified as mapping relevant
if (!ted.getType().getConstraint(MappingRelevantFlag.class).isEnabled()) {
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
ss.toggleMappable(schemaSpace, Collections.singleton(ted.getType()));
}
cache.put(original, ted);
return new DefaultType(ted);
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class EntityDefinitionServiceImpl method getTypeEntities.
/**
* @see EntityDefinitionService#getTypeEntities(TypeDefinition,
* SchemaSpaceID)
*/
@Override
public Collection<? extends TypeEntityDefinition> getTypeEntities(TypeDefinition type, SchemaSpaceID schemaSpace) {
TypeEntityDefinition ted = new TypeEntityDefinition(type, schemaSpace, null);
Set<Condition> conditions;
synchronized (conditionContexts) {
conditions = conditionContexts.get(ted);
}
List<TypeEntityDefinition> result = new ArrayList<TypeEntityDefinition>();
// add default type entity
result.add(ted);
// type entity definitions with filters
for (Condition condition : conditions) {
result.add(new TypeEntityDefinition(type, schemaSpace, condition.getFilter()));
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition 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.impl.TypeEntityDefinition in project hale by halestudio.
the class UnpopulatedPropertiesFilter method select.
/**
* @see ViewerFilter#select(Viewer, Object, Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (ps != null) {
if (element instanceof TreePath) {
element = ((TreePath) element).getLastSegment();
}
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
if (filterOnlyPopulatedTypes) {
TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
int typeCount = ps.getPopulation(type).getOverallCount();
if (typeCount == 0 || typeCount == Population.UNKNOWN) {
// all
return true;
}
}
if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
ps.hasPopulation(entityDef.getSchemaSpace())) {
// only filter if there is a population
Population pop = ps.getPopulation(entityDef);
return pop != null && pop.getOverallCount() != 0;
}
}
}
return true;
}
Aggregations