use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class SetDefaultGeometryHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
/*
* Set the defaut geometry to the first valid child entity definition
* from the selection (for the type the entity definition is associated
* to)
*/
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object element : ((IStructuredSelection) selection).toList()) {
if (element instanceof EntityDefinition) {
EntityDefinition def = (EntityDefinition) element;
if (!def.getPropertyPath().isEmpty()) {
// path must not be empty
// XXX is this true? we could set the default geometry
// to the type to use all geometries
List<QName> path = new ArrayList<QName>(def.getPropertyPath().size());
for (ChildContext child : def.getPropertyPath()) {
path.add(child.getChild().getName());
}
GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
gss.setDefaultGeometry(def.getType(), path);
}
}
}
}
// otherwise does nothing
return null;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class MappingView method createLabelProvider.
@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {
@Override
protected boolean isInherited(Cell cell) {
// cannot inherit type cells
if (AlignmentUtil.isTypeCell(cell))
return false;
SchemaSelection selection = SchemaSelectionHelper.getSchemaSelection();
if (selection != null && !selection.isEmpty()) {
DefaultCell dummyTypeCell = new DefaultCell();
ListMultimap<String, Type> sources = ArrayListMultimap.create();
ListMultimap<String, Type> targets = ArrayListMultimap.create();
Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
for (EntityDefinition def : items.getFirst()) sources.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
for (EntityDefinition def : items.getSecond()) targets.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
dummyTypeCell.setSource(sources);
dummyTypeCell.setTarget(targets);
return AlignmentUtil.reparentCell(cell, dummyTypeCell, true) != cell;
} else
return false;
}
};
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class UserMigration method entityReplacement.
@Override
public Optional<EntityDefinition> entityReplacement(EntityDefinition entity, SimpleLog log) {
// use functionality from entity resolver
if (entity instanceof TypeEntityDefinition) {
EntityDefinition candidate = entity;
Type type = UserFallbackEntityResolver.resolveType((TypeEntityDefinition) entity, candidate, schemaSpace);
return Optional.ofNullable(type).map(e -> e.getDefinition());
} else if (entity instanceof PropertyEntityDefinition) {
EntityDefinition candidate = entity;
candidate = EntityCandidates.find((PropertyEntityDefinition) entity);
Property property = UserFallbackEntityResolver.resolveProperty((PropertyEntityDefinition) entity, candidate, schemaSpace);
return Optional.ofNullable(property).map(e -> e.getDefinition());
} else {
log.error("Unrecognised entity type: " + entity.getClass());
return Optional.empty();
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class UserFallbackEntityResolver method resolveProperty.
/**
* Ask the user to select a replacement for a property.
*
* @param original the original entity
* @param candidate a candidate for the replacement
* @param schemaSpace the schema space
* @return the resolved property (may be the original)
*/
public static Property resolveProperty(PropertyEntityDefinition original, @Nullable EntityDefinition candidate, SchemaSpaceID schemaSpace) {
ResolveCache cache = getCache();
PropertyEntityDefinition replacement = cache.getReplacement(original);
if (replacement != null) {
// use cached replacement
return new DefaultProperty(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() {
PropertyEntityResolverDialog dlg = new PropertyEntityResolverDialog(Display.getCurrent().getActiveShell(), schemaSpace, null, "Cell entity could not be resolved", candidate) {
@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 PropertyEntityResolverDialog.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 DefaultProperty(original);
} else if (def == null) {
// caller must take care about this
return null;
} else {
PropertyEntityDefinition propDef = (PropertyEntityDefinition) def;
cache.put(original, propDef);
return new DefaultProperty(propDef);
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class EntityDefinitionServiceImpl method getChildren.
/**
* @see EntityDefinitionService#getChildren(EntityDefinition)
*/
@Override
public Collection<? extends EntityDefinition> getChildren(EntityDefinition entity) {
List<ChildContext> path = entity.getPropertyPath();
Collection<? extends ChildDefinition<?>> children;
if (path == null || path.isEmpty()) {
// entity is a type, children are the type children
children = entity.getType().getChildren();
} else {
// get parent context
ChildContext parentContext = path.get(path.size() - 1);
if (parentContext.getChild().asGroup() != null) {
children = parentContext.getChild().asGroup().getDeclaredChildren();
} else if (parentContext.getChild().asProperty() != null) {
children = parentContext.getChild().asProperty().getPropertyType().getChildren();
} else {
throw new IllegalStateException("Illegal child definition type encountered");
}
}
if (children == null || children.isEmpty()) {
return Collections.emptyList();
}
Collection<EntityDefinition> result = new ArrayList<EntityDefinition>(children.size());
for (ChildDefinition<?> child : children) {
// add default child entity definition to result
ChildContext context = new ChildContext(child);
EntityDefinition defaultEntity = createEntity(entity.getType(), createPath(entity.getPropertyPath(), context), entity.getSchemaSpace(), entity.getFilter());
result.add(defaultEntity);
// look up additional instance contexts and add them
synchronized (namedContexts) {
for (Integer contextName : namedContexts.get(defaultEntity)) {
ChildContext namedContext = new ChildContext(contextName, null, null, child);
EntityDefinition namedChild = createEntity(entity.getType(), createPath(entity.getPropertyPath(), namedContext), entity.getSchemaSpace(), entity.getFilter());
result.add(namedChild);
}
}
synchronized (indexContexts) {
for (Integer index : indexContexts.get(defaultEntity)) {
ChildContext indexContext = new ChildContext(null, index, null, child);
EntityDefinition indexChild = createEntity(entity.getType(), createPath(entity.getPropertyPath(), indexContext), entity.getSchemaSpace(), entity.getFilter());
result.add(indexChild);
}
}
synchronized (conditionContexts) {
for (Condition condition : conditionContexts.get(defaultEntity)) {
ChildContext conditionContext = new ChildContext(null, null, condition, child);
EntityDefinition conditionChild = createEntity(entity.getType(), createPath(entity.getPropertyPath(), conditionContext), entity.getSchemaSpace(), entity.getFilter());
result.add(conditionChild);
}
}
}
return result;
}
Aggregations