Search in sources :

Example 36 with ChildContext

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();
}
Also used : ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 37 with ChildContext

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;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 38 with ChildContext

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);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 39 with ChildContext

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[] {};
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 40 with ChildContext

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;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Function(com.google.common.base.Function) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)63 ArrayList (java.util.ArrayList)32 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)29 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)24 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)12 QName (javax.xml.namespace.QName)11 Property (eu.esdihumboldt.hale.common.align.model.Property)7 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 List (java.util.List)7 Condition (eu.esdihumboldt.hale.common.align.model.Condition)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)6 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)5 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)5 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)4 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3