Search in sources :

Example 1 with IBatchValidator

use of org.eclipse.emf.validation.service.IBatchValidator 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)

Example 2 with IBatchValidator

use of org.eclipse.emf.validation.service.IBatchValidator in project Palladio-Editors-Sirius by PalladioSimulator.

the class SemanticElementsValidateAction method createBatchValidator.

private static IBatchValidator createBatchValidator() {
    IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH);
    validator.setIncludeLiveConstraints(true);
    return validator;
}
Also used : IBatchValidator(org.eclipse.emf.validation.service.IBatchValidator)

Example 3 with IBatchValidator

use of org.eclipse.emf.validation.service.IBatchValidator in project Palladio-Editors-Sirius by PalladioSimulator.

the class SemanticElementsValidateAction method validate.

/**
 * @was-generated NOT it is not necessary to call the createMarkers operation since the markers are automatically added
 *                for EMF validation. <br/>
 *                Validation is run on view elements and its children.<br/>
 */
private static void validate(DiagramEditPart diagramEditPart, View view) {
    IFile target = getFileToMark(diagramEditPart, view);
    if (target != null) {
        SiriusMarkerNavigationProvider.deleteMarkers(target);
    }
    if (view.isSetElement()) {
        final EObject element = view.getElement();
        if (element != null) {
            IBatchValidator validator = createBatchValidator();
            IStatus status = validator.validate(element);
            createMarkers(target, status, diagramEditPart);
            if (element instanceof DSemanticDecorator) {
                List<EObject> elementsToValidate = new ArrayList<>();
                final EObject semanticElement = ((DSemanticDecorator) element).getTarget();
                elementsToValidate.add(semanticElement);
                createMarkers(target, runEMFValidator(semanticElement), diagramEditPart);
                for (final EObject representationElement : AllContents.of(view.getElement(), ViewpointPackage.eINSTANCE.getDRepresentationElement())) {
                    elementsToValidate.addAll(((DRepresentationElement) representationElement).getSemanticElements());
                }
                validator.setTraversalStrategy(new ITraversalStrategy.Flat());
                IStatus status2 = validator.validate(elementsToValidate);
                createMarkers(target, status2, diagramEditPart);
            }
        }
    }
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) EObject(org.eclipse.emf.ecore.EObject) IBatchValidator(org.eclipse.emf.validation.service.IBatchValidator) ITraversalStrategy(org.eclipse.emf.validation.service.ITraversalStrategy) ArrayList(java.util.ArrayList)

Aggregations

IBatchValidator (org.eclipse.emf.validation.service.IBatchValidator)3 IStatus (org.eclipse.core.runtime.IStatus)2 EObject (org.eclipse.emf.ecore.EObject)2 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EclipseResourcesUtil (org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil)1 ITraversalStrategy (org.eclipse.emf.validation.service.ITraversalStrategy)1 DSemanticDecorator (org.eclipse.sirius.viewpoint.DSemanticDecorator)1