Search in sources :

Example 1 with ChildContext

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;
}
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 2 with ChildContext

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

Example 3 with ChildContext

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

Example 4 with ChildContext

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;
}
Also used : QName(javax.xml.namespace.QName) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)

Example 5 with ChildContext

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;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) QName(javax.xml.namespace.QName) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)

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