Search in sources :

Example 1 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class GraphLabelProvider method getText.

/**
 * @see LabelProvider#getText(Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof Entity) {
        element = ((Entity) element).getDefinition();
    }
    if (element instanceof EntityDefinition) {
        // use definition text
        return definitionLabels.getText(element);
    }
    if (element instanceof Definition<?>) {
        // use definition text
        return definitionLabels.getText(element);
    }
    if (element instanceof Cell) {
        // use function name if possible
        Cell cell = (Cell) element;
        String functionId = cell.getTransformationIdentifier();
        FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, serviceProvider);
        if (function != null) {
            return functionLabels.getText(function);
        }
        return functionId;
    }
    if (element instanceof FunctionDefinition) {
        return functionLabels.getText(element);
    }
    return super.getText(element);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 2 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class GraphLabelProvider method getImage.

/**
 * @see LabelProvider#getImage(Object)
 */
@Override
public Image getImage(Object element) {
    if (element instanceof Entity) {
        element = ((Entity) element).getDefinition();
    }
    if (element instanceof EntityDefinition || element instanceof Definition<?>) {
        // use definition image
        return definitionLabels.getImage(element);
    }
    if (element instanceof Cell) {
        // use function image if possible
        Cell cell = (Cell) element;
        String functionId = cell.getTransformationIdentifier();
        FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, serviceProvider);
        if (function != null) {
            Image image = functionLabels.getImage(function);
            if (image == null) {
                // use a default image if none is available
                image = CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_FUNCTION);
            }
            if (cell.isBaseCell()) {
                Image baseAlignmentImage = baseAlignmentFunctionImages.get(functionId);
                if (baseAlignmentImage == null) {
                    baseAlignmentImage = new Image(image.getDevice(), image.getBounds());
                    GC gc = new GC(baseAlignmentImage);
                    try {
                        gc.drawImage(image, 0, 0);
                        gc.drawImage(baseAlignmentFunctionOverlay, 0, 0);
                    } finally {
                        gc.dispose();
                    }
                    baseAlignmentFunctionImages.put(functionId, baseAlignmentImage);
                }
                image = baseAlignmentImage;
            }
            return image;
        }
        return null;
    }
    if (element instanceof FunctionDefinition) {
        return functionLabels.getImage(element);
    }
    return super.getImage(element);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 3 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class OptionalPropertiesFilter method areChildrenOptional.

/**
 * Determines if the given (nillable) entity can be considered optional in
 * respect to its children.
 *
 * @param entityDef the entity definition which children to check
 * @param alreadyChecked the set of definitions that have already been
 *            checked (excluding the given entity)
 * @return if all children are optional
 */
private boolean areChildrenOptional(EntityDefinition entityDef, Set<Definition<?>> alreadyChecked) {
    // get children without contexts
    Collection<? extends EntityDefinition> children = AlignmentUtil.getChildrenWithoutContexts(entityDef);
    if (children == null || children.isEmpty()) {
        return true;
    }
    for (EntityDefinition child : children) {
        Set<Definition<?>> checked = new HashSet<>(alreadyChecked);
        checked.add(entityDef.getDefinition());
        ChildDefinition<?> childDef = (ChildDefinition<?>) child.getDefinition();
        /*
			 * XML: We only need to check children that are attributes, if they
			 * are optional.
			 */
        if (childDef.asProperty() != null && childDef.asProperty().getConstraint(XmlAttributeFlag.class).isEnabled()) {
            // need to check if it is optional
            if (!isOptional(child, checked)) {
                return false;
            }
        }
    /*
			 * XXX does other special handling need to be done for other kinds
			 * of schemas?
			 */
    }
    return true;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) HashSet(java.util.HashSet)

Example 4 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition 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 5 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class StyledDefinitionLabelProvider method update.

/**
 * @see StyledCellLabelProvider#update(ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    element = extractElement(element);
    StyledString text = new StyledString(defaultLabels.getText(element));
    cell.setImage(defaultLabels.getImage(element));
    String contextText = null;
    String countText = null;
    if (element instanceof EntityDefinition) {
        PopulationService ps = PlatformUI.getWorkbench().getService(PopulationService.class);
        if (ps != null) {
            Population pop = ps.getPopulation((EntityDefinition) element);
            int count = pop.getOverallCount();
            int parents = pop.getParentsCount();
            switch(count) {
                case Population.UNKNOWN:
                    countText = "\u00d7?";
                    break;
                case 0:
                    break;
                default:
                    countText = "\u00d7" + count;
                    if (parents != count) {
                        countText += " (" + parents + ")";
                    }
            }
        }
        contextText = AlignmentUtil.getContextText((EntityDefinition) element);
        element = ((EntityDefinition) element).getDefinition();
    }
    // append cardinality
    if (!suppressCardinality && element instanceof ChildDefinition<?>) {
        Cardinality cardinality = null;
        if (((ChildDefinition<?>) element).asGroup() != null) {
            cardinality = ((ChildDefinition<?>) element).asGroup().getConstraint(Cardinality.class);
        } else if (((ChildDefinition<?>) element).asProperty() != null) {
            cardinality = ((ChildDefinition<?>) element).asProperty().getConstraint(Cardinality.class);
        }
        if (cardinality != null) {
            // only append cardinality if it isn't 1/1
            if (cardinality.getMinOccurs() != 1 || cardinality.getMaxOccurs() != 1) {
                String card = " " + MessageFormat.format("({0}..{1})", new Object[] { Long.valueOf(cardinality.getMinOccurs()), (cardinality.getMaxOccurs() == Cardinality.UNBOUNDED) ? ("n") : (Long.valueOf(cardinality.getMaxOccurs())) });
                text.append(card, StyledString.COUNTER_STYLER);
            }
        }
    }
    if (contextText != null) {
        contextText = " " + contextText;
        text.append(contextText, StyledString.DECORATIONS_STYLER);
    }
    if (countText != null) {
        countText = " " + countText;
        text.append(countText, StyledString.QUALIFIER_STYLER);
    }
    cell.setText(text.toString());
    cell.setStyleRanges(text.getStyleRanges());
    Color foreground = getForeground(cell.getElement());
    cell.setForeground(foreground);
    Color background = getBackground(cell.getElement());
    cell.setBackground(background);
    super.update(cell);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) Color(org.eclipse.swt.graphics.Color) PopulationService(eu.esdihumboldt.hale.ui.common.service.population.PopulationService) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) Population(eu.esdihumboldt.hale.ui.common.service.population.Population) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5