Search in sources :

Example 6 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class InstanceValidationReportDetailsPage method createControls.

/**
 * @see CustomReportDetailsPage#createControls(Composite)
 */
@Override
public Control createControls(Composite parent) {
    // filtered tree sets itself GridData, so set layout to gridlayout
    parent.setLayout(GridLayoutFactory.fillDefaults().create());
    // create pattern filter for FilteredTree
    PatternFilter filter = new TreePathPatternFilter();
    filter.setIncludeLeadingWildcard(true);
    // create FilteredTree
    FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    treeViewer = filteredTree.getViewer();
    // set content provider
    contentProvider = new InstanceValidationReportDetailsContentProvider();
    treeViewer.setContentProvider(contentProvider);
    // set label provider
    treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
    // set comparator
    treeViewer.setComparator(new ViewerComparator() {

        /**
         * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
         */
        @Override
        public int category(Object element) {
            if (element instanceof QName || element instanceof Definition<?>)
                // Path
                return 0;
            else if (element instanceof String)
                // Category
                return 1;
            else
                // InstanceValidationMessage
                return 2;
        }
    });
    // add menu on right-click
    MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (getValidSelection() == null)
                return;
            // selection is valid, offer link to transformed data view
            manager.add(new ShowExampleAction());
        }
    });
    // remove previous menus
    menuMgr.setRemoveAllWhenShown(true);
    // add menu to tree
    treeViewer.getTree().setMenu(menu);
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            showSelectionInDataView();
        }
    });
    Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
    reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
    return filteredTree;
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) QName(javax.xml.namespace.QName) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) Image(org.eclipse.swt.graphics.Image) IMenuListener(org.eclipse.jface.action.IMenuListener) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 7 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class InspireInstanceWriter method writeAdditionalElements.

/**
 * @see StreamGmlWriter#writeAdditionalElements(XMLStreamWriter,
 *      TypeDefinition, IOReporter)
 */
@Override
protected void writeAdditionalElements(XMLStreamWriter writer, TypeDefinition containerDefinition, IOReporter reporter) throws XMLStreamException {
    super.writeAdditionalElements(writer, containerDefinition, reporter);
    // determine INSPIRE identifier and metadata names
    Path<Definition<?>> localIdPath = new DefinitionAccessor(containerDefinition).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
    QName identifierName = localIdPath.getElements().get(1).getName();
    Definition<?> internalIdentifierDef = localIdPath.getElements().get(2);
    QName internalIdentifierName = internalIdentifierDef.getName();
    QName localIdName = localIdPath.getElements().get(3).getName();
    Path<Definition<?>> namespacePath = new DefinitionAccessor(internalIdentifierDef).findChildren("namespace").eval(false);
    QName namespaceName = namespacePath.getElements().get(1).getName();
    Path<Definition<?>> metadataPath = new DefinitionAccessor(containerDefinition).findChildren("metadata").eval(false);
    QName metadataName = metadataPath.getElements().get(1).getName();
    // write INSPIRE identifier
    writer.writeStartElement(identifierName.getNamespaceURI(), identifierName.getLocalPart());
    writer.writeStartElement(internalIdentifierName.getNamespaceURI(), internalIdentifierName.getLocalPart());
    writer.writeStartElement(localIdName.getNamespaceURI(), localIdName.getLocalPart());
    writer.writeCharacters(getParameter(PARAM_SPATIAL_DATA_SET_LOCALID).as(String.class, ""));
    writer.writeEndElement();
    writer.writeStartElement(namespaceName.getNamespaceURI(), namespaceName.getLocalPart());
    writer.writeCharacters(getParameter(PARAM_SPATIAL_DATA_SET_NAMESPACE).as(String.class, ""));
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    // write metadata
    writer.writeStartElement(metadataName.getNamespaceURI(), metadataName.getLocalPart());
    // retrieve metadata element (if any)
    Element metadataElement = getParameter(PARAM_SPATIAL_DATA_SET_METADATA_DOM).as(Element.class);
    // metadata from file (if any)
    if (metadataElement == null) {
        String metadataFile = getParameter(PARAM_SPATIAL_DATA_SET_METADATA_FILE).as(String.class);
        if (metadataFile != null && !metadataFile.isEmpty()) {
            try (InputStream input = new BufferedInputStream(new FileInputStream(new File(metadataFile)))) {
                metadataElement = findMetadata(input, reporter);
            } catch (IOException e) {
                reporter.warn(new IOMessageImpl("Could not load specified metadata file.", e));
            }
        }
    }
    if (metadataElement != null) {
        try {
            writeElement(metadataElement, writer);
        } catch (TransformerException e) {
            reporter.warn(new IOMessageImpl("Couldn't include specified metadata file.", e));
        }
    } else {
        writer.writeAttribute(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil", "true");
    }
    writer.writeEndElement();
}
Also used : QName(javax.xml.namespace.QName) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) Element(org.w3c.dom.Element) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) DefinitionAccessor(eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 8 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition 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 9 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition 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 10 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class CodeListAssocationFactory method restore.

@Override
public CodeListAssociation restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    // is it a simple value? (single String code list reference)
    String single = value.as(String.class);
    if (single != null) {
        return new CodeListAssociation(Collections.singleton(single));
    }
    // is it a value list? (multiple String code list references)
    ValueList list = value.as(ValueList.class);
    if (list != null) {
        List<String> refList = list.stream().map(val -> val.as(String.class)).filter(val -> val != null).collect(Collectors.toList());
        return new CodeListAssociation(refList);
    }
    // fall-back
    return new CodeListAssociation();
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) List(java.util.List) ClassResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ClassResolver) TypeResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeResolver) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation) StreamSupport(java.util.stream.StreamSupport) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeReferenceBuilder(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeReferenceBuilder) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Value(eu.esdihumboldt.hale.common.core.io.Value) ValueConstraintFactory(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ValueConstraintFactory) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation)

Aggregations

Definition (eu.esdihumboldt.hale.common.schema.model.Definition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)4 QName (javax.xml.namespace.QName)4 DefinitionAccessor (eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor)3 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)3 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)2 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)2 Pair (eu.esdihumboldt.util.Pair)2 List (java.util.List)2 GridData (org.eclipse.swt.layout.GridData)2 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)1 ChildContextType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ChildContextType)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1