use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class PropertyPathContentProvider method getEntityChildren.
private Collection<EntityDefinition> getEntityChildren(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 = AlignmentUtil.createEntity(entity.getType(), createPath(entity.getPropertyPath(), context), entity.getSchemaSpace(), entity.getFilter());
result.add(defaultEntity);
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class MergeParameterPage method getEntityDefinition.
@Nullable
private EntityDefinition getEntityDefinition(String propertyPath, TypeDefinition sourceType) {
ArrayList<ChildContext> contextPath = new ArrayList<ChildContext>();
// XXX removed because it causes problems with dots in property names
// List<QName> path = PropertyResolver.getQNamesFromPath(propertyPath);
// FIXME quick fix that only works because only first level properties
// are supported
List<QName> path = Collections.singletonList(QName.valueOf(propertyPath));
Iterator<QName> iter = path.iterator();
ChildDefinition<?> child = sourceType.getChild(iter.next());
if (child != null) {
contextPath.add(new ChildContext(child));
while (iter.hasNext()) {
child = DefinitionUtil.getChild(child, iter.next());
contextPath.add(new ChildContext(child));
}
return AlignmentUtil.createEntity(sourceType, contextPath, SchemaSpaceID.SOURCE, null);
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class CellInfo method getName.
private String getName(CellType cellType, boolean fullName) {
Iterator<? extends Entity> iterator;
ListMultimap<String, ? extends Entity> entities;
PropertyDefinition child = null;
switch(cellType) {
case SOURCE:
if ((entities = getCell().getSource()) == null)
return null;
iterator = entities.values().iterator();
break;
case TARGET:
if ((entities = getCell().getTarget()) == null)
return null;
iterator = entities.values().iterator();
break;
default:
return null;
}
StringBuffer sb = new StringBuffer();
while (iterator.hasNext()) {
Entity entity = iterator.next();
if (fullName) {
for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
child = childContext.getChild().asProperty();
if (child != null) {
sb.append(child.getDisplayName());
sb.append(".");
}
}
sb.append(entity.getDefinition().getDefinition().getDisplayName());
sb.append(",\n");
} else {
sb.append(entity.getDefinition().getDefinition().getDisplayName());
sb.append(", ");
}
}
String result = sb.toString();
if (fullName)
return result.substring(0, result.lastIndexOf(",\n"));
else
return result.substring(0, result.lastIndexOf(","));
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class DefaultGeometryUtil method isDefaultGeometry.
/**
* Determines if the given entity definition is a default geometry property.
*
* @param entityDef the entity definition
* @return if the entity definition represents a default geometry property
*/
public static boolean isDefaultGeometry(EntityDefinition entityDef) {
GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
if (gss == null) {
log.error("No geometry schema service available");
return false;
}
List<QName> defPath = gss.getDefaultGeometry(entityDef.getType());
if (defPath != null) {
// match path against entity definition path
List<ChildContext> entPath = entityDef.getPropertyPath();
if (defPath.size() == entPath.size()) {
// compare path elements
for (int i = 0; i < defPath.size(); i++) {
if (!Objects.equal(defPath.get(i), entPath.get(i).getChild().getName())) {
// each path entry must be equal
return false;
}
}
return true;
}
}
return false;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext 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;
}
Aggregations