use of eu.esdihumboldt.hale.ui.service.align.resolver.internal.TypeEntityResolverDialog 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);
}
}
Aggregations