Search in sources :

Example 46 with TypeDefinition

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);
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) TreePath(org.eclipse.jface.viewers.TreePath) Pair(eu.esdihumboldt.util.Pair)

Example 47 with TypeDefinition

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);
}
Also used : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) Message(eu.esdihumboldt.hale.common.core.report.Message) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Pair(eu.esdihumboldt.util.Pair) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 48 with TypeDefinition

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

Example 49 with TypeDefinition

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.");
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) TypeIndex(eu.esdihumboldt.hale.common.schema.model.TypeIndex) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 50 with TypeDefinition

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;
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) QName(javax.xml.namespace.QName) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12