Search in sources :

Example 1 with InstanceValidationReport

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

the class DefinitionInstanceLabelProvider method update.

/**
 * @see CellLabelProvider#update(ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    TreePath treePath = cell.getViewerRow().getTreePath();
    InstanceEntry entry = findInstanceEntry(treePath);
    Object value = entry.value;
    InstanceValidationReport report = null;
    // If childDef is null we are at the top element.
    if (entry.definition && entry.childDef == null) {
        report = validator.validate(instance);
    }
    boolean hasValue = false;
    if (entry.definition && value instanceof Instance) {
        hasValue = ((Instance) value).getValue() != null;
    } else if (!entry.definition && treePath.getSegmentCount() == 1) {
        // metadata root
        if (instance.getMetaDataNames().isEmpty()) {
            hasValue = true;
            value = 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);
    }
    // mark cell if there are other values
    if (entry.valueCount > 1) {
        String decoration = " " + MessageFormat.format(MULTIPLE_VALUE_FORMAT, entry.choice + 1, entry.valueCount);
        styledString.append(decoration, StyledString.COUNTER_STYLER);
    }
    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 : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) Group(eu.esdihumboldt.hale.common.instance.model.Group) TreePath(org.eclipse.jface.viewers.TreePath) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 2 with InstanceValidationReport

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

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

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

the class InstanceValidationStatusAction method createListeners.

/**
 * Registers needed listeners.
 */
private void createListeners() {
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    is.addListener(new InstanceServiceAdapter() {

        @Override
        public void datasetAboutToChange(DataSet type) {
            report = null;
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    updateStatus();
                }
            });
        }
    });
    final InstanceValidationService ivs = PlatformUI.getWorkbench().getService(InstanceValidationService.class);
    ivs.addListener(new InstanceValidationListener() {

        @Override
        public void instancesValidated(InstanceValidationReport report) {
            InstanceValidationStatusAction.this.report = report;
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    updateStatus();
                }
            });
        }

        @Override
        public void validationEnabledChange() {
        // don't care
        }
    });
}
Also used : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) InstanceServiceAdapter(eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter) InstanceValidationService(eu.esdihumboldt.hale.ui.service.instance.validation.InstanceValidationService) InstanceValidationListener(eu.esdihumboldt.hale.ui.service.instance.validation.InstanceValidationListener)

Example 5 with InstanceValidationReport

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

the class DefinitionInstanceLabelProvider method getToolTipText.

/**
 * @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
 */
@Override
public String getToolTipText(Object element) {
    if (element instanceof EntityDefinition) {
        InstanceValidationReport report = validator.validate(instance);
        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);
    } else
        return null;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Message(eu.esdihumboldt.hale.common.core.report.Message) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)

Aggregations

InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)5 Message (eu.esdihumboldt.hale.common.core.report.Message)2 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)2 Group (eu.esdihumboldt.hale.common.instance.model.Group)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)2 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)2 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 Pair (eu.esdihumboldt.util.Pair)2 StyledString (org.eclipse.jface.viewers.StyledString)2 TreePath (org.eclipse.jface.viewers.TreePath)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)1 InstanceServiceAdapter (eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter)1 InstanceValidationListener (eu.esdihumboldt.hale.ui.service.instance.validation.InstanceValidationListener)1 InstanceValidationService (eu.esdihumboldt.hale.ui.service.instance.validation.InstanceValidationService)1