use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class InstanceValueLabelProvider method update.
/**
* @see CellLabelProvider#update(ViewerCell)
*/
@Override
public void update(ViewerCell cell) {
TreePath treePath = cell.getViewerRow().getTreePath();
Object element = treePath.getLastSegment();
Definition<?> definition = null;
Object value = ((Pair<?, ?>) element).getSecond();
if (((Pair<?, ?>) element).getFirst() instanceof Definition)
definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
InstanceValidationReport report = null;
if (definition instanceof ChildDefinition<?>) {
report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
} else if (definition instanceof TypeDefinition) {
report = validator.validate((Instance) value);
}
boolean hasValue = false;
if (value instanceof Instance) {
hasValue = ((Instance) value).getValue() != null;
}
StyledString styledString;
if (value == null) {
styledString = new StyledString("no value", StyledString.DECORATIONS_STYLER);
} else if (value instanceof Group && !hasValue) {
styledString = new StyledString("+", StyledString.QUALIFIER_STYLER);
} else {
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// TODO some kind of conversion?
String stringValue = value.toString();
/*
* Values that are very large, e.g. string representations of very
* complex geometries lead to
* StyledCellLabelProvider.updateTextLayout taking a very long time,
* rendering the application unresponsive when the data views are
* displayed. As such, we reduce the string to a maximum size.
*/
if (stringValue.length() > MAX_STRING_LENGTH) {
stringValue = stringValue.substring(0, MAX_STRING_LENGTH) + "...";
}
styledString = new StyledString(stringValue, null);
}
cell.setText(styledString.toString());
cell.setStyleRanges(styledString.getStyleRanges());
if (report != null && !report.getWarnings().isEmpty()) {
cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
}
super.update(cell);
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class InstanceValueLabelProvider method getToolTipText.
/**
* @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
*/
@Override
public String getToolTipText(Object element) {
InstanceValidationReport report;
Object value = ((Pair<?, ?>) element).getSecond();
Definition<?> definition = null;
if (((Pair<?, ?>) element).getFirst() instanceof Definition)
definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
if (definition instanceof ChildDefinition<?>) {
report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
} else if (definition instanceof TypeDefinition) {
report = validator.validate((Instance) value);
} else {
return null;
}
Collection<InstanceValidationMessage> warnings = report.getWarnings();
if (warnings.isEmpty())
return null;
StringBuilder toolTip = new StringBuilder();
for (Message m : warnings) {
toolTip.append(m.getFormattedMessage()).append('\n');
}
return toolTip.substring(0, toolTip.length() - 1);
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class EntityTypeIndexHierarchy method getChildren.
/**
* @see ITreeContentProvider#getChildren(Object)
*/
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof EntityDefinition) {
EntityDefinition parent = (EntityDefinition) parentElement;
List<EntityDefinition> children = new ArrayList<EntityDefinition>();
// add valid sub types and alternative type entities
if (parent.getPropertyPath().isEmpty() && parent.getFilter() == null) {
// add valid sub types w/o filter
for (TypeDefinition subtype : parent.getType().getSubTypes()) {
if (validTypes.contains(subtype)) {
children.add(new TypeEntityDefinition(subtype, parent.getSchemaSpace(), null));
}
}
// add type contexts
for (TypeEntityDefinition typeEntity : entityDefinitionService.getTypeEntities(parent.getType(), parent.getSchemaSpace())) {
if (typeEntity.getFilter() != null) {
// only use type entities with filter defined
children.add(typeEntity);
}
}
}
if (!onlyTypes) {
// add regular children
children.addAll(entityDefinitionService.getChildren(parent));
}
return children.toArray();
} else {
throw new IllegalArgumentException("Given element not supported in schema tree structure.");
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class EntityTypeIndexHierarchy method getElements.
/**
* @see ITreeContentProvider#getElements(Object)
*/
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof TypeIndex) {
validTypes = new HashSet<TypeDefinition>();
List<TypeEntityDefinition> roots = new ArrayList<TypeEntityDefinition>();
Queue<TypeDefinition> types = new LinkedList<TypeDefinition>();
if (onlyMappingRelevant)
types.addAll(((TypeIndex) inputElement).getMappingRelevantTypes());
else {
for (TypeDefinition type : ((TypeIndex) inputElement).getTypes()) if (type.getConstraint(MappableFlag.class).isEnabled())
types.add(type);
}
// collect types and super types in valid types set
while (!types.isEmpty()) {
TypeDefinition type = types.poll();
if (!validTypes.contains(type)) {
validTypes.add(type);
TypeDefinition superType = type.getSuperType();
if (superType != null && !validTypes.contains(superType)) {
types.add(superType);
}
if (superType == null) {
// add default type as root
roots.add(new TypeEntityDefinition(type, schemaSpace, null));
}
}
}
// }
return roots.toArray();
} else {
throw new IllegalArgumentException("Content provider only applicable for type indexes.");
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class OrientInstanceService method getInstanceTypes.
/**
* Get the instance types available in the given database
*
* @param lodb the database
* @param schemas the type definitions
* @return the set of type definitions for which instances are present in
* the database
*/
private Set<TypeDefinition> getInstanceTypes(LocalOrientDB lodb, SchemaSpace schemas) {
Set<TypeDefinition> result = new HashSet<TypeDefinition>();
DatabaseReference<ODatabaseDocumentTx> dbref = lodb.openRead();
try {
ODatabaseDocumentTx db = dbref.getDatabase();
// get schema and classes
OSchema schema = db.getMetadata().getSchema();
Collection<OClass> classes = schema.getClasses();
Collection<? extends TypeDefinition> mappableTypes = schemas.getMappingRelevantTypes();
Set<QName> allowedTypes = new HashSet<QName>();
for (TypeDefinition type : mappableTypes) {
allowedTypes.add(type.getName());
}
for (OClass clazz : classes) {
try {
if (clazz.getName().equals(OSerializationHelper.BINARY_WRAPPER_CLASSNAME)) {
// ignore binary wrapper class
continue;
}
QName typeName = ONamespaceMap.decode(clazz.getName());
// ONameUtil.decodeName(clazz.getName());
if (allowedTypes.contains(typeName) && db.countClass(clazz.getName()) > 0) {
TypeDefinition type = schemas.getType(typeName);
if (type != null) {
result.add(type);
} else {
log.error(MessageFormat.format("Could not resolve type with name {0}", typeName));
}
}
} catch (Throwable e) {
log.error("Could not decode class name to type identifier", e);
}
}
} finally {
dbref.dispose();
}
return result;
}
Aggregations