Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » OCL live validation in generated tree editor
OCL live validation in generated tree editor [message #870236] Mon, 07 May 2012 11:57 Go to next message
Eclipse UserFriend
Hi,
regarding to
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/oclValidationTutorial.html
I tried to specify OCL constraints for my metamodel. I generated the
tree editor and expected the validation to be invoked after changing a
model. But it doesn't. Can you help me to identify my fault? Here are
the defined constraints in the plugin.xml:

<extension
point="org.eclipse.emf.validation.constraintProviders">
<category
id="my.validation/ocl"
mandatory="true"
name="Static Semantics for Operators">
</category>
<constraintProvider
cache="true">
<package namespaceUri="http://www.qualitune.org/operators"/>
<constraints categories="my.validation/ocl">
<constraint
id="org.qualitune.evolution.operators.validation.operationFeatureXOR"
isEnabledByDefault="true"
lang="OCL"
mode="Live"
name="XOR between operation and structuralFeature"
severity="ERROR"
statusCode="1">
<message>
It is only allowed to reference either an operation or a
structural feature (XOR) for "{0}".
</message>
<target
class="QueryVariable"></target>
<![CDATA[
self.operation = null xor self.structuralFeature = null
]]>
</constraint>
<constraint
id="org.qualitune.evolution.operators.validation.testConstraint"
isEnabledByDefault="true"
lang="OCL"
mode="Live"
name="Test constraint"
severity="ERROR"
statusCode="1">
<message>
Blah.
</message>
<target class="QueryVariable"/>
<![CDATA[
not(self.name = null)
]]>
</constraint>
</constraints>
</constraintProvider>
</extension>
<extension point="org.eclipse.emf.validation.constraintBindings">
<clientContext
default="false"
id="my.clientContext1">
<enablement></enablement>
</clientContext>
<binding
category="my.validation/ocl"
context="my.clientContext1">
</binding>
</extension>

The problem is that nothing happens when I change a model and sae it. At
least the second constraint must be violated if no name is set. What am
I doing wrong?

best regards,
Gilbert
Re: OCL live validation in generated tree editor [message #870404 is a reply to message #870236] Tue, 08 May 2012 04:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Gilbert,

Better to ask on the OCL newsgroup how best to make use of OCL for
specifying constraints.


On 07/05/2012 1:57 PM, Gilbert Mirenque wrote:
> Hi,
> regarding to
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/oclValidationTutorial.html
> I tried to specify OCL constraints for my metamodel. I generated the
> tree editor and expected the validation to be invoked after changing a
> model. But it doesn't. Can you help me to identify my fault? Here are
> the defined constraints in the plugin.xml:
>
> <extension
> point="org.eclipse.emf.validation.constraintProviders">
> <category
> id="my.validation/ocl"
> mandatory="true"
> name="Static Semantics for Operators">
> </category>
> <constraintProvider
> cache="true">
> <package namespaceUri="http://www.qualitune.org/operators"/>
> <constraints categories="my.validation/ocl">
> <constraint
> id="org.qualitune.evolution.operators.validation.operationFeatureXOR"
> isEnabledByDefault="true"
> lang="OCL"
> mode="Live"
> name="XOR between operation and structuralFeature"
> severity="ERROR"
> statusCode="1">
> <message>
> It is only allowed to reference either an operation or a
> structural feature (XOR) for "{0}".
> </message>
> <target
> class="QueryVariable"></target>
> <![CDATA[
> self.operation = null xor self.structuralFeature = null
> ]]>
> </constraint>
> <constraint
> id="org.qualitune.evolution.operators.validation.testConstraint"
> isEnabledByDefault="true"
> lang="OCL"
> mode="Live"
> name="Test constraint"
> severity="ERROR"
> statusCode="1">
> <message>
> Blah.
> </message>
> <target class="QueryVariable"/>
> <![CDATA[
> not(self.name = null)
> ]]>
> </constraint>
> </constraints>
> </constraintProvider>
> </extension>
> <extension point="org.eclipse.emf.validation.constraintBindings">
> <clientContext
> default="false"
> id="my.clientContext1">
> <enablement></enablement>
> </clientContext>
> <binding
> category="my.validation/ocl"
> context="my.clientContext1">
> </binding>
> </extension>
>
> The problem is that nothing happens when I change a model and sae it. At
> least the second constraint must be violated if no name is set. What am
> I doing wrong?
>
> best regards,
> Gilbert


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: OCL live validation in generated tree editor [message #870416 is a reply to message #870236] Tue, 08 May 2012 06:16 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are using very old reference material.

Embedding OCL as CDATA was a nightmare in a variety of ways.

Helios introduced EMF delegates with corresponding OCL delegates that
solved EMF integration difficulties.
An Xtext-based OCLinEcore editor to maintain them solved ergonomic entry
challenges.

Follow the OCLinEcore tutorial in the OCL Documentation.

Regards

Ed Willink


On 07/05/2012 12:57, Gilbert Mirenque wrote:
> Hi,
> regarding to
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/oclValidationTutorial.html
> I tried to specify OCL constraints for my metamodel. I generated the
> tree editor and expected the validation to be invoked after changing a
> model. But it doesn't. Can you help me to identify my fault? Here are
> the defined constraints in the plugin.xml:
>
> <extension
> point="org.eclipse.emf.validation.constraintProviders">
> <category
> id="my.validation/ocl"
> mandatory="true"
> name="Static Semantics for Operators">
> </category>
> <constraintProvider
> cache="true">
> <package namespaceUri="http://www.qualitune.org/operators"/>
> <constraints categories="my.validation/ocl">
> <constraint
> id="org.qualitune.evolution.operators.validation.operationFeatureXOR"
> isEnabledByDefault="true"
> lang="OCL"
> mode="Live"
> name="XOR between operation and structuralFeature"
> severity="ERROR"
> statusCode="1">
> <message>
> It is only allowed to reference either an operation or a
> structural feature (XOR) for "{0}".
> </message>
> <target
> class="QueryVariable"></target>
> <![CDATA[
> self.operation = null xor self.structuralFeature = null
> ]]>
> </constraint>
> <constraint
> id="org.qualitune.evolution.operators.validation.testConstraint"
> isEnabledByDefault="true"
> lang="OCL"
> mode="Live"
> name="Test constraint"
> severity="ERROR"
> statusCode="1">
> <message>
> Blah.
> </message>
> <target class="QueryVariable"/>
> <![CDATA[
> not(self.name = null)
> ]]>
> </constraint>
> </constraints>
> </constraintProvider>
> </extension>
> <extension point="org.eclipse.emf.validation.constraintBindings">
> <clientContext
> default="false"
> id="my.clientContext1">
> <enablement></enablement>
> </clientContext>
> <binding
> category="my.validation/ocl"
> context="my.clientContext1">
> </binding>
> </extension>
>
> The problem is that nothing happens when I change a model and sae it. At
> least the second constraint must be violated if no name is set. What am
> I doing wrong?
>
> best regards,
> Gilbert
Re: OCL live validation in generated tree editor [message #870998 is a reply to message #870416] Thu, 10 May 2012 13:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,
thanks for the hint. This works now. But, how is it possible to activate
those constraints as live constraints, so that they will be evaluated
after saving or parsing (for a textual editor)?

best regards,
Gilbert

Ed Willink wrote:
> Hi
>
> You are using very old reference material.
>
> Embedding OCL as CDATA was a nightmare in a variety of ways.
>
> Helios introduced EMF delegates with corresponding OCL delegates that
> solved EMF integration difficulties.
> An Xtext-based OCLinEcore editor to maintain them solved ergonomic entry
> challenges.
>
> Follow the OCLinEcore tutorial in the OCL Documentation.
>
> Regards
>
> Ed Willink
>
>
> On 07/05/2012 12:57, Gilbert Mirenque wrote:
>> Hi,
>> regarding to
>> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/oclValidationTutorial.html
>>
>> I tried to specify OCL constraints for my metamodel. I generated the
>> tree editor and expected the validation to be invoked after changing a
>> model. But it doesn't. Can you help me to identify my fault? Here are
>> the defined constraints in the plugin.xml:
>>
>> <extension
>> point="org.eclipse.emf.validation.constraintProviders">
>> <category
>> id="my.validation/ocl"
>> mandatory="true"
>> name="Static Semantics for Operators">
>> </category>
>> <constraintProvider
>> cache="true">
>> <package namespaceUri="http://www.qualitune.org/operators"/>
>> <constraints categories="my.validation/ocl">
>> <constraint
>> id="org.qualitune.evolution.operators.validation.operationFeatureXOR"
>> isEnabledByDefault="true"
>> lang="OCL"
>> mode="Live"
>> name="XOR between operation and structuralFeature"
>> severity="ERROR"
>> statusCode="1">
>> <message>
>> It is only allowed to reference either an operation or a
>> structural feature (XOR) for "{0}".
>> </message>
>> <target
>> class="QueryVariable"></target>
>> <![CDATA[
>> self.operation = null xor self.structuralFeature =
>> null
>> ]]>
>> </constraint>
>> <constraint
>> id="org.qualitune.evolution.operators.validation.testConstraint"
>> isEnabledByDefault="true"
>> lang="OCL"
>> mode="Live"
>> name="Test constraint"
>> severity="ERROR"
>> statusCode="1">
>> <message>
>> Blah.
>> </message>
>> <target class="QueryVariable"/>
>> <![CDATA[
>> not(self.name = null)
>> ]]>
>> </constraint>
>> </constraints>
>> </constraintProvider>
>> </extension>
>> <extension point="org.eclipse.emf.validation.constraintBindings">
>> <clientContext
>> default="false"
>> id="my.clientContext1">
>> <enablement></enablement>
>> </clientContext>
>> <binding
>> category="my.validation/ocl"
>> context="my.clientContext1">
>> </binding>
>> </extension>
>>
>> The problem is that nothing happens when I change a model and sae it. At
>> least the second constraint must be violated if no name is set. What am
>> I doing wrong?
>>
>> best regards,
>> Gilbert
>
Re: OCL live validation in generated tree editor [message #871352 is a reply to message #870998] Sat, 12 May 2012 10:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I'm afraid that I don't really understand EMFv; the OCL related part is
no longer appropriate and for my purposes simple validation on demand is
adequate.

It may well be that if you use the normal EMFv live/batch facilities and
ignore all OCL aspects of EMFv, it will just work as you require. The
magic of EMF/OCL delegates is that the OCL is integrated as part of the
Ecore model so EMFv needs no help in activating it.

Regards

Ed Willink


On 10/05/2012 14:48, Gilbert Mirenque wrote:
> Hi Ed,
> thanks for the hint. This works now. But, how is it possible to activate
> those constraints as live constraints, so that they will be evaluated
> after saving or parsing (for a textual editor)?
>
> best regards,
> Gilbert
>
> Ed Willink wrote:
>> Hi
>>
>> You are using very old reference material.
>>
>> Embedding OCL as CDATA was a nightmare in a variety of ways.
>>
>> Helios introduced EMF delegates with corresponding OCL delegates that
>> solved EMF integration difficulties.
>> An Xtext-based OCLinEcore editor to maintain them solved ergonomic entry
>> challenges.
>>
>> Follow the OCLinEcore tutorial in the OCL Documentation.
>>
>> Regards
>>
>> Ed Willink
>>
>>
>> On 07/05/2012 12:57, Gilbert Mirenque wrote:
>>> Hi,
>>> regarding to
>>> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.emf.validation.doc/tutorials/oclValidationTutorial.html
>>>
>>> I tried to specify OCL constraints for my metamodel. I generated the
>>> tree editor and expected the validation to be invoked after changing a
>>> model. But it doesn't. Can you help me to identify my fault? Here are
>>> the defined constraints in the plugin.xml:
>>>
>>> <extension
>>> point="org.eclipse.emf.validation.constraintProviders">
>>> <category
>>> id="my.validation/ocl"
>>> mandatory="true"
>>> name="Static Semantics for Operators">
>>> </category>
>>> <constraintProvider
>>> cache="true">
>>> <package namespaceUri="http://www.qualitune.org/operators"/>
>>> <constraints categories="my.validation/ocl">
>>> <constraint
>>> id="org.qualitune.evolution.operators.validation.operationFeatureXOR"
>>> isEnabledByDefault="true"
>>> lang="OCL"
>>> mode="Live"
>>> name="XOR between operation and structuralFeature"
>>> severity="ERROR"
>>> statusCode="1">
>>> <message>
>>> It is only allowed to reference either an operation or a
>>> structural feature (XOR) for "{0}".
>>> </message>
>>> <target
>>> class="QueryVariable"></target>
>>> <![CDATA[
>>> self.operation = null xor self.structuralFeature =
>>> null
>>> ]]>
>>> </constraint>
>>> <constraint
>>> id="org.qualitune.evolution.operators.validation.testConstraint"
>>> isEnabledByDefault="true"
>>> lang="OCL"
>>> mode="Live"
>>> name="Test constraint"
>>> severity="ERROR"
>>> statusCode="1">
>>> <message>
>>> Blah.
>>> </message>
>>> <target class="QueryVariable"/>
>>> <![CDATA[
>>> not(self.name = null)
>>> ]]>
>>> </constraint>
>>> </constraints>
>>> </constraintProvider>
>>> </extension>
>>> <extension point="org.eclipse.emf.validation.constraintBindings">
>>> <clientContext
>>> default="false"
>>> id="my.clientContext1">
>>> <enablement></enablement>
>>> </clientContext>
>>> <binding
>>> category="my.validation/ocl"
>>> context="my.clientContext1">
>>> </binding>
>>> </extension>
>>>
>>> The problem is that nothing happens when I change a model and sae it. At
>>> least the second constraint must be violated if no name is set. What am
>>> I doing wrong?
>>>
>>> best regards,
>>> Gilbert
Re: OCL live validation in generated tree editor [message #874564 is a reply to message #871352] Mon, 21 May 2012 06:55 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

Ed Willink wrote:
> It may well be that if you use the normal EMFv live/batch facilities and
> ignore all OCL aspects of EMFv, it will just work as you require. The
> magic of EMF/OCL delegates is that the OCL is integrated as part of the
> Ecore model so EMFv needs no help in activating it.
That OCL is integrated into the metamodel is what I like best. But I
don't know how to activate OCL delegates as live validation. Well, I
think it's not a OCL issue directly, so maybe I should rename the topic
here? So the question is, how to activate delegates for live validation?

best regards,
Gilbert
Re: OCL live validation in generated tree editor [message #874568 is a reply to message #874564] Mon, 21 May 2012 06:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi<br>
<br>
The nice thing about delegates is that they should be invisible.<br>
<br>
You do live validation just as you would for any other model not
using delegates.<br>
<br>
The only requirement should be ensuring that, if running standalone,
you have replicated the delegate extension point registration
activity.<br>
<br>
From the OCL Documentation for the Ecore binding:<br>
<br>
<i>If you want to use EMF delegates to dispatch OCL, the required
registrations may be provided by <code class="code">org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)</code>.
</i>
<p><i>This may be invoked with a null argument to install the
registrations in the global EPackage.Registry rather than a
specified local registry.</i></p>
    Regards<br>
<br>
        Ed Willink<br>
<br>
<br>
On 21/05/2012 07:55, Gilbert Mirenque wrote:
<blockquote cite="mid:jpcosh$dgp$1@xxxxxxxxe.org" type="cite">
<pre wrap="">Hi Ed,

Ed Willink wrote:
</pre>
<blockquote type="cite">
<pre wrap="">It may well be that if you use the normal EMFv live/batch facilities and
ignore all OCL aspects of EMFv, it will just work as you require. The
magic of EMF/OCL delegates is that the OCL is integrated as part of the
Ecore model so EMFv needs no help in activating it.
</pre>
</blockquote>
<pre wrap="">That OCL is integrated into the metamodel is what I like best. But I
don't know how to activate OCL delegates as live validation. Well, I
think it's not a OCL issue directly, so maybe I should rename the topic
here? So the question is, how to activate delegates for live validation?

best regards,
Gilbert
</pre>
</blockquote>
<br>
</body>
</html>
Re: OCL live validation in generated tree editor [message #874698 is a reply to message #874568] Mon, 21 May 2012 11:34 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,
ok, now I noticed that an implementation of EValidator is generated when
adding OCL annotations to my ecore file. Then I searched for how to
register an EValidator for live validation and found only:

http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering

But this already happens in the generated MyDSLPackageImpl in the init
method. What do you mean with "as you would for any other model not
using delegates"?

best regards,
Gilbert


Ed Willink wrote:
> Hi
>
> The nice thing about delegates is that they should be invisible.
>
> You do live validation just as you would for any other model not using
> delegates.
>
> The only requirement should be ensuring that, if running standalone, you
> have replicated the delegate extension point registration activity.
>
> From the OCL Documentation for the Ecore binding:
>
> /If you want to use EMF delegates to dispatch OCL, the required
> registrations may be provided by
> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|. /
>
> /This may be invoked with a null argument to install the registrations
> in the global EPackage.Registry rather than a specified local registry./
>
> Regards
>
> Ed Willink
>
>
> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>> Hi Ed,
>>
>> Ed Willink wrote:
>>> It may well be that if you use the normal EMFv live/batch facilities and
>>> ignore all OCL aspects of EMFv, it will just work as you require. The
>>> magic of EMF/OCL delegates is that the OCL is integrated as part of the
>>> Ecore model so EMFv needs no help in activating it.
>> That OCL is integrated into the metamodel is what I like best. But I
>> don't know how to activate OCL delegates as live validation. Well, I
>> think it's not a OCL issue directly, so maybe I should rename the topic
>> here? So the question is, how to activate delegates for live validation?
>>
>> best regards,
>> Gilbert
>
Re: OCL live validation in generated tree editor [message #875114 is a reply to message #874698] Tue, 22 May 2012 07:02 Go to previous messageGo to next message
Eclipse UserFriend
Do you have some pointers, Ed? Or anybody else? I cannot really imagine
that no one wanted to try this out.

best regards,
Gilbert
Re: OCL live validation in generated tree editor [message #875265 is a reply to message #874698] Tue, 22 May 2012 12:45 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Gilbert,

That tutorial illustrates the integration of EMF Validation Framework
(extrinsic) constraints into the EMF (intrinsinc) EValidator, by
delegating to an IBatchValidator.

I think you're looking for something that does the opposite:
integrating an EValidator generated (and, yes, already registered by
the EPacakge, itself) into a ILiveValidator's execution.

What you could do is to create a dynamic constraint provider that
discovers the constraints implemented in a package's EValidator and
contributes individual IModelConstraint wrappers for them that present
themselves as "live mode" constraints. Then, you could to implement a
hook that invokes an ILiveValidator upon changes in the model and
reports problems. This might be based on a TransactionalEditingDomain,
which does much of that work for you in its command stack.

Your constraint provider would probably end up looking a lot like what
was implemented for Juno in the UML2 project and integrated into
Papyrus: it's batch-mode validation, but that's a small difference on
the provider side:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=373643 (UML2)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=373644 (Papyrus)

Alternatively, if from the execution of editing commands you can find
out what the affected objects are, you may be able to dramatically
simplify this by just running them through the EValidator in a
command-stack listener. I don't know how feasible that might be.

HTH,

Christian


On 2012-05-21 11:34:46 +0000, Gilbert Mirenque said:

> Hi Ed,
> ok, now I noticed that an implementation of EValidator is generated when
> adding OCL annotations to my ecore file. Then I searched for how to
> register an EValidator for live validation and found only:
>
> http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering
>
>
> But this already happens in the generated MyDSLPackageImpl in the init
> method. What do you mean with "as you would for any other model not
> using delegates"?
>
> best regards,
> Gilbert
>
>
> Ed Willink wrote:
>> Hi
>>
>> The nice thing about delegates is that they should be invisible.
>>
>> You do live validation just as you would for any other model not using
>> delegates.
>>
>> The only requirement should be ensuring that, if running standalone, you
>> have replicated the delegate extension point registration activity.
>>
>> From the OCL Documentation for the Ecore binding:
>>
>> /If you want to use EMF delegates to dispatch OCL, the required
>> registrations may be provided by
>> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|. /
>>
>> /This may be invoked with a null argument to install the registrations
>> in the global EPackage.Registry rather than a specified local registry./
>>
>> Regards
>>
>> Ed Willink
>>
>>
>> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>>> Hi Ed,
>>>
>>> Ed Willink wrote:
>>>> It may well be that if you use the normal EMFv live/batch facilities and
>>>> ignore all OCL aspects of EMFv, it will just work as you require. The
>>>> magic of EMF/OCL delegates is that the OCL is integrated as part of the
>>>> Ecore model so EMFv needs no help in activating it.
>>> That OCL is integrated into the metamodel is what I like best. But I
>>> don't know how to activate OCL delegates as live validation. Well, I
>>> think it's not a OCL issue directly, so maybe I should rename the topic
>>> here? So the question is, how to activate delegates for live validation?
>>>
>>> best regards,
>>> Gilbert
Re: OCL live validation in generated tree editor [message #875851 is a reply to message #875265] Wed, 23 May 2012 12:55 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

Christian W. Damus wrote:
> What you could do is to create a dynamic constraint provider that
> discovers the constraints implemented in a package's EValidator and
> contributes individual IModelConstraint wrappers for them that present
> themselves as "live mode" constraints. Then, you could to implement a
> hook that invokes an ILiveValidator upon changes in the model and
> reports problems. This might be based on a TransactionalEditingDomain,
> which does much of that work for you in its command stack.
>
> Your constraint provider would probably end up looking a lot like what
> was implemented for Juno in the UML2 project and integrated into
> Papyrus: it's batch-mode validation, but that's a small difference on
> the provider side:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373643 (UML2)
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373644 (Papyrus)
thanks for the detailed answer. But, unfortunately I couldn't do it.
What I've done is the following:

The constraints are annotated in my ecore model. The corresponding
validator (EValidator) was generated. Now I registered the following
extensions:

<extension
point="org.eclipse.emf.validation.constraintProviders">
<category
id="my.category.ocl"
mandatory="true"
name="my OCL constraints">
</category>
<constraintProvider
cache="true"
mode="Live">
<package
namespaceUri="http://www.my.dsl/">
</package>
<constraints
categories="my.category.ocl">
<constraint
class="my.OCLConstraintProvider"
id="my.OCLconstraintWrapper"
lang="Java"
mode="Live"
name="Constraint which wraps the defined OCL constraints"
severity="ERROR"
statusCode="1">
</constraint></constraints>
</constraintProvider>
</extension>
<extension
point="org.eclipse.emf.validation.constraintBindings">
<clientContext
default="false"
id="my.OCLclientContext">
<enablement></enablement>
</clientContext>
<binding
category="my.category.ocl"
context="my.OCLclientContext">
</binding>
</extension>

The class OCLConstraintProvider extends AbstractModelConstraint and
implements IModelConstraint. The validate method is implemented as follows:

public IStatus validate(IValidationContext ctx) {
EObject target = ctx.getTarget();
boolean validate = OperatorsValidator.INSTANCE.validate(target, null,
null);
if(!validate){
Set<EObject> targets = new HashSet<EObject>();
targets.add(target);
ConstraintStatus status = new ConstraintStatus(this, target, "A
constraint could not be satisfied.", targets);
return status;
}
return ctx.createSuccessStatus();
}

The problem is that nothing happens. Some time ago I successfully
realised a simple Java constraint this way (the constraint is
implemented in the validate method and not delegated to an EValidator).
While debugging I recognized that the validate method is never executed.
What am i doing wrong?

best regards,
Gilbert

>
> Alternatively, if from the execution of editing commands you can find
> out what the affected objects are, you may be able to dramatically
> simplify this by just running them through the EValidator in a
> command-stack listener. I don't know how feasible that might be.
Can you give some more pointers or hints how to do this?

best regards,
Gilbert


>
> HTH,
>
> Christian
>
>
> On 2012-05-21 11:34:46 +0000, Gilbert Mirenque said:
>
>> Hi Ed,
>> ok, now I noticed that an implementation of EValidator is generated when
>> adding OCL annotations to my ecore file. Then I searched for how to
>> register an EValidator for live validation and found only:
>>
>> http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering
>>
>>
>> But this already happens in the generated MyDSLPackageImpl in the init
>> method. What do you mean with "as you would for any other model not
>> using delegates"?
>>
>> best regards,
>> Gilbert
>>
>>
>> Ed Willink wrote:
>>> Hi
>>>
>>> The nice thing about delegates is that they should be invisible.
>>>
>>> You do live validation just as you would for any other model not using
>>> delegates.
>>>
>>> The only requirement should be ensuring that, if running standalone, you
>>> have replicated the delegate extension point registration activity.
>>>
>>> From the OCL Documentation for the Ecore binding:
>>>
>>> /If you want to use EMF delegates to dispatch OCL, the required
>>> registrations may be provided by
>>> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|.
>>> /
>>>
>>> /This may be invoked with a null argument to install the registrations
>>> in the global EPackage.Registry rather than a specified local registry./
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>>
>>> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>>>> Hi Ed,
>>>>
>>>> Ed Willink wrote:
>>>>> It may well be that if you use the normal EMFv live/batch
>>>>> facilities and
>>>>> ignore all OCL aspects of EMFv, it will just work as you require. The
>>>>> magic of EMF/OCL delegates is that the OCL is integrated as part of
>>>>> the
>>>>> Ecore model so EMFv needs no help in activating it.
>>>> That OCL is integrated into the metamodel is what I like best. But I
>>>> don't know how to activate OCL delegates as live validation. Well, I
>>>> think it's not a OCL issue directly, so maybe I should rename the topic
>>>> here? So the question is, how to activate delegates for live
>>>> validation?
>>>>
>>>> best regards,
>>>> Gilbert
>
>
Re: OCL live validation in generated tree editor [message #875875 is a reply to message #875851] Wed, 23 May 2012 13:34 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Gilbert,

So, you have one constraint that delegates to all of the rules
implemented by the EValidator? I guess that works. It certainly is a
simpler solution. :-)

I suspect the client context. It doesn't have an enablement condition,
so it probably doesn't match your model instance. This was always one
of the most fiddly aspects, trying to get that context match to work
properly.

You should be able to debug where the validation service matches client
contexts to see whether that's the issue. Off-hand, I don't see
anything else that could be causing your trouble.

HTH,

Christian


On 2012-05-23 12:55:47 +0000, Gilbert Mirenque said:

> Hi Christian,
>
> Christian W. Damus wrote:
>> What you could do is to create a dynamic constraint provider that
>> discovers the constraints implemented in a package's EValidator and
>> contributes individual IModelConstraint wrappers for them that present
>> themselves as "live mode" constraints. Then, you could to implement a
>> hook that invokes an ILiveValidator upon changes in the model and
>> reports problems. This might be based on a TransactionalEditingDomain,
>> which does much of that work for you in its command stack.
>>
>> Your constraint provider would probably end up looking a lot like what
>> was implemented for Juno in the UML2 project and integrated into
>> Papyrus: it's batch-mode validation, but that's a small difference on
>> the provider side:
>>
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373643 (UML2)
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373644 (Papyrus)
> thanks for the detailed answer. But, unfortunately I couldn't do it.
> What I've done is the following:
>
> The constraints are annotated in my ecore model. The corresponding
> validator (EValidator) was generated. Now I registered the following
> extensions:
>
> <extension
> point="org.eclipse.emf.validation.constraintProviders">
> <category
> id="my.category.ocl"
> mandatory="true"
> name="my OCL constraints">
> </category>
> <constraintProvider
> cache="true"
> mode="Live">
> <package
> namespaceUri="http://www.my.dsl/">
> </package>
> <constraints
> categories="my.category.ocl">
> <constraint
> class="my.OCLConstraintProvider"
> id="my.OCLconstraintWrapper"
> lang="Java"
> mode="Live"
> name="Constraint which wraps the defined OCL constraints"
> severity="ERROR"
> statusCode="1">
> </constraint></constraints>
> </constraintProvider>
> </extension>
> <extension
> point="org.eclipse.emf.validation.constraintBindings">
> <clientContext
> default="false"
> id="my.OCLclientContext">
> <enablement></enablement>
> </clientContext>
> <binding
> category="my.category.ocl"
> context="my.OCLclientContext">
> </binding>
> </extension>
>
> The class OCLConstraintProvider extends AbstractModelConstraint and
> implements IModelConstraint. The validate method is implemented as follows:
>
> public IStatus validate(IValidationContext ctx) {
> EObject target = ctx.getTarget();
> boolean validate = OperatorsValidator.INSTANCE.validate(target, null,
> null);
> if(!validate){
> Set<EObject> targets = new HashSet<EObject>();
> targets.add(target);
> ConstraintStatus status = new ConstraintStatus(this, target, "A
> constraint could not be satisfied.", targets);
> return status;
> }
> return ctx.createSuccessStatus();
> }
>
> The problem is that nothing happens. Some time ago I successfully
> realised a simple Java constraint this way (the constraint is
> implemented in the validate method and not delegated to an EValidator).
> While debugging I recognized that the validate method is never executed.
> What am i doing wrong?
>
> best regards,
> Gilbert
>
>>
>> Alternatively, if from the execution of editing commands you can find
>> out what the affected objects are, you may be able to dramatically
>> simplify this by just running them through the EValidator in a
>> command-stack listener. I don't know how feasible that might be.
> Can you give some more pointers or hints how to do this?
>
> best regards,
> Gilbert
>
>
>>
>> HTH,
>>
>> Christian
>>
>>
>> On 2012-05-21 11:34:46 +0000, Gilbert Mirenque said:
>>
>>> Hi Ed,
>>> ok, now I noticed that an implementation of EValidator is generated when
>>> adding OCL annotations to my ecore file. Then I searched for how to
>>> register an EValidator for live validation and found only:
>>>
>>> http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering
>>>
>>>
>>>
>>> But this already happens in the generated MyDSLPackageImpl in the init
>>> method. What do you mean with "as you would for any other model not
>>> using delegates"?
>>>
>>> best regards,
>>> Gilbert
>>>
>>>
>>> Ed Willink wrote:
>>>> Hi
>>>>
>>>> The nice thing about delegates is that they should be invisible.
>>>>
>>>> You do live validation just as you would for any other model not using
>>>> delegates.
>>>>
>>>> The only requirement should be ensuring that, if running standalone, you
>>>> have replicated the delegate extension point registration activity.
>>>>
>>>> From the OCL Documentation for the Ecore binding:
>>>>
>>>> /If you want to use EMF delegates to dispatch OCL, the required
>>>> registrations may be provided by
>>>> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|.
>>>> /
>>>>
>>>> /This may be invoked with a null argument to install the registrations
>>>> in the global EPackage.Registry rather than a specified local registry./
>>>>
>>>> Regards
>>>>
>>>> Ed Willink
>>>>
>>>>
>>>> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>>>>> Hi Ed,
>>>>>
>>>>> Ed Willink wrote:
>>>>>> It may well be that if you use the normal EMFv live/batch
>>>>>> facilities and
>>>>>> ignore all OCL aspects of EMFv, it will just work as you require. The
>>>>>> magic of EMF/OCL delegates is that the OCL is integrated as part of
>>>>>> the
>>>>>> Ecore model so EMFv needs no help in activating it.
>>>>> That OCL is integrated into the metamodel is what I like best. But I
>>>>> don't know how to activate OCL delegates as live validation. Well, I
>>>>> think it's not a OCL issue directly, so maybe I should rename the topic
>>>>> here? So the question is, how to activate delegates for live
>>>>> validation?
>>>>>
>>>>> best regards,
>>>>> Gilbert
Re: OCL live validation in generated tree editor [message #876773 is a reply to message #875875] Fri, 25 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
I don't get it to work. I copy & pasted the relevant part of another
plugin.xml for the client context where it worked just with Java
implemented constraint. But it doesn't for my OCL constraints :(

> You should be able to debug where the validation service matches client
> contexts to see whether that's the issue. Off-hand, I don't see
> anything else that could be causing your trouble.
Can you name the validation service class to debug?

best regards,
Gilbert


>
> HTH,
>
> Christian
>
>
> On 2012-05-23 12:55:47 +0000, Gilbert Mirenque said:
>
>> Hi Christian,
>>
>> Christian W. Damus wrote:
>>> What you could do is to create a dynamic constraint provider that
>>> discovers the constraints implemented in a package's EValidator and
>>> contributes individual IModelConstraint wrappers for them that present
>>> themselves as "live mode" constraints. Then, you could to implement a
>>> hook that invokes an ILiveValidator upon changes in the model and
>>> reports problems. This might be based on a TransactionalEditingDomain,
>>> which does much of that work for you in its command stack.
>>>
>>> Your constraint provider would probably end up looking a lot like what
>>> was implemented for Juno in the UML2 project and integrated into
>>> Papyrus: it's batch-mode validation, but that's a small difference on
>>> the provider side:
>>>
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373643 (UML2)
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373644 (Papyrus)
>> thanks for the detailed answer. But, unfortunately I couldn't do it.
>> What I've done is the following:
>>
>> The constraints are annotated in my ecore model. The corresponding
>> validator (EValidator) was generated. Now I registered the following
>> extensions:
>>
>> <extension
>> point="org.eclipse.emf.validation.constraintProviders">
>> <category
>> id="my.category.ocl"
>> mandatory="true"
>> name="my OCL constraints">
>> </category>
>> <constraintProvider
>> cache="true"
>> mode="Live">
>> <package
>> namespaceUri="http://www.my.dsl/">
>> </package>
>> <constraints
>> categories="my.category.ocl">
>> <constraint
>> class="my.OCLConstraintProvider"
>> id="my.OCLconstraintWrapper"
>> lang="Java"
>> mode="Live"
>> name="Constraint which wraps the defined OCL
>> constraints"
>> severity="ERROR"
>> statusCode="1">
>> </constraint></constraints>
>> </constraintProvider>
>> </extension>
>> <extension
>> point="org.eclipse.emf.validation.constraintBindings">
>> <clientContext
>> default="false"
>> id="my.OCLclientContext">
>> <enablement></enablement>
>> </clientContext>
>> <binding
>> category="my.category.ocl"
>> context="my.OCLclientContext">
>> </binding>
>> </extension>
>>
>> The class OCLConstraintProvider extends AbstractModelConstraint and
>> implements IModelConstraint. The validate method is implemented as
>> follows:
>>
>> public IStatus validate(IValidationContext ctx) {
>> EObject target = ctx.getTarget();
>> boolean validate = OperatorsValidator.INSTANCE.validate(target, null,
>> null);
>> if(!validate){
>> Set<EObject> targets = new HashSet<EObject>();
>> targets.add(target);
>> ConstraintStatus status = new ConstraintStatus(this, target, "A
>> constraint could not be satisfied.", targets);
>> return status;
>> }
>> return ctx.createSuccessStatus();
>> }
>>
>> The problem is that nothing happens. Some time ago I successfully
>> realised a simple Java constraint this way (the constraint is
>> implemented in the validate method and not delegated to an EValidator).
>> While debugging I recognized that the validate method is never executed.
>> What am i doing wrong?
>>
>> best regards,
>> Gilbert
>>
>>>
>>> Alternatively, if from the execution of editing commands you can find
>>> out what the affected objects are, you may be able to dramatically
>>> simplify this by just running them through the EValidator in a
>>> command-stack listener. I don't know how feasible that might be.
>> Can you give some more pointers or hints how to do this?
>>
>> best regards,
>> Gilbert
>>
>>
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>>
>>> On 2012-05-21 11:34:46 +0000, Gilbert Mirenque said:
>>>
>>>> Hi Ed,
>>>> ok, now I noticed that an implementation of EValidator is generated
>>>> when
>>>> adding OCL annotations to my ecore file. Then I searched for how to
>>>> register an EValidator for live validation and found only:
>>>>
>>>> http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering
>>>>
>>>>
>>>>
>>>> But this already happens in the generated MyDSLPackageImpl in the init
>>>> method. What do you mean with "as you would for any other model not
>>>> using delegates"?
>>>>
>>>> best regards,
>>>> Gilbert
>>>>
>>>>
>>>> Ed Willink wrote:
>>>>> Hi
>>>>>
>>>>> The nice thing about delegates is that they should be invisible.
>>>>>
>>>>> You do live validation just as you would for any other model not using
>>>>> delegates.
>>>>>
>>>>> The only requirement should be ensuring that, if running
>>>>> standalone, you
>>>>> have replicated the delegate extension point registration activity.
>>>>>
>>>>> From the OCL Documentation for the Ecore binding:
>>>>>
>>>>> /If you want to use EMF delegates to dispatch OCL, the required
>>>>> registrations may be provided by
>>>>> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|.
>>>>>
>>>>> /
>>>>>
>>>>> /This may be invoked with a null argument to install the registrations
>>>>> in the global EPackage.Registry rather than a specified local
>>>>> registry./
>>>>>
>>>>> Regards
>>>>>
>>>>> Ed Willink
>>>>>
>>>>>
>>>>> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>>>>>> Hi Ed,
>>>>>>
>>>>>> Ed Willink wrote:
>>>>>>> It may well be that if you use the normal EMFv live/batch
>>>>>>> facilities and
>>>>>>> ignore all OCL aspects of EMFv, it will just work as you require.
>>>>>>> The
>>>>>>> magic of EMF/OCL delegates is that the OCL is integrated as part of
>>>>>>> the
>>>>>>> Ecore model so EMFv needs no help in activating it.
>>>>>> That OCL is integrated into the metamodel is what I like best. But I
>>>>>> don't know how to activate OCL delegates as live validation. Well, I
>>>>>> think it's not a OCL issue directly, so maybe I should rename the
>>>>>> topic
>>>>>> here? So the question is, how to activate delegates for live
>>>>>> validation?
>>>>>>
>>>>>> best regards,
>>>>>> Gilbert
>
>
Re: OCL live validation in generated tree editor [message #876957 is a reply to message #876773] Fri, 25 May 2012 15:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your problems prompted me to provide a patch
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=327956) for the EMFv
documentation, which will hopefully give a much better impression of the
alternatives available for using OCL for validation.

Unfortunately it does not help you with the missing
EValidatorConstraintProvider facility that Christian outlined.

Regards

Ed Willink


On 25/05/2012 10:04, Gilbert Mirenque wrote:
> Hi Christian,
> I don't get it to work. I copy& pasted the relevant part of another
> plugin.xml for the client context where it worked just with Java
> implemented constraint. But it doesn't for my OCL constraints :(
>
>> You should be able to debug where the validation service matches client
>> contexts to see whether that's the issue. Off-hand, I don't see
>> anything else that could be causing your trouble.
> Can you name the validation service class to debug?
>
> best regards,
> Gilbert
>
>
>> HTH,
>>
>> Christian
>>
>>
>> On 2012-05-23 12:55:47 +0000, Gilbert Mirenque said:
>>
>>> Hi Christian,
>>>
>>> Christian W. Damus wrote:
>>>> What you could do is to create a dynamic constraint provider that
>>>> discovers the constraints implemented in a package's EValidator and
>>>> contributes individual IModelConstraint wrappers for them that present
>>>> themselves as "live mode" constraints. Then, you could to implement a
>>>> hook that invokes an ILiveValidator upon changes in the model and
>>>> reports problems. This might be based on a TransactionalEditingDomain,
>>>> which does much of that work for you in its command stack.
>>>>
>>>> Your constraint provider would probably end up looking a lot like what
>>>> was implemented for Juno in the UML2 project and integrated into
>>>> Papyrus: it's batch-mode validation, but that's a small difference on
>>>> the provider side:
>>>>
>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373643 (UML2)
>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373644 (Papyrus)
>>> thanks for the detailed answer. But, unfortunately I couldn't do it.
>>> What I've done is the following:
>>>
>>> The constraints are annotated in my ecore model. The corresponding
>>> validator (EValidator) was generated. Now I registered the following
>>> extensions:
>>>
>>> <extension
>>> point="org.eclipse.emf.validation.constraintProviders">
>>> <category
>>> id="my.category.ocl"
>>> mandatory="true"
>>> name="my OCL constraints">
>>> </category>
>>> <constraintProvider
>>> cache="true"
>>> mode="Live">
>>> <package
>>> namespaceUri="http://www.my.dsl/">
>>> </package>
>>> <constraints
>>> categories="my.category.ocl">
>>> <constraint
>>> class="my.OCLConstraintProvider"
>>> id="my.OCLconstraintWrapper"
>>> lang="Java"
>>> mode="Live"
>>> name="Constraint which wraps the defined OCL
>>> constraints"
>>> severity="ERROR"
>>> statusCode="1">
>>> </constraint></constraints>
>>> </constraintProvider>
>>> </extension>
>>> <extension
>>> point="org.eclipse.emf.validation.constraintBindings">
>>> <clientContext
>>> default="false"
>>> id="my.OCLclientContext">
>>> <enablement></enablement>
>>> </clientContext>
>>> <binding
>>> category="my.category.ocl"
>>> context="my.OCLclientContext">
>>> </binding>
>>> </extension>
>>>
>>> The class OCLConstraintProvider extends AbstractModelConstraint and
>>> implements IModelConstraint. The validate method is implemented as
>>> follows:
>>>
>>> public IStatus validate(IValidationContext ctx) {
>>> EObject target = ctx.getTarget();
>>> boolean validate = OperatorsValidator.INSTANCE.validate(target, null,
>>> null);
>>> if(!validate){
>>> Set<EObject> targets = new HashSet<EObject>();
>>> targets.add(target);
>>> ConstraintStatus status = new ConstraintStatus(this, target, "A
>>> constraint could not be satisfied.", targets);
>>> return status;
>>> }
>>> return ctx.createSuccessStatus();
>>> }
>>>
>>> The problem is that nothing happens. Some time ago I successfully
>>> realised a simple Java constraint this way (the constraint is
>>> implemented in the validate method and not delegated to an EValidator).
>>> While debugging I recognized that the validate method is never executed.
>>> What am i doing wrong?
>>>
>>> best regards,
>>> Gilbert
>>>
>>>> Alternatively, if from the execution of editing commands you can find
>>>> out what the affected objects are, you may be able to dramatically
>>>> simplify this by just running them through the EValidator in a
>>>> command-stack listener. I don't know how feasible that might be.
>>> Can you give some more pointers or hints how to do this?
>>>
>>> best regards,
>>> Gilbert
>>>
>>>
>>>> HTH,
>>>>
>>>> Christian
>>>>
>>>>
>>>> On 2012-05-21 11:34:46 +0000, Gilbert Mirenque said:
>>>>
>>>>> Hi Ed,
>>>>> ok, now I noticed that an implementation of EValidator is generated
>>>>> when
>>>>> adding OCL annotations to my ecore file. Then I searched for how to
>>>>> register an EValidator for live validation and found only:
>>>>>
>>>>> http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering
>>>>>
>>>>>
>>>>>
>>>>> But this already happens in the generated MyDSLPackageImpl in the init
>>>>> method. What do you mean with "as you would for any other model not
>>>>> using delegates"?
>>>>>
>>>>> best regards,
>>>>> Gilbert
>>>>>
>>>>>
>>>>> Ed Willink wrote:
>>>>>> Hi
>>>>>>
>>>>>> The nice thing about delegates is that they should be invisible.
>>>>>>
>>>>>> You do live validation just as you would for any other model not using
>>>>>> delegates.
>>>>>>
>>>>>> The only requirement should be ensuring that, if running
>>>>>> standalone, you
>>>>>> have replicated the delegate extension point registration activity.
>>>>>>
>>>>>> From the OCL Documentation for the Ecore binding:
>>>>>>
>>>>>> /If you want to use EMF delegates to dispatch OCL, the required
>>>>>> registrations may be provided by
>>>>>> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|.
>>>>>>
>>>>>> /
>>>>>>
>>>>>> /This may be invoked with a null argument to install the registrations
>>>>>> in the global EPackage.Registry rather than a specified local
>>>>>> registry./
>>>>>>
>>>>>> Regards
>>>>>>
>>>>>> Ed Willink
>>>>>>
>>>>>>
>>>>>> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>>>>>>> Hi Ed,
>>>>>>>
>>>>>>> Ed Willink wrote:
>>>>>>>> It may well be that if you use the normal EMFv live/batch
>>>>>>>> facilities and
>>>>>>>> ignore all OCL aspects of EMFv, it will just work as you require.
>>>>>>>> The
>>>>>>>> magic of EMF/OCL delegates is that the OCL is integrated as part of
>>>>>>>> the
>>>>>>>> Ecore model so EMFv needs no help in activating it.
>>>>>>> That OCL is integrated into the metamodel is what I like best. But I
>>>>>>> don't know how to activate OCL delegates as live validation. Well, I
>>>>>>> think it's not a OCL issue directly, so maybe I should rename the
>>>>>>> topic
>>>>>>> here? So the question is, how to activate delegates for live
>>>>>>> validation?
>>>>>>>
>>>>>>> best regards,
>>>>>>> Gilbert
>>
Re: OCL live validation in generated tree editor [message #877158 is a reply to message #876773] Sat, 26 May 2012 01:11 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Gilbert,

My memory of this code is fairly dim after more than four years away
from it, and it has changed, too, in ways that I don't know.

Have a look at what ClientContextManager::getClientContextsFor(EObject)
computes for the client-contexts matching the object you're trying to
validate. And then, what getBindings(Collection, Collection) in the
same class computes for constraints that match the contexts for your
object.

HTH,

Christian


On 2012-05-25 09:04:54 +0000, Gilbert Mirenque said:

> Hi Christian,
> I don't get it to work. I copy & pasted the relevant part of another
> plugin.xml for the client context where it worked just with Java
> implemented constraint. But it doesn't for my OCL constraints :(
>
>> You should be able to debug where the validation service matches client
>> contexts to see whether that's the issue. Off-hand, I don't see
>> anything else that could be causing your trouble.
> Can you name the validation service class to debug?
>
> best regards,
> Gilbert
>
>
>>
>> HTH,
>>
>> Christian
>>
>>
>> On 2012-05-23 12:55:47 +0000, Gilbert Mirenque said:
>>
>>> Hi Christian,
>>>
>>> Christian W. Damus wrote:
>>>> What you could do is to create a dynamic constraint provider that
>>>> discovers the constraints implemented in a package's EValidator and
>>>> contributes individual IModelConstraint wrappers for them that present
>>>> themselves as "live mode" constraints. Then, you could to implement a
>>>> hook that invokes an ILiveValidator upon changes in the model and
>>>> reports problems. This might be based on a TransactionalEditingDomain,
>>>> which does much of that work for you in its command stack.
>>>>
>>>> Your constraint provider would probably end up looking a lot like what
>>>> was implemented for Juno in the UML2 project and integrated into
>>>> Papyrus: it's batch-mode validation, but that's a small difference on
>>>> the provider side:
>>>>
>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373643 (UML2)
>>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=373644 (Papyrus)
>>> thanks for the detailed answer. But, unfortunately I couldn't do it.
>>> What I've done is the following:
>>>
>>> The constraints are annotated in my ecore model. The corresponding
>>> validator (EValidator) was generated. Now I registered the following
>>> extensions:
>>>
>>> <extension
>>> point="org.eclipse.emf.validation.constraintProviders">
>>> <category
>>> id="my.category.ocl"
>>> mandatory="true"
>>> name="my OCL constraints">
>>> </category>
>>> <constraintProvider
>>> cache="true"
>>> mode="Live">
>>> <package
>>> namespaceUri="http://www.my.dsl/">
>>> </package>
>>> <constraints
>>> categories="my.category.ocl">
>>> <constraint
>>> class="my.OCLConstraintProvider"
>>> id="my.OCLconstraintWrapper"
>>> lang="Java"
>>> mode="Live"
>>> name="Constraint which wraps the defined OCL
>>> constraints"
>>> severity="ERROR"
>>> statusCode="1">
>>> </constraint></constraints>
>>> </constraintProvider>
>>> </extension>
>>> <extension
>>> point="org.eclipse.emf.validation.constraintBindings">
>>> <clientContext
>>> default="false"
>>> id="my.OCLclientContext">
>>> <enablement></enablement>
>>> </clientContext>
>>> <binding
>>> category="my.category.ocl"
>>> context="my.OCLclientContext">
>>> </binding>
>>> </extension>
>>>
>>> The class OCLConstraintProvider extends AbstractModelConstraint and
>>> implements IModelConstraint. The validate method is implemented as
>>> follows:
>>>
>>> public IStatus validate(IValidationContext ctx) {
>>> EObject target = ctx.getTarget();
>>> boolean validate = OperatorsValidator.INSTANCE.validate(target, null,
>>> null);
>>> if(!validate){
>>> Set<EObject> targets = new HashSet<EObject>();
>>> targets.add(target);
>>> ConstraintStatus status = new ConstraintStatus(this, target, "A
>>> constraint could not be satisfied.", targets);
>>> return status;
>>> }
>>> return ctx.createSuccessStatus();
>>> }
>>>
>>> The problem is that nothing happens. Some time ago I successfully
>>> realised a simple Java constraint this way (the constraint is
>>> implemented in the validate method and not delegated to an EValidator).
>>> While debugging I recognized that the validate method is never executed.
>>> What am i doing wrong?
>>>
>>> best regards,
>>> Gilbert
>>>
>>>>
>>>> Alternatively, if from the execution of editing commands you can find
>>>> out what the affected objects are, you may be able to dramatically
>>>> simplify this by just running them through the EValidator in a
>>>> command-stack listener. I don't know how feasible that might be.
>>> Can you give some more pointers or hints how to do this?
>>>
>>> best regards,
>>> Gilbert
>>>
>>>
>>>>
>>>> HTH,
>>>>
>>>> Christian
>>>>
>>>>
>>>> On 2012-05-21 11:34:46 +0000, Gilbert Mirenque said:
>>>>
>>>>> Hi Ed,
>>>>> ok, now I noticed that an implementation of EValidator is generated
>>>>> when
>>>>> adding OCL annotations to my ecore file. Then I searched for how to
>>>>> register an EValidator for live validation and found only:
>>>>>
>>>>> http://help.eclipse.org/galileo/topic/org.eclipse.emf.validation.doc/tutorials/validationAdapterTutorial.html#registering
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> But this already happens in the generated MyDSLPackageImpl in the init
>>>>> method. What do you mean with "as you would for any other model not
>>>>> using delegates"?
>>>>>
>>>>> best regards,
>>>>> Gilbert
>>>>>
>>>>>
>>>>> Ed Willink wrote:
>>>>>> Hi
>>>>>>
>>>>>> The nice thing about delegates is that they should be invisible.
>>>>>>
>>>>>> You do live validation just as you would for any other model not using
>>>>>> delegates.
>>>>>>
>>>>>> The only requirement should be ensuring that, if running
>>>>>> standalone, you
>>>>>> have replicated the delegate extension point registration activity.
>>>>>>
>>>>>> From the OCL Documentation for the Ecore binding:
>>>>>>
>>>>>> /If you want to use EMF delegates to dispatch OCL, the required
>>>>>> registrations may be provided by
>>>>>> |org.eclipse.ocl.ecore.delegate.DelegateDomain.initialize(ResourceSet)|.
>>>>>>
>>>>>> /
>>>>>>
>>>>>> /This may be invoked with a null argument to install the registrations
>>>>>> in the global EPackage.Registry rather than a specified local
>>>>>> registry./
>>>>>>
>>>>>> Regards
>>>>>>
>>>>>> Ed Willink
>>>>>>
>>>>>>
>>>>>> On 21/05/2012 07:55, Gilbert Mirenque wrote:
>>>>>>> Hi Ed,
>>>>>>>
>>>>>>> Ed Willink wrote:
>>>>>>>> It may well be that if you use the normal EMFv live/batch
>>>>>>>> facilities and
>>>>>>>> ignore all OCL aspects of EMFv, it will just work as you require.
>>>>>>>> The
>>>>>>>> magic of EMF/OCL delegates is that the OCL is integrated as part of
>>>>>>>> the
>>>>>>>> Ecore model so EMFv needs no help in activating it.
>>>>>>> That OCL is integrated into the metamodel is what I like best. But I
>>>>>>> don't know how to activate OCL delegates as live validation. Well, I
>>>>>>> think it's not a OCL issue directly, so maybe I should rename the
>>>>>>> topic
>>>>>>> here? So the question is, how to activate delegates for live
>>>>>>> validation?
>>>>>>>
>>>>>>> best regards,
>>>>>>> Gilbert
Previous Topic:[CDO] Local CDO Workspace with only a part of the model tree
Next Topic:packageImport
Goto Forum:
  


Current Time: Fri Apr 26 15:18:45 GMT 2024

Powered by FUDForum. Page generated in 0.05071 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top