Search in sources :

Example 1 with InstanceValidationMessage

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.

the class InstanceValidationReportDetailsContentProvider method getChildren.

/**
 * @see ITreePathContentProvider#getChildren(TreePath)
 */
@Override
public Object[] getChildren(TreePath parentPath) {
    Set<Object> children = childCache.get(parentPath);
    if (children == null) {
        Collection<InstanceValidationMessage> ivms = messages.get(parentPath);
        if (!ivms.isEmpty()) {
            children = new HashSet<Object>();
            // count of added messages
            int messageCount = 0;
            for (InstanceValidationMessage message : ivms) {
                if (message.getPath().size() > parentPath.getSegmentCount() - 1) {
                    // path not done, add next segment
                    QName name = message.getPath().get(parentPath.getSegmentCount() - 1);
                    Object child = name;
                    Object parent = parentPath.getLastSegment();
                    if (parent instanceof Definition<?>) {
                        ChildDefinition<?> childDef = DefinitionUtil.getChild((Definition<?>) parent, name);
                        if (childDef != null)
                            child = childDef;
                    }
                    children.add(child);
                    messages.put(parentPath.createChildPath(child), message);
                } else if (message.getPath().size() == parentPath.getSegmentCount() - 1) {
                    // path done, go by category
                    String category = message.getCategory();
                    children.add(category);
                    messages.put(parentPath.createChildPath(category), message);
                } else {
                    // all done, add as child
                    if (messageCount < LIMIT) {
                        children.add(message);
                        messageCount++;
                    } else {
                        limitedPaths.add(parentPath);
                    }
                }
            }
        } else
            children = Collections.emptySet();
        childCache.put(parentPath, children);
    }
    return children.toArray();
}
Also used : QName(javax.xml.namespace.QName) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)

Example 2 with InstanceValidationMessage

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.

the class InstanceValidationReportDetailsLabelProvider method update.

/**
 * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    String label = getText(element);
    int newLine = label.indexOf('\n');
    if (newLine > -1)
        label = label.substring(0, newLine) + " ...";
    StyledString text = new StyledString(label);
    if (!(element instanceof InstanceValidationMessage)) {
        TreePath treePath = cell.getViewerRow().getTreePath();
        boolean isLimited = contentProvider.isLimited(treePath);
        text.append(' ');
        if (!isLimited)
            text.append(MessageFormat.format("({0} warnings)", contentProvider.getMessageCount(treePath)), StyledString.COUNTER_STYLER);
        else
            text.append(MessageFormat.format("(showing {0} of {1})", InstanceValidationReportDetailsContentProvider.LIMIT, contentProvider.getMessageCount(treePath)), StyledString.COUNTER_STYLER);
    }
    cell.setText(text.getString());
    cell.setStyleRanges(text.getStyleRanges());
    cell.setImage(getImage(element));
    super.update(cell);
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 3 with InstanceValidationMessage

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage 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 4 with InstanceValidationMessage

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.

the class InstanceValidationReportDetailsContentProvider method inputChanged.

/**
 * @see ITreePathContentProvider#inputChanged(Viewer, Object, Object)
 */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    childCache.clear();
    messages.clear();
    limitedPaths.clear();
    if (newInput instanceof Collection<?>) {
        SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
        TreePath emptyPath = new TreePath(new Object[0]);
        for (Object o : (Collection<?>) newInput) {
            if (o instanceof InstanceValidationMessage) {
                InstanceValidationMessage message = ((InstanceValidationMessage) o);
                Set<Object> baseTypes = childCache.get(emptyPath);
                if (baseTypes == null) {
                    baseTypes = new HashSet<Object>();
                    childCache.put(emptyPath, baseTypes);
                }
                // XXX maybe expand messages with SSID?
                TypeDefinition typeDef = null;
                if (message.getType() != null) {
                    typeDef = ss.getSchemas(SchemaSpaceID.TARGET).getType(message.getType());
                }
                // use typeDef if available, QName otherwise
                Object use = typeDef == null ? message.getType() : typeDef;
                if (use == null) {
                    // fall-back to generic category
                    use = "General";
                }
                baseTypes.add(use);
                messages.put(new TreePath(new Object[] { use }), message);
            }
        }
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) Collection(java.util.Collection) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 5 with InstanceValidationMessage

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage in project hale by halestudio.

the class InstanceValidationReportDetailsPage method getValidSelection.

/**
 * Returns a valid instance selection for the current selection of the tree
 * viewer. Returns <code>null</code> if there is none.
 *
 * @return a valid instance selection for the current selection of the tree
 *         viewer or <code>null</code>
 */
private InstanceSelection getValidSelection() {
    ISelection viewerSelection = treeViewer.getSelection();
    if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty())
        return null;
    ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
    // XXX use all paths
    TreePath firstPath = treeSelection.getPaths()[0];
    // instead of first
    // only?
    InstanceValidationMessage firstMessage;
    Iterator<InstanceValidationMessage> restIter;
    if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
        firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
        restIter = Iterators.emptyIterator();
    } else {
        Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]);
        if (messages.isEmpty())
            // shouldn't happen, but doesn't really matter
            return null;
        restIter = messages.iterator();
        firstMessage = restIter.next();
    }
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    // check first message for valid instance reference
    if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null)
        return null;
    Set<InstanceReference> references = new HashSet<InstanceReference>();
    references.add(firstMessage.getInstanceReference());
    while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());
    return new DefaultInstanceSelection(references.toArray());
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) ISelection(org.eclipse.jface.viewers.ISelection) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) HashSet(java.util.HashSet) DefaultInstanceSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)

Aggregations

InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)6 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)3 TreePath (org.eclipse.jface.viewers.TreePath)3 Message (eu.esdihumboldt.hale.common.core.report.Message)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)2 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 DefaultInstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage)1 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)1 DefaultInstanceSelection (eu.esdihumboldt.hale.ui.selection.impl.DefaultInstanceSelection)1 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)1 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)1 Pair (eu.esdihumboldt.util.Pair)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1 StyledString (org.eclipse.jface.viewers.StyledString)1