Search in sources :

Example 1 with Validation

use of org.eclipse.sirius.components.validation.Validation in project sirius-components by eclipse-sirius.

the class ValidationComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    ValidationDescription validationDescription = this.props.getValidationDescription();
    Optional<Validation> optionalPreviousValidation = this.props.getPreviousValidation();
    // $NON-NLS-1$
    String id = optionalPreviousValidation.map(Validation::getId).orElseGet(() -> "validation");
    String label = validationDescription.getLabel();
    List<?> diagnostics = validationDescription.getDiagnosticsProvider().apply(variableManager);
    List<Element> children = new ArrayList<>(diagnostics.size());
    for (Object diagnostic : diagnostics) {
        DiagnosticComponentProps diagnosticComponentProps = new DiagnosticComponentProps(diagnostic, validationDescription);
        children.add(new Element(DiagnosticComponent.class, diagnosticComponentProps));
    }
    // @formatter:off
    ValidationElementProps validationElementProps = ValidationElementProps.newValidationElementProps(id).label(label).descriptionId(validationDescription.getId()).children(children).build();
    return new Element(ValidationElementProps.TYPE, validationElementProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Validation(org.eclipse.sirius.components.validation.Validation) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) ValidationDescription(org.eclipse.sirius.components.validation.description.ValidationDescription) ValidationElementProps(org.eclipse.sirius.components.validation.elements.ValidationElementProps)

Example 2 with Validation

use of org.eclipse.sirius.components.validation.Validation in project sirius-components by eclipse-sirius.

the class ValidationEventProcessor method refresh.

@Override
public void refresh(ChangeDescription changeDescription) {
    if (this.shouldRefresh(changeDescription)) {
        long start = System.currentTimeMillis();
        Validation validation = this.refreshValidation();
        this.validationContext.update(validation);
        if (this.sink.currentSubscriberCount() > 0) {
            EmitResult emitResult = this.sink.tryEmitNext(new ValidationRefreshedEventPayload(changeDescription.getInput().getId(), validation));
            if (emitResult.isFailure()) {
                // $NON-NLS-1$
                String pattern = "An error has occurred while emitting a ValidationRefreshedEventPayload: {}";
                this.logger.warn(pattern, emitResult);
            }
        }
        long end = System.currentTimeMillis();
        this.timer.record(end - start, TimeUnit.MILLISECONDS);
    }
}
Also used : Validation(org.eclipse.sirius.components.validation.Validation) ValidationRefreshedEventPayload(org.eclipse.sirius.components.collaborative.validation.dto.ValidationRefreshedEventPayload) EmitResult(reactor.core.publisher.Sinks.EmitResult)

Example 3 with Validation

use of org.eclipse.sirius.components.validation.Validation in project sirius-components by eclipse-sirius.

the class ValidationEventProcessor method refreshValidation.

private Validation refreshValidation() {
    VariableManager variableManager = new VariableManager();
    variableManager.put(IEditingContext.EDITING_CONTEXT, this.editingContext);
    ValidationComponentProps validationComponentProps = new ValidationComponentProps(variableManager, this.validationDescription, Optional.ofNullable(this.validationContext.getValidation()));
    Element element = new Element(ValidationComponent.class, validationComponentProps);
    Validation validation = new ValidationRenderer().render(element);
    // $NON-NLS-1$
    this.logger.trace("Validation refreshed: {}", this.editingContext.getId());
    return validation;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) ValidationComponentProps(org.eclipse.sirius.components.validation.components.ValidationComponentProps) Validation(org.eclipse.sirius.components.validation.Validation) Element(org.eclipse.sirius.components.representations.Element) ValidationRenderer(org.eclipse.sirius.components.validation.render.ValidationRenderer)

Aggregations

Validation (org.eclipse.sirius.components.validation.Validation)3 Element (org.eclipse.sirius.components.representations.Element)2 VariableManager (org.eclipse.sirius.components.representations.VariableManager)2 ArrayList (java.util.ArrayList)1 ValidationRefreshedEventPayload (org.eclipse.sirius.components.collaborative.validation.dto.ValidationRefreshedEventPayload)1 ValidationComponentProps (org.eclipse.sirius.components.validation.components.ValidationComponentProps)1 ValidationDescription (org.eclipse.sirius.components.validation.description.ValidationDescription)1 ValidationElementProps (org.eclipse.sirius.components.validation.elements.ValidationElementProps)1 ValidationRenderer (org.eclipse.sirius.components.validation.render.ValidationRenderer)1 EmitResult (reactor.core.publisher.Sinks.EmitResult)1