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);
}
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);
}
}
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;
}
Aggregations