use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class GroovyTransformationPage method getVariableName.
/**
* Get the variable name for an entity definition.
*
* @param variable the variable
* @return the name to use as variable name
*/
protected String getVariableName(EntityDefinition variable) {
if (variable.getPropertyPath() != null && !variable.getPropertyPath().isEmpty()) {
List<String> names = new ArrayList<String>();
for (ChildContext context : variable.getPropertyPath()) {
names.add(context.getChild().getName().getLocalPart());
}
String longName = Joiner.on('_').join(names);
return longName;
} else
return variable.getDefinition().getDisplayName();
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class PropertyDefinitionDialog method getObjectFromSelection.
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
return (EntityDefinition) element;
}
}
if (!selection.isEmpty() && selection instanceof ITreeSelection) {
// create property definition w/ default contexts
TreePath path = ((ITreeSelection) selection).getPaths()[0];
// get parent type
TypeDefinition type = ((ChildDefinition<?>) path.getFirstSegment()).getParentType();
// determine definition path
List<ChildContext> defPath = new ArrayList<ChildContext>();
for (int i = 0; i < path.getSegmentCount(); i++) {
defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
}
// TODO check if property entity definition is applicable?
return new PropertyEntityDefinition(type, defPath, ssid, null);
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class DefinitionLabelProvider method getText.
/**
* @see LabelProvider#getText(Object)
*/
@Override
public String getText(Object element) {
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
element = entityDef.getDefinition();
List<ChildContext> path = entityDef.getPropertyPath();
if (path != null && !path.isEmpty()) {
if (!longNames) {
path = Collections.singletonList(path.get(path.size() - 1));
}
StringBuffer name = new StringBuffer();
boolean first = true;
for (ChildContext context : path) {
if (first) {
first = false;
} else {
name.append('.');
}
boolean defContext = context.getContextName() == null && context.getIndex() == null && context.getCondition() == null;
if (!defContext) {
name.append('(');
}
name.append(getText(context.getChild()));
if (!defContext) {
name.append(')');
}
}
return name.toString();
} else {
if (entityDef.getFilter() != null) {
return "(" + getText(element) + ")";
}
}
}
if (element instanceof Definition<?>) {
return ((Definition<?>) element).getDisplayName();
}
return super.getText(element);
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class SchemaEntityTypeIndexContentProvider method getChildren.
/**
* @see ITreeContentProvider#getChildren(Object)
*/
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof EntityDefinition) {
EntityDefinition entity = (EntityDefinition) parentElement;
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()) {
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.toArray();
}
}
return new Object[] {};
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class MergeParameterPage method getConfiguration.
/**
* @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
*/
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
ListMultimap<String, ParameterValue> configuration = ArrayListMultimap.create();
for (EntityDefinition selected : selection) {
// build property path (QNames separated by .)
/*
* FIXME this is problematic with property names that contain dots
* and only works out because only top level properties are allowed.
* If multiple levels are needed, properties should be stored as
* Lists of QNames (Complex values) or EntityDefinitions.
*/
// FIXME use MergeUtil helper function instead
String propertyPath = Joiner.on('.').join(Collections2.transform(selected.getPropertyPath(), new Function<ChildContext, String>() {
@Override
public String apply(ChildContext input) {
return input.getChild().getName().toString();
}
}));
// add it to configuration
configuration.put(parameter.getName(), new ParameterValue(propertyPath));
}
return configuration;
}
Aggregations