How to use EVL validation from GEF [message #870772] |
Wed, 09 May 2012 11:23  |
Eclipse User |
|
|
|
Currently I am not using GMF, but would like to use EVL for my (live) validations.
Is this possible? I do not seem able to find any documentation on this subject.
Note: I already removed the GmfMarkerResolver class to remove the dependency of org.eclipse.epsilon.evl.emf.validation on GMF (see bug #378998 (still no links, sorry))
|
|
|
|
Re: How to use EVL validation from GEF [message #870965 is a reply to message #870918] |
Thu, 10 May 2012 07:22  |
Eclipse User |
|
|
|
I managed to get it working for GEF, so I'll put some notes here for others.
Registering my EVL file in the EMF validation did not cause too much problems using the org.eclipse.epsilon.evl.emf.validation.org.eclipse.epsilon.evl.emf.validation extension.
Finding out how to activate this registered EVL file, was a bigger challenge.
In the end I found out about the Diagnostician class (in emf.ecore.util) and that is it able to 'find' the EVL file and use it for its diagnostics.
I created a AbstractModelConstraint that uses the Diagnostician class for its validation and convert the result into a status:
public class MyConstraint extends AbstractModelConstraint
{
@Override
public IStatus validate(IValidationContext ctx)
{
Diagnostician diagnostician = new Diagnostician();
Diagnostic diagnostics = diagnostician.validate(ctx.getTarget());
if (diagnostics.getSeverity() == Diagnostic.OK)
{
return createSuccessReport(ctx, target);
}
List<Diagnostic> diagnosticsChildren = diagnostics.getChildren();
if (diagnosticsChildren.size() == 1)
{
Diagnostic child = diagnosticsChildren.get(0);
return createFailureReport(ctx, target, child.getMessage());
}
// Create multiple failure reports and combine into a multistatus report
List<IStatus> statusList = new ArrayList<IStatus>(diagnosticsChildren.size());
for (Diagnostic child : diagnosticsChildren)
{
statusList.add(createFailureReport(ctx, target, child.getMessage()));
}
return ConstraintStatus.createMultiStatus(ctx, statusList);
}
}
The constraint can be registered using the org.eclipse.emf.validation.constraintProviders extension and a validation listener can be used to do something with the validation result (eg creating markers)
|
|
|
Powered by
FUDForum. Page generated in 0.04775 seconds