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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations