Search in sources :

Example 1 with EclipseResourcesUtil

use of org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil in project InformationSystem by ObeoNetwork.

the class ValidateRequirementsHandler method executeValidation.

private void executeValidation(Collection<EObject> selectedEObjects) {
    ValidationDelegateClientSelector.running = true;
    IBatchValidator validator = ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH);
    // include live constraints, also, in batch validation
    validator.setOption(IBatchValidator.OPTION_INCLUDE_LIVE_CONSTRAINTS, true);
    final IStatus status = validator.validate(selectedEObjects);
    ValidationDelegateClientSelector.running = false;
    // Markers creation
    EclipseResourcesUtil eclipseResourcesUtil = new EclipseResourcesUtil();
    eclipseResourcesUtil.deleteMarkers(resourceSet);
    BasicDiagnostic parentDiagnostic = new BasicDiagnostic(EObjectValidator.DIAGNOSTIC_SOURCE, 0, EMFEditUIPlugin.INSTANCE.getString("_UI_DiagnosisOfNObjects_message", new String[] { Integer.toString(selectedEObjects.size()) }), selectedEObjects.toArray());
    for (IStatus childStatus : status.getChildren()) {
        EObject target = (EObject) ((IConstraintStatus) childStatus).getTarget();
        Diagnostic childDiagnostic = new BasicDiagnostic(// Severity
        childStatus.getSeverity(), // Source
        childStatus.getPlugin(), // Code
        childStatus.getCode(), // Message
        childStatus.getMessage(), // Data
        new Object[] { ((IConstraintStatus) childStatus).getTarget() });
        parentDiagnostic.add(childDiagnostic);
        eclipseResourcesUtil.createMarkers(target.eResource(), childDiagnostic);
    }
    if (parentDiagnostic.getChildren().isEmpty()) {
        MessageDialog.openInformation(shell, "No errors during validation", "No errors found when validating requirements	");
    } else {
        DiagnosticDialog.open(shell, "Errors during validation", "Errors have been encountered during validation", parentDiagnostic);
    }
    ValidationDelegateClientSelector.running = false;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) IBatchValidator(org.eclipse.emf.validation.service.IBatchValidator) EObject(org.eclipse.emf.ecore.EObject) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EclipseResourcesUtil(org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EObject (org.eclipse.emf.ecore.EObject)1 EclipseResourcesUtil (org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil)1 IBatchValidator (org.eclipse.emf.validation.service.IBatchValidator)1