Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Connecting editor action with OCL Constraint provider
Connecting editor action with OCL Constraint provider [message #59368] Mon, 21 July 2008 12:48 Go to next message
Mark Melia is currently offline Mark MeliaFriend
Messages: 142
Registered: July 2009
Senior Member
Hi all,

I have created a new menu item for a GMF project I am running, this will
trigger validation. The menu item appears but does not trigger the
OCLConstraintProvider. The class of the action is triggered -
org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate
but it never gets as far as the OCLConstriantProvider. I should mention
that this is an amended version of the OCL example from the MDT site. Does
anyone know what triggers the OCLConstraint provider to be triggered?

Thanks,
Mark
Re: Connecting editor action with OCL Constraint provider [message #59395 is a reply to message #59368] Mon, 21 July 2008 13:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

--=-T506QscBOS5NFHhJPZ0j
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Mark,

Questions of constraint-provider integration into validation are not
OCL-specific, so I am replying to the EMF newsgroup.

If your provider isn't even being queried to serve up constraints, then
the problem isn't the usual failure to find a matching client-context.
Perhaps something is awry in the registration of the provider. Does it
specify one or more namespace URIs of packages for which it defines
constraints? Check the workspace log for any warnings or errors
pertaining to your provider.

I'm not sure what you mean by "amended version of the OCL example from
the MDT site." The MDT OCL component doesn't provide any examples of
integration with the EMF Validation Framework component. The only
example that demonstrates validation is the article demonstrating OCL in
EMF's generative validation solution, which is quite a different matter.

HTH,

Christian

On Mon, 2008-07-21 at 12:48 +0000, Mark Melia wrote:

> Hi all,
>
> I have created a new menu item for a GMF project I am running, this will
> trigger validation. The menu item appears but does not trigger the
> OCLConstraintProvider. The class of the action is triggered -
> org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate
> but it never gets as far as the OCLConstriantProvider. I should mention
> that this is an amended version of the OCL example from the MDT site. Does
> anyone know what triggers the OCLConstraint provider to be triggered?
>
> Thanks,
> Mark
>

--=-T506QscBOS5NFHhJPZ0j
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.0">
</HEAD>
<BODY>
Hi, Mark,<BR>
<BR>
Questions of constraint-provider integration into validation are not OCL-specific, so I am replying to the EMF newsgroup.<BR>
<BR>
If your provider isn't even being queried to serve up constraints, then the problem isn't the usual failure to find a matching client-context.&nbsp; Perhaps something is awry in the registration of the provider.&nbsp; Does it specify one or more namespace URIs of packages for which it defines constraints?&nbsp; Check the workspace log for any warnings or errors pertaining to your provider.<BR>
<BR>
I'm not sure what you mean by &quot;amended version of the OCL example from the MDT site.&quot;&nbsp; The MDT OCL component doesn't provide any examples of integration with the EMF Validation Framework component.&nbsp; The only example that demonstrates validation is the article demonstrating OCL in EMF's generative validation solution, which is quite a different matter.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
On Mon, 2008-07-21 at 12:48 +0000, Mark Melia wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Hi all,</FONT>

<FONT COLOR="#000000">I have created a new menu item for a GMF project I am running, this will </FONT>
<FONT COLOR="#000000">trigger validation. The menu item appears but does not trigger the </FONT>
<FONT COLOR="#000000">OCLConstraintProvider. The class of the action is triggered - </FONT>
<FONT COLOR="#000000"> org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate </FONT>
<FONT COLOR="#000000">but it never gets as far as the OCLConstriantProvider. I should mention </FONT>
<FONT COLOR="#000000">that this is an amended version of the OCL example from the MDT site. Does </FONT>
<FONT COLOR="#000000">anyone know what triggers the OCLConstraint provider to be triggered?</FONT>

<FONT COLOR="#000000">Thanks,</FONT>
<FONT COLOR="#000000">Mark</FONT>

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-T506QscBOS5NFHhJPZ0j--
Re: Connecting editor action with OCL Constraint provider [message #59418 is a reply to message #59395] Mon, 21 July 2008 16:01 Go to previous messageGo to next message
Mark Melia is currently offline Mark MeliaFriend
Messages: 142
Registered: July 2009
Senior Member
Hi Christian,

Thanks for helping once again. The example I am using is the Library one
http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
Re: Connecting editor action with OCL Constraint provider [message #59443 is a reply to message #59418] Mon, 21 July 2008 16:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

--=-R+66mgwCQQX53ysDQFJH
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Mark,

That example has nothing to do with validation. It's simply an
interactive OCL console. Perhaps you melded it with the
org.eclipse.emf.validation.examples.ocl example?

Perhaps if you can supply the plugin.xml that defines your
constraint-provider extension, that would help to diagnose your problem.

cW


On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:

> Hi Christian,
>
> Thanks for helping once again. The example I am using is the Library one
> http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip

--=-R+66mgwCQQX53ysDQFJH
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.0">
</HEAD>
<BODY>
Hi, Mark,<BR>
<BR>
That example has nothing to do with validation.&nbsp; It's simply an interactive OCL console.&nbsp; Perhaps you melded it with the org.eclipse.emf.validation.examples.ocl example?<BR>
<BR>
Perhaps if you can supply the plugin.xml that defines your constraint-provider extension, that would help to diagnose your problem.<BR>
<BR>
cW<BR>
<BR>
<BR>
On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Hi Christian,</FONT>

<FONT COLOR="#000000">Thanks for helping once again. The example I am using is the Library one </FONT>
<FONT COLOR="#000000"><A HREF=" http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip"> http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip</A> </FONT>
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-R+66mgwCQQX53ysDQFJH--
Re: Connecting editor action with OCL Constraint provider [message #59467 is a reply to message #59443] Mon, 21 July 2008 16:23 Go to previous messageGo to next message
Mark Melia is currently offline Mark MeliaFriend
Messages: 142
Registered: July 2009
Senior Member
Sorry Christian for the confusion - that is the one i meant, the
org.eclipse.emf.validation.examples.ocl example.

I have included the plugin.xml below - thanks again:
<plugin>

<extension point="org.eclipse.ui.editorActions">
<editorContribution

id=" org.eclipse.emf.validation.examples.general.editorContributi on "
targetID="Mikael2High.diagram.part.MIKAEL2hDiagramEditorID" >
<menu
label="CAVIAr Validation"
path="additions"
id="Course.Validation">
<separator name="additions"/>
</menu>

<action
label="%ValidateElementsAction.label"
icon="$nl$/icons/elcl16/validate_co.gif"

class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
menubarPath="Course.Validation/additions"

id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
<action
label="%EnableLiveValidationAction.label"

class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
menubarPath="Course.Validation/additions"

id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
<action
label="%ShowValidationEventsAction.label"

class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
style="toggle"
state="false"
menubarPath="Course.Validation/additions"

id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>

</editorContribution>
</extension>

<extension
point="org.eclipse.ui.popupMenus">
<viewerContribution
targetID="CaviarLow.presentation.CaviarLowEditorID"

id=" org.eclipse.emf.validation.examples.general.viewerContributi on ">
<menu
label="%_UI_ValidationMenu_label"
path="additions"
id="org.eclipse.emf.validationMenuID">
<separator name="additions"/>
</menu>
<action
label="%ValidateElementsAction.label"
icon="$nl$/icons/elcl16/validate_co.gif"

class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
menubarPath="org.eclipse.emf.validationMenuID/additions"

id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
<action
label="%EnableLiveValidationAction.label"

class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
menubarPath="org.eclipse.emf.validationMenuID/additions"

id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
<action
label="%ShowValidationEventsAction.label"

class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
style="toggle"
state="false"
menubarPath="org.eclipse.emf.validationMenuID/additions"

id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>

</viewerContribution>
</extension>




<extension
point="org.eclipse.emf.validation.constraintProviders"
id="oclProvider">
<!-- Custom constraint provider using OCL documents -->
<constraintProvider

class=" org.eclipse.emf.validation.examples.ocl.OCLConstraintProvide r "
category="Constraints from an OCL Document"
cache="false">

<package namespaceUri="http://mikael.computing.dcu.ie/#2_0"/>

<ocl path="constraints/library.ocl"/>
</constraintProvider>
</extension>



<extension
point="org.eclipse.emf.validation.constraintBindings">
<clientContext
default="false"
id="MIKAEL2hClientContext">
<selector
class=" org.eclipse.emf.validation.examples.general.constraints.Vali dationDelegateClientSelector "/>
</clientContext>
<binding
context="MIKAEL2hClientContext"
category="mikael.validation"/>
</extension>
<extension
point="org.eclipse.emf.validation.validationListeners">
<listener
class=" org.eclipse.emf.validation.examples.general.listeners.Valida tionListener ">
<clientContext id="MIKAEL2hClientContext"/>
</listener>
</extension>
<extension
point="org.eclipse.emf.validation.ui.UIRegisteredClientContext ">
<clientContext id="MIKAEL2hClientContext"/>
</extension>
</plugin>

Christian W. Damus wrote:

> Hi, Mark,

> That example has nothing to do with validation. It's simply an
> interactive OCL console. Perhaps you melded it with the
> org.eclipse.emf.validation.examples.ocl example?

> Perhaps if you can supply the plugin.xml that defines your
> constraint-provider extension, that would help to diagnose your problem.

> cW


> On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:

>> Hi Christian,
>>
>> Thanks for helping once again. The example I am using is the Library one
>>
http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
Re: Connecting editor action with OCL Constraint provider [message #59517 is a reply to message #59467] Tue, 22 July 2008 12:22 Go to previous messageGo to next message
Mark Melia is currently offline Mark MeliaFriend
Messages: 142
Registered: July 2009
Senior Member
Hi,

Just a quick update on this - in case anybody has the same problem.

I have established that the selectionChanged method of the
BatchValidateDelegate is called to any selection changes after the first
time the Validator is called. This means that the initial validation still
has no selectedEObjects but after the initial validation, the selected
element is found for any subsequent validations.

I have also noted that because our project is a GMF project, the
selectionChanged method had to be changed to handle editparts as opposed
to eObjects that were coming in the original EMF project.

The OCLConstraintProvider is now being invoked - but not giving the
correct result for the OCL I have defined - I think this might be a client
context issue.

Anybody with ideas, I would love to hear them.

Thanks,
Mark

Mark Melia wrote:

> Sorry Christian for the confusion - that is the one i meant, the
> org.eclipse.emf.validation.examples.ocl example.

> I have included the plugin.xml below - thanks again:
> <plugin>

> <extension point="org.eclipse.ui.editorActions">
> <editorContribution

> id=" org.eclipse.emf.validation.examples.general.editorContributi on "
> targetID="Mikael2High.diagram.part.MIKAEL2hDiagramEditorID" >
> <menu
> label="CAVIAr Validation"
> path="additions"
> id="Course.Validation">
> <separator name="additions"/>
> </menu>

> <action
> label="%ValidateElementsAction.label"
> icon="$nl$/icons/elcl16/validate_co.gif"

>
class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
> menubarPath="Course.Validation/additions"

> id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
> <action
> label="%EnableLiveValidationAction.label"

>
class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
> menubarPath="Course.Validation/additions"

>
id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
> <action
> label="%ShowValidationEventsAction.label"

>
class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
> style="toggle"
> state="false"
> menubarPath="Course.Validation/additions"

>
id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>

> </editorContribution>
> </extension>

> <extension
> point="org.eclipse.ui.popupMenus">
> <viewerContribution
> targetID="CaviarLow.presentation.CaviarLowEditorID"

> id=" org.eclipse.emf.validation.examples.general.viewerContributi on ">
> <menu
> label="%_UI_ValidationMenu_label"
> path="additions"
> id="org.eclipse.emf.validationMenuID">
> <separator name="additions"/>
> </menu>
> <action
> label="%ValidateElementsAction.label"
> icon="$nl$/icons/elcl16/validate_co.gif"

>
class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
> menubarPath="org.eclipse.emf.validationMenuID/additions"

> id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
> <action
> label="%EnableLiveValidationAction.label"

>
class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
> menubarPath="org.eclipse.emf.validationMenuID/additions"

>
id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
> <action
> label="%ShowValidationEventsAction.label"

>
class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
> style="toggle"
> state="false"
> menubarPath="org.eclipse.emf.validationMenuID/additions"

>
id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>

> </viewerContribution>
> </extension>




> <extension
> point="org.eclipse.emf.validation.constraintProviders"
> id="oclProvider">
> <!-- Custom constraint provider using OCL documents -->
> <constraintProvider

> class=" org.eclipse.emf.validation.examples.ocl.OCLConstraintProvide r "
> category="Constraints from an OCL Document"
> cache="false">

> <package namespaceUri="http://mikael.computing.dcu.ie/#2_0"/>

> <ocl path="constraints/library.ocl"/>
> </constraintProvider>
> </extension>



> <extension
> point="org.eclipse.emf.validation.constraintBindings">
> <clientContext
> default="false"
> id="MIKAEL2hClientContext">
> <selector
>
class=" org.eclipse.emf.validation.examples.general.constraints.Vali dationDelegateClientSelector "/>
> </clientContext>
> <binding
> context="MIKAEL2hClientContext"
> category="mikael.validation"/>
> </extension>
> <extension
> point="org.eclipse.emf.validation.validationListeners">
> <listener
>
class=" org.eclipse.emf.validation.examples.general.listeners.Valida tionListener ">
> <clientContext id="MIKAEL2hClientContext"/>
> </listener>
> </extension>
> <extension
> point="org.eclipse.emf.validation.ui.UIRegisteredClientContext ">
> <clientContext id="MIKAEL2hClientContext"/>
> </extension>
> </plugin>

> Christian W. Damus wrote:

>> Hi, Mark,

>> That example has nothing to do with validation. It's simply an
>> interactive OCL console. Perhaps you melded it with the
>> org.eclipse.emf.validation.examples.ocl example?

>> Perhaps if you can supply the plugin.xml that defines your
>> constraint-provider extension, that would help to diagnose your problem.

>> cW


>> On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:

>>> Hi Christian,
>>>
>>> Thanks for helping once again. The example I am using is the Library one
>>>
>
http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
Re: Connecting editor action with OCL Constraint provider [message #59590 is a reply to message #59517] Tue, 22 July 2008 13:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

--=-pfhMP8cRliiJIyHgixwN
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Mark,

Sorry for not responding sooner.

Yeah, GMF provides an IAdaptableSelection interface that is implemented
by the selections in the diagrams, which provides convenient access to
the model elements (as opposed to the diagram views) that are selected.
Just adapt to EObject and you're cool.

If there's a bug in the action-delegate's handling of selection, perhaps
you could raise it? It won't do to have examples that don't demonstrate
working code. :-(

For debugging client-context issues, the best place to start is with a
breakpoint in the

getBindings(Collection<IClientContext>,
Collection<IModelConstraint>)

method of the
org.eclipse.emf.validation.internal.service.ClientContextMan ager.

You will see whether your constraint matches any of the incoming
client-contexts, which should suggest whether you are missing bindings
or whether you need to define an additional context. These contexts are
kind of notoriously tricky to get right (they're always tripping me up,
and I invented them!).

HTH,

Christian


On Tue, 2008-07-22 at 12:22 +0000, Mark Melia wrote:

> Hi,
>
> Just a quick update on this - in case anybody has the same problem.
>
> I have established that the selectionChanged method of the
> BatchValidateDelegate is called to any selection changes after the first
> time the Validator is called. This means that the initial validation still
> has no selectedEObjects but after the initial validation, the selected
> element is found for any subsequent validations.
>
> I have also noted that because our project is a GMF project, the
> selectionChanged method had to be changed to handle editparts as opposed
> to eObjects that were coming in the original EMF project.
>
> The OCLConstraintProvider is now being invoked - but not giving the
> correct result for the OCL I have defined - I think this might be a client
> context issue.
>
> Anybody with ideas, I would love to hear them.
>
> Thanks,
> Mark
>
> Mark Melia wrote:
>
> > Sorry Christian for the confusion - that is the one i meant, the
> > org.eclipse.emf.validation.examples.ocl example.
>
> > I have included the plugin.xml below - thanks again:
> > <plugin>
>
> > <extension point="org.eclipse.ui.editorActions">
> > <editorContribution
>
> > id=" org.eclipse.emf.validation.examples.general.editorContributi on "
> > targetID="Mikael2High.diagram.part.MIKAEL2hDiagramEditorID" >
> > <menu
> > label="CAVIAr Validation"
> > path="additions"
> > id="Course.Validation">
> > <separator name="additions"/>
> > </menu>
>
> > <action
> > label="%ValidateElementsAction.label"
> > icon="$nl$/icons/elcl16/validate_co.gif"
>
> >
> class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
> > menubarPath="Course.Validation/additions"
>
> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
> > <action
> > label="%EnableLiveValidationAction.label"
>
> >
> class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
> > menubarPath="Course.Validation/additions"
>
> >
> id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
> > <action
> > label="%ShowValidationEventsAction.label"
>
> >
> class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
> > style="toggle"
> > state="false"
> > menubarPath="Course.Validation/additions"
>
> >
> id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
>
> > </editorContribution>
> > </extension>
>
> > <extension
> > point="org.eclipse.ui.popupMenus">
> > <viewerContribution
> > targetID="CaviarLow.presentation.CaviarLowEditorID"
>
> > id=" org.eclipse.emf.validation.examples.general.viewerContributi on ">
> > <menu
> > label="%_UI_ValidationMenu_label"
> > path="additions"
> > id="org.eclipse.emf.validationMenuID">
> > <separator name="additions"/>
> > </menu>
> > <action
> > label="%ValidateElementsAction.label"
> > icon="$nl$/icons/elcl16/validate_co.gif"
>
> >
> class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>
> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
> > <action
> > label="%EnableLiveValidationAction.label"
>
> >
> class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>
> >
> id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
> > <action
> > label="%ShowValidationEventsAction.label"
>
> >
> class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
> > style="toggle"
> > state="false"
> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>
> >
> id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
>
> > </viewerContribution>
> > </extension>
>
>
>
>
> > <extension
> > point="org.eclipse.emf.validation.constraintProviders"
> > id="oclProvider">
> > <!-- Custom constraint provider using OCL documents -->
> > <constraintProvider
>
> > class=" org.eclipse.emf.validation.examples.ocl.OCLConstraintProvide r "
> > category="Constraints from an OCL Document"
> > cache="false">
>
> > <package namespaceUri="http://mikael.computing.dcu.ie/#2_0"/>
>
> > <ocl path="constraints/library.ocl"/>
> > </constraintProvider>
> > </extension>
>
>
>
> > <extension
> > point="org.eclipse.emf.validation.constraintBindings">
> > <clientContext
> > default="false"
> > id="MIKAEL2hClientContext">
> > <selector
> >
> class=" org.eclipse.emf.validation.examples.general.constraints.Vali dationDelegateClientSelector "/>
> > </clientContext>
> > <binding
> > context="MIKAEL2hClientContext"
> > category="mikael.validation"/>
> > </extension>
> > <extension
> > point="org.eclipse.emf.validation.validationListeners">
> > <listener
> >
> class=" org.eclipse.emf.validation.examples.general.listeners.Valida tionListener ">
> > <clientContext id="MIKAEL2hClientContext"/>
> > </listener>
> > </extension>
> > <extension
> > point="org.eclipse.emf.validation.ui.UIRegisteredClientContext ">
> > <clientContext id="MIKAEL2hClientContext"/>
> > </extension>
> > </plugin>
>
> > Christian W. Damus wrote:
>
> >> Hi, Mark,
>
> >> That example has nothing to do with validation. It's simply an
> >> interactive OCL console. Perhaps you melded it with the
> >> org.eclipse.emf.validation.examples.ocl example?
>
> >> Perhaps if you can supply the plugin.xml that defines your
> >> constraint-provider extension, that would help to diagnose your problem.
>
> >> cW
>
>
> >> On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:
>
> >>> Hi Christian,
> >>>
> >>> Thanks for helping once again. The example I am using is the Library one
> >>>
> >
> http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
>
>

--=-pfhMP8cRliiJIyHgixwN
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.0">
</HEAD>
<BODY>
Hi, Mark,<BR>
<BR>
Sorry for not responding sooner.<BR>
<BR>
Yeah, GMF provides an IAdaptableSelection interface that is implemented by the selections in the diagrams, which provides convenient access to the model elements (as opposed to the diagram views) that are selected.&nbsp; Just adapt to EObject and you're cool.<BR>
<BR>
If there's a bug in the action-delegate's handling of selection, perhaps you could raise it?&nbsp; It won't do to have examples that don't demonstrate working code.&nbsp; :-(<BR>
<BR>
For debugging client-context issues, the best place to start is with a breakpoint in the<BR>
<BR>
&nbsp;&nbsp;&nbsp; getBindings(Collection&lt;IClientContext&gt;, Collection&lt;IModelConstraint&gt;)<BR>
<BR>
method of the org.eclipse.emf.validation.internal.service.ClientContextMan ager. <BR>
<BR>
You will see whether your constraint matches any of the incoming client-contexts, which should suggest whether you are missing bindings or whether you need to define an additional context.&nbsp; These contexts are kind of notoriously tricky to get right (they're always tripping me up, and I invented them!).<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Tue, 2008-07-22 at 12:22 +0000, Mark Melia wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Hi,</FONT>

<FONT COLOR="#000000">Just a quick update on this - in case anybody has the same problem.</FONT>

<FONT COLOR="#000000">I have established that the selectionChanged method of the </FONT>
<FONT COLOR="#000000">BatchValidateDelegate is called to any selection changes after the first </FONT>
<FONT COLOR="#000000">time the Validator is called. This means that the initial validation still </FONT>
<FONT COLOR="#000000">has no selectedEObjects but after the initial validation, the selected </FONT>
<FONT COLOR="#000000">element is found for any subsequent validations.</FONT>

<FONT COLOR="#000000">I have also noted that because our project is a GMF project, the </FONT>
<FONT COLOR="#000000">selectionChanged method had to be changed to handle editparts as opposed </FONT>
<FONT COLOR="#000000">to eObjects that were coming in the original EMF project. </FONT>

<FONT COLOR="#000000">The OCLConstraintProvider is now being invoked - but not giving the </FONT>
<FONT COLOR="#000000">correct result for the OCL I have defined - I think this might be a client </FONT>
<FONT COLOR="#000000">context issue.</FONT>

<FONT COLOR="#000000">Anybody with ideas, I would love to hear them.</FONT>

<FONT COLOR="#000000">Thanks,</FONT>
<FONT COLOR="#000000">Mark</FONT>

<FONT COLOR="#000000">Mark Melia wrote:</FONT>

<FONT COLOR="#000000">&gt; Sorry Christian for the confusion - that is the one i meant, the </FONT>
<FONT COLOR="#000000">&gt; org.eclipse.emf.validation.examples.ocl example.</FONT>

<FONT COLOR="#000000">&gt; I have included the plugin.xml below - thanks again:</FONT>
<FONT COLOR="#000000">&gt; &lt;plugin&gt;</FONT>

<FONT COLOR="#000000">&gt; &lt;extension point=&quot;org.eclipse.ui.editorActions&quot;&g t; </FONT>
<FONT COLOR="#000000">&gt; &lt;editorContribution </FONT>

<FONT COLOR="#000000">&gt; id=&quot;org.eclipse.emf.validation.examples.general.edi torContribution&quot; </FONT>
<FONT COLOR="#000000">&gt; targetID=&quot;Mikael2High.diagram.part.MIKAEL2hDiagramE ditorID&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;menu</FONT>
<FONT COLOR="#000000">&gt; label=&quot;CAVIAr Validation&quot;</FONT>
<FONT COLOR="#000000">&gt; path=&quot;additions&quot;</FONT>
<FONT COLOR="#000000">&gt; id=&quot;Course.Validation&quot;&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;separator name=&quot;additions&quot;/&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;/menu&gt;</FONT>

<FONT COLOR="#000000">&gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%ValidateElementsAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt; icon=&quot;$nl$/icons/elcl16/validate_co.gif&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.BatchValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt; menubarPath=&quot;Course.Validation/additions&quot;</FONT >

<FONT COLOR="#000000">&gt; id=&quot;org.eclipse.emf.validation.pde.example.general. ui.validateAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%EnableLiveValidationAction.label&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.EnableLiveValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt; menubarPath=&quot;Course.Validation/additions&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.enableLiveValidationAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%ShowValidationEventsAction.label&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.ShowValidationEventsDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt; style=&quot;toggle&quot;</FONT>
<FONT COLOR="#000000">&gt; state=&quot;false&quot;</FONT>
<FONT COLOR="#000000">&gt; menubarPath=&quot;Course.Validation/additions&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.showValidationEventsAction&quot;/&gt; </FONT>

<FONT COLOR="#000000">&gt; &lt;/editorContribution&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;/extension&gt; </FONT>

<FONT COLOR="#000000">&gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt; point=&quot;org.eclipse.ui.popupMenus&quot;&gt;</FONT >
<FONT COLOR="#000000">&gt; &lt;viewerContribution</FONT>
<FONT COLOR="#000000">&gt; targetID=&quot;CaviarLow.presentation.CaviarLowEditorID& amp;quot; </FONT>

<FONT COLOR="#000000">&gt; id=&quot;org.eclipse.emf.validation.examples.general.vie werContribution&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;menu</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%_UI_ValidationMenu_label&quot;</FONT>
<FONT COLOR="#000000">&gt; path=&quot;additions&quot;</FONT>
<FONT COLOR="#000000">&gt; id=&quot;org.eclipse.emf.validationMenuID&quot;& gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;separator name=&quot;additions&quot;/&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;/menu&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%ValidateElementsAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt; icon=&quot;$nl$/icons/elcl16/validate_co.gif&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.BatchValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt; menubarPath=&quot;org.eclipse.emf.validationMenuID/addit ions&quot; </FONT>

<FONT COLOR="#000000">&gt; id=&quot;org.eclipse.emf.validation.pde.example.general. ui.validateAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%EnableLiveValidationAction.label&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.EnableLiveValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt; menubarPath=&quot;org.eclipse.emf.validationMenuID/addit ions&quot; </FONT>

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.enableLiveValidationAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt; label=&quot;%ShowValidationEventsAction.label&quot;</FONT >

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.ShowValidationEventsDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt; style=&quot;toggle&quot;</FONT>
<FONT COLOR="#000000">&gt; state=&quot;false&quot;</FONT>
<FONT COLOR="#000000">&gt; menubarPath=&quot;org.eclipse.emf.validationMenuID/addit ions&quot; </FONT>

<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.showValidationEventsAction&quot;/&gt; </FONT>

<FONT COLOR="#000000">&gt; &lt;/viewerContribution&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;/extension&gt;</FONT>




<FONT COLOR="#000000">&gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt; point=&quot;org.eclipse.emf.validation.constraintProvide rs&quot; </FONT>
<FONT COLOR="#000000">&gt; id=&quot;oclProvider&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;!-- Custom constraint provider using OCL documents --&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;constraintProvider</FONT>

<FONT COLOR="#000000">&gt; class=&quot;org.eclipse.emf.validation.examples.ocl.OCLC onstraintProvider&quot; </FONT>
<FONT COLOR="#000000">&gt; category=&quot;Constraints from an OCL Document&quot;</FONT>
<FONT COLOR="#000000">&gt; cache=&quot;false&quot;&gt;</FONT>

<FONT COLOR="#000000">&gt; &lt;package namespaceUri=&quot;<A HREF="http://mikael.computing.dcu.ie/#2_0">http://mikael.computing.dcu.ie/#2_0&quot;/</A>&gt;</FONT>

<FONT COLOR="#000000">&gt; &lt;ocl path=&quot;constraints/library.ocl&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt; &lt;/constraintProvider&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;/extension&gt;</FONT>



<FONT COLOR="#000000">&gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt; point=&quot;org.eclipse.emf.validation.constraintBinding s&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;clientContext</FONT>
<FONT COLOR="#000000">&gt; default=&quot;false&quot;</FONT>
<FONT COLOR="#000000">&gt; id=&quot;MIKAEL2hClientContext&quot;&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;selector </FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. constraints.ValidationDelegateClientSelector&quot;/& gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;/clientContext&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;binding</FONT>
<FONT COLOR="#000000">&gt; context=&quot;MIKAEL2hClientContext&quot;</FONT>
<FONT COLOR="#000000">&gt; category=&quot;mikael.validation&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt; &lt;/extension&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt; point=&quot;org.eclipse.emf.validation.validationListene rs&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;listener </FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. listeners.ValidationListener&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;clientContext id=&quot;MIKAEL2hClientContext&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt; &lt;/listener&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;/extension&gt;</FONT>
<FONT COLOR="#000000">&gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt; point=&quot;org.eclipse.emf.validation.ui.UIRegisteredCl ientContext&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;clientContext id=&quot;MIKAEL2hClientContext&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt; &lt;/extension&gt; </FONT>
<FONT COLOR="#000000">&gt; &lt;/plugin&gt;</FONT>

<FONT COLOR="#000000">&gt; Christian W. Damus wrote:</FONT>

<FONT COLOR="#000000">&gt;&gt; Hi, Mark,</FONT>

<FONT COLOR="#000000">&gt;&gt; That example has nothing to do with validation. It's simply an</FONT>
<FONT COLOR="#000000">&gt;&gt; interactive OCL console. Perhaps you melded it with the</FONT>
<FONT COLOR="#000000">&gt;&gt; org.eclipse.emf.validation.examples.ocl example?</FONT>

<FONT COLOR="#000000">&gt;&gt; Perhaps if you can supply the plugin.xml that defines your</FONT>
<FONT COLOR="#000000">&gt;&gt; constraint-provider extension, that would help to diagnose your problem.</FONT>

<FONT COLOR="#000000">&gt;&gt; cW</FONT>


<FONT COLOR="#000000">&gt;&gt; On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:</FONT>

<FONT COLOR="#000000">&gt;&gt;&gt; Hi Christian,</FONT>
<FONT COLOR="#000000">&gt;&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt;&gt; Thanks for helping once again. The example I am using is the Library one </FONT>
<FONT COLOR="#000000">&gt;&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000"><A HREF=" http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip"> http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip</A></FONT>


</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-pfhMP8cRliiJIyHgixwN--
Re: Connecting editor action with OCL Constraint provider [message #59714 is a reply to message #59590] Wed, 23 July 2008 13:42 Go to previous messageGo to next message
Mark Melia is currently offline Mark MeliaFriend
Messages: 142
Registered: July 2009
Senior Member
Hey Christian,

I nearly have this working, just trying to sort out one small context
issue. In my validation, I want to validate everthing in the model when
the user select validate. So the selected item is irrelevant, as all items
in the model will have to be validated.

To do this, in the BatchValidateDelegate I set up my run method to read in
all elements of the model and add them to the selectedEObjects, but there
was context issues. I discovered when you add two different EObject types
to the selectedEObjects it doesnt work - is this correct? Do you have any
ideas why this is the case.

The below code works for me, but if I add in the commented out lines it
does not validate against the OCL constraints.

Thanks again for all your help,
Mark

public void run(IAction action) {


ValidationDelegateClientSelector.running = true;

MIKAEL2hDiagramEditor mikaelEditor =
(MIKAEL2hDiagramEditor)MIKAEL2hEditorPlugin.getPlugin().getW orkbench().getActiveWorkbenchWindow().getActivePage().getAct iveEditor();
CaviarImpl c =
(CaviarImpl)mikaelEditor.getDiagram().getElement().eContaine r();

TreeIterator<EObject> l = c.eAllContents();
this.selectedEObjects = new ArrayList<EObject>();


this.selectedEObjects.addAll(c.getCoursewareModel().getTopic s());
while(l.hasNext()){
EObject eObj = l.next();
if(eObj instanceof Concept){
this.selectedEObjects.add((Concept)eObj);
//}else if(eObj instanceof Topic){
// this.selectedEObjects.add((Topic)eObj);
}else{}
}
// this.selectedEObjects.add((EObject)l.next());

IBatchValidator validator =
(IBatchValidator)ModelValidationService.getInstance()
.newValidator(EvaluationMode.BATCH);
validator.setIncludeLiveConstraints(true);

final IStatus status = validator.validate(selectedEObjects);


Christian W. Damus wrote:

> Hi, Mark,

> Sorry for not responding sooner.

> Yeah, GMF provides an IAdaptableSelection interface that is implemented
> by the selections in the diagrams, which provides convenient access to
> the model elements (as opposed to the diagram views) that are selected.
> Just adapt to EObject and you're cool.

> If there's a bug in the action-delegate's handling of selection, perhaps
> you could raise it? It won't do to have examples that don't demonstrate
> working code. :-(

> For debugging client-context issues, the best place to start is with a
> breakpoint in the

> getBindings(Collection<IClientContext>,
> Collection<IModelConstraint>)

> method of the
> org.eclipse.emf.validation.internal.service.ClientContextMan ager.

> You will see whether your constraint matches any of the incoming
> client-contexts, which should suggest whether you are missing bindings
> or whether you need to define an additional context. These contexts are
> kind of notoriously tricky to get right (they're always tripping me up,
> and I invented them!).

> HTH,

> Christian


> On Tue, 2008-07-22 at 12:22 +0000, Mark Melia wrote:

>> Hi,
>>
>> Just a quick update on this - in case anybody has the same problem.
>>
>> I have established that the selectionChanged method of the
>> BatchValidateDelegate is called to any selection changes after the first
>> time the Validator is called. This means that the initial validation still
>> has no selectedEObjects but after the initial validation, the selected
>> element is found for any subsequent validations.
>>
>> I have also noted that because our project is a GMF project, the
>> selectionChanged method had to be changed to handle editparts as opposed
>> to eObjects that were coming in the original EMF project.
>>
>> The OCLConstraintProvider is now being invoked - but not giving the
>> correct result for the OCL I have defined - I think this might be a client
>> context issue.
>>
>> Anybody with ideas, I would love to hear them.
>>
>> Thanks,
>> Mark
>>
>> Mark Melia wrote:
>>
>> > Sorry Christian for the confusion - that is the one i meant, the
>> > org.eclipse.emf.validation.examples.ocl example.
>>
>> > I have included the plugin.xml below - thanks again:
>> > <plugin>
>>
>> > <extension point="org.eclipse.ui.editorActions">
>> > <editorContribution
>>
>> > id=" org.eclipse.emf.validation.examples.general.editorContributi on "
>> > targetID="Mikael2High.diagram.part.MIKAEL2hDiagramEditorID" >
>> > <menu
>> > label="CAVIAr Validation"
>> > path="additions"
>> > id="Course.Validation">
>> > <separator name="additions"/>
>> > </menu>
>>
>> > <action
>> > label="%ValidateElementsAction.label"
>> > icon="$nl$/icons/elcl16/validate_co.gif"
>>
>> >
>>
class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
>> > menubarPath="Course.Validation/additions"
>>
>> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
>> > <action
>> > label="%EnableLiveValidationAction.label"
>>
>> >
>>
class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
>> > menubarPath="Course.Validation/additions"
>>
>> >
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
>> > <action
>> > label="%ShowValidationEventsAction.label"
>>
>> >
>>
class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
>> > style="toggle"
>> > state="false"
>> > menubarPath="Course.Validation/additions"
>>
>> >
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
>>
>> > </editorContribution>
>> > </extension>
>>
>> > <extension
>> > point="org.eclipse.ui.popupMenus">
>> > <viewerContribution
>> > targetID="CaviarLow.presentation.CaviarLowEditorID"
>>
>> > id=" org.eclipse.emf.validation.examples.general.viewerContributi on ">
>> > <menu
>> > label="%_UI_ValidationMenu_label"
>> > path="additions"
>> > id="org.eclipse.emf.validationMenuID">
>> > <separator name="additions"/>
>> > </menu>
>> > <action
>> > label="%ValidateElementsAction.label"
>> > icon="$nl$/icons/elcl16/validate_co.gif"
>>
>> >
>>
class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
>> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>>
>> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
>> > <action
>> > label="%EnableLiveValidationAction.label"
>>
>> >
>>
class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
>> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>>
>> >
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
>> > <action
>> > label="%ShowValidationEventsAction.label"
>>
>> >
>>
class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
>> > style="toggle"
>> > state="false"
>> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>>
>> >
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
>>
>> > </viewerContribution>
>> > </extension>
>>
>>
>>
>>
>> > <extension
>> > point="org.eclipse.emf.validation.constraintProviders"
>> > id="oclProvider">
>> > <!-- Custom constraint provider using OCL documents -->
>> > <constraintProvider
>>
>> > class=" org.eclipse.emf.validation.examples.ocl.OCLConstraintProvide r "
>> > category="Constraints from an OCL Document"
>> > cache="false">
>>
>> > <package namespaceUri="http://mikael.computing.dcu.ie/#2_0"/>
>>
>> > <ocl path="constraints/library.ocl"/>
>> > </constraintProvider>
>> > </extension>
>>
>>
>>
>> > <extension
>> > point="org.eclipse.emf.validation.constraintBindings">
>> > <clientContext
>> > default="false"
>> > id="MIKAEL2hClientContext">
>> > <selector
>> >
>>
class=" org.eclipse.emf.validation.examples.general.constraints.Vali dationDelegateClientSelector "/>
>> > </clientContext>
>> > <binding
>> > context="MIKAEL2hClientContext"
>> > category="mikael.validation"/>
>> > </extension>
>> > <extension
>> > point="org.eclipse.emf.validation.validationListeners">
>> > <listener
>> >
>>
class=" org.eclipse.emf.validation.examples.general.listeners.Valida tionListener ">
>> > <clientContext id="MIKAEL2hClientContext"/>
>> > </listener>
>> > </extension>
>> > <extension
>> > point="org.eclipse.emf.validation.ui.UIRegisteredClientContext ">
>> > <clientContext id="MIKAEL2hClientContext"/>
>> > </extension>
>> > </plugin>
>>
>> > Christian W. Damus wrote:
>>
>> >> Hi, Mark,
>>
>> >> That example has nothing to do with validation. It's simply an
>> >> interactive OCL console. Perhaps you melded it with the
>> >> org.eclipse.emf.validation.examples.ocl example?
>>
>> >> Perhaps if you can supply the plugin.xml that defines your
>> >> constraint-provider extension, that would help to diagnose your problem.
>>
>> >> cW
>>
>>
>> >> On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:
>>
>> >>> Hi Christian,
>> >>>
>> >>> Thanks for helping once again. The example I am using is the Library
one
>> >>>
>> >
>>
http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
>>
>>
Re: Connecting editor action with OCL Constraint provider [message #59742 is a reply to message #59714] Wed, 23 July 2008 19:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

--=-mz9hryCaBRdDfhrrqHM+
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Mark,

See some replies in-line, below.

HTH,

Christian


On Wed, 2008-07-23 at 13:42 +0000, Mark Melia wrote:

> Hey Christian,
>
> I nearly have this working, just trying to sort out one small context
> issue. In my validation, I want to validate everthing in the model when
> the user select validate. So the selected item is irrelevant, as all items
> in the model will have to be validated.
>
> To do this, in the BatchValidateDelegate I set up my run method to read in
> all elements of the model and add them to the selectedEObjects, but there


Oo. By default, batch validation iterates over the objects contained by
the selection, so you should only need to add the resource contents to
your selection. Otherwise, you'll be iterating over all of the objects
once to collect them, again to validate them, and in between the
validator does a lot of work to remove from your selection all of the
elements that are nested within other elements in the selection.


> was context issues. I discovered when you add two different EObject types
> to the selectedEObjects it doesnt work - is this correct? Do you have any
> ideas why this is the case.


What do you mean by "two different EObject types?" You can select
instances of any number of different EClasses, from different EPackages,
and even different client-contexts.




> The below code works for me, but if I add in the commented out lines it
> does not validate against the OCL constraints.


I see that it is usurping the validator's job of determining which
objects to evaluate constraints on by filtering the eAllContents().
Except, as I mentioned, that it won't work that way because the
validator will iterate contents anyway.

Simply doing

validator.validate(Collections.singletonList(c))

should do the trick. Or, maybe you need to add the
c.getCoursewareModel() to the list of objects to validate if it isn't
contained by c.

In any case, the way you're doing it shouldn't fail to work; it should
just be inefficient. It looks like there's some kind of bug, maybe in
the client-context handling. If you can produce a small reproducible
test case as a bugzilla attachment, that would be most cool.

P.S.

I see that you are casting to CaviarImpl. It is recommended practice to
treat *Impls as "internal" code in the Eclipse sense and use only the
interfaces; e.g., Caviar.


>
> Thanks again for all your help,
> Mark
>
> public void run(IAction action) {
>
>
> ValidationDelegateClientSelector.running = true;
>
> MIKAEL2hDiagramEditor mikaelEditor =
> (MIKAEL2hDiagramEditor)MIKAEL2hEditorPlugin.getPlugin().getW orkbench().getActiveWorkbenchWindow().getActivePage().getAct iveEditor();
> CaviarImpl c =
> (CaviarImpl)mikaelEditor.getDiagram().getElement().eContaine r();
>
> TreeIterator<EObject> l = c.eAllContents();
> this.selectedEObjects = new ArrayList<EObject>();
>
>
> this.selectedEObjects.addAll(c.getCoursewareModel().getTopic s());
> while(l.hasNext()){
> EObject eObj = l.next();
> if(eObj instanceof Concept){
> this.selectedEObjects.add((Concept)eObj);
> //}else if(eObj instanceof Topic){
> // this.selectedEObjects.add((Topic)eObj);
> }else{}
> }
> // this.selectedEObjects.add((EObject)l.next());
>
> IBatchValidator validator =
> (IBatchValidator)ModelValidationService.getInstance()
> .newValidator(EvaluationMode.BATCH);
> validator.setIncludeLiveConstraints(true);
>
> final IStatus status = validator.validate(selectedEObjects);
>
>
> Christian W. Damus wrote:
>
> > Hi, Mark,
>
> > Sorry for not responding sooner.
>
> > Yeah, GMF provides an IAdaptableSelection interface that is implemented
> > by the selections in the diagrams, which provides convenient access to
> > the model elements (as opposed to the diagram views) that are selected.
> > Just adapt to EObject and you're cool.
>
> > If there's a bug in the action-delegate's handling of selection, perhaps
> > you could raise it? It won't do to have examples that don't demonstrate
> > working code. :-(
>
> > For debugging client-context issues, the best place to start is with a
> > breakpoint in the
>
> > getBindings(Collection<IClientContext>,
> > Collection<IModelConstraint>)
>
> > method of the
> > org.eclipse.emf.validation.internal.service.ClientContextMan ager.
>
> > You will see whether your constraint matches any of the incoming
> > client-contexts, which should suggest whether you are missing bindings
> > or whether you need to define an additional context. These contexts are
> > kind of notoriously tricky to get right (they're always tripping me up,
> > and I invented them!).
>
> > HTH,
>
> > Christian
>
>
> > On Tue, 2008-07-22 at 12:22 +0000, Mark Melia wrote:
>
> >> Hi,
> >>
> >> Just a quick update on this - in case anybody has the same problem.
> >>
> >> I have established that the selectionChanged method of the
> >> BatchValidateDelegate is called to any selection changes after the first
> >> time the Validator is called. This means that the initial validation still
> >> has no selectedEObjects but after the initial validation, the selected
> >> element is found for any subsequent validations.
> >>
> >> I have also noted that because our project is a GMF project, the
> >> selectionChanged method had to be changed to handle editparts as opposed
> >> to eObjects that were coming in the original EMF project.
> >>
> >> The OCLConstraintProvider is now being invoked - but not giving the
> >> correct result for the OCL I have defined - I think this might be a client
> >> context issue.
> >>
> >> Anybody with ideas, I would love to hear them.
> >>
> >> Thanks,
> >> Mark
> >>
> >> Mark Melia wrote:
> >>
> >> > Sorry Christian for the confusion - that is the one i meant, the
> >> > org.eclipse.emf.validation.examples.ocl example.
> >>
> >> > I have included the plugin.xml below - thanks again:
> >> > <plugin>
> >>
> >> > <extension point="org.eclipse.ui.editorActions">
> >> > <editorContribution
> >>
> >> > id=" org.eclipse.emf.validation.examples.general.editorContributi on "
> >> > targetID="Mikael2High.diagram.part.MIKAEL2hDiagramEditorID" >
> >> > <menu
> >> > label="CAVIAr Validation"
> >> > path="additions"
> >> > id="Course.Validation">
> >> > <separator name="additions"/>
> >> > </menu>
> >>
> >> > <action
> >> > label="%ValidateElementsAction.label"
> >> > icon="$nl$/icons/elcl16/validate_co.gif"
> >>
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
> >> > menubarPath="Course.Validation/additions"
> >>
> >> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
> >> > <action
> >> > label="%EnableLiveValidationAction.label"
> >>
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
> >> > menubarPath="Course.Validation/additions"
> >>
> >> >
> >>
> id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
> >> > <action
> >> > label="%ShowValidationEventsAction.label"
> >>
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
> >> > style="toggle"
> >> > state="false"
> >> > menubarPath="Course.Validation/additions"
> >>
> >> >
> >>
> id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
> >>
> >> > </editorContribution>
> >> > </extension>
> >>
> >> > <extension
> >> > point="org.eclipse.ui.popupMenus">
> >> > <viewerContribution
> >> > targetID="CaviarLow.presentation.CaviarLowEditorID"
> >>
> >> > id=" org.eclipse.emf.validation.examples.general.viewerContributi on ">
> >> > <menu
> >> > label="%_UI_ValidationMenu_label"
> >> > path="additions"
> >> > id="org.eclipse.emf.validationMenuID">
> >> > <separator name="additions"/>
> >> > </menu>
> >> > <action
> >> > label="%ValidateElementsAction.label"
> >> > icon="$nl$/icons/elcl16/validate_co.gif"
> >>
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
> >> > menubarPath="org.eclipse.emf.validationMenuID/additions"
> >>
> >> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
> >> > <action
> >> > label="%EnableLiveValidationAction.label"
> >>
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
> >> > menubarPath="org.eclipse.emf.validationMenuID/additions"
> >>
> >> >
> >>
> id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
> >> > <action
> >> > label="%ShowValidationEventsAction.label"
> >>
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
> >> > style="toggle"
> >> > state="false"
> >> > menubarPath="org.eclipse.emf.validationMenuID/additions"
> >>
> >> >
> >>
> id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
> >>
> >> > </viewerContribution>
> >> > </extension>
> >>
> >>
> >>
> >>
> >> > <extension
> >> > point="org.eclipse.emf.validation.constraintProviders"
> >> > id="oclProvider">
> >> > <!-- Custom constraint provider using OCL documents -->
> >> > <constraintProvider
> >>
> >> > class=" org.eclipse.emf.validation.examples.ocl.OCLConstraintProvide r "
> >> > category="Constraints from an OCL Document"
> >> > cache="false">
> >>
> >> > <package namespaceUri="http://mikael.computing.dcu.ie/#2_0"/>
> >>
> >> > <ocl path="constraints/library.ocl"/>
> >> > </constraintProvider>
> >> > </extension>
> >>
> >>
> >>
> >> > <extension
> >> > point="org.eclipse.emf.validation.constraintBindings">
> >> > <clientContext
> >> > default="false"
> >> > id="MIKAEL2hClientContext">
> >> > <selector
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.constraints.Vali dationDelegateClientSelector "/>
> >> > </clientContext>
> >> > <binding
> >> > context="MIKAEL2hClientContext"
> >> > category="mikael.validation"/>
> >> > </extension>
> >> > <extension
> >> > point="org.eclipse.emf.validation.validationListeners">
> >> > <listener
> >> >
> >>
> class=" org.eclipse.emf.validation.examples.general.listeners.Valida tionListener ">
> >> > <clientContext id="MIKAEL2hClientContext"/>
> >> > </listener>
> >> > </extension>
> >> > <extension
> >> > point="org.eclipse.emf.validation.ui.UIRegisteredClientContext ">
> >> > <clientContext id="MIKAEL2hClientContext"/>
> >> > </extension>
> >> > </plugin>
> >>
> >> > Christian W. Damus wrote:
> >>
> >> >> Hi, Mark,
> >>
> >> >> That example has nothing to do with validation. It's simply an
> >> >> interactive OCL console. Perhaps you melded it with the
> >> >> org.eclipse.emf.validation.examples.ocl example?
> >>
> >> >> Perhaps if you can supply the plugin.xml that defines your
> >> >> constraint-provider extension, that would help to diagnose your problem.
> >>
> >> >> cW
> >>
> >>
> >> >> On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:
> >>
> >> >>> Hi Christian,
> >> >>>
> >> >>> Thanks for helping once again. The example I am using is the Library
> one
> >> >>>
> >> >
> >>
> http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
> >>
> >>
>
>

--=-mz9hryCaBRdDfhrrqHM+
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.0">
</HEAD>
<BODY>
Hi, Mark,<BR>
<BR>
See some replies in-line, below.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Wed, 2008-07-23 at 13:42 +0000, Mark Melia wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Hey Christian,</FONT>

<FONT COLOR="#000000">I nearly have this working, just trying to sort out one small context </FONT>
<FONT COLOR="#000000">issue. In my validation, I want to validate everthing in the model when </FONT>
<FONT COLOR="#000000">the user select validate. So the selected item is irrelevant, as all items </FONT>
<FONT COLOR="#000000">in the model will have to be validated.</FONT>

<FONT COLOR="#000000">To do this, in the BatchValidateDelegate I set up my run method to read in </FONT>
<FONT COLOR="#000000">all elements of the model and add them to the selectedEObjects, but there </FONT>
</PRE>
</BLOCKQUOTE>
<BR>
Oo.&nbsp; By default, batch validation iterates over the objects contained by the selection, so you should only need to add the resource contents to your selection.&nbsp; Otherwise, you'll be iterating over all of the objects once to collect them, again to validate them, and in between the validator does a lot of work to remove from your selection all of the elements that are nested within other elements in the selection.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">was context issues. I discovered when you add two different EObject types </FONT>
<FONT COLOR="#000000">to the selectedEObjects it doesnt work - is this correct? Do you have any </FONT>
<FONT COLOR="#000000">ideas why this is the case.</FONT>
</PRE>
</BLOCKQUOTE>
<BR>
What do you mean by &quot;two different EObject types?&quot;&nbsp; You can select instances of any number of different EClasses, from different EPackages, and even different client-contexts.<BR>
<BR>
<PRE>

</PRE>
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">The below code works for me, but if I add in the commented out lines it </FONT>
<FONT COLOR="#000000">does not validate against the OCL constraints.</FONT>
</PRE>
</BLOCKQUOTE>
<BR>
I see that it is usurping the validator's job of determining which objects to evaluate constraints on by filtering the eAllContents().&nbsp; Except, as I mentioned, that it won't work that way because the validator will iterate contents anyway.<BR>
<BR>
Simply doing<BR>
<BR>
&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000">validator.validate(</FONT>Collections.singletonList(c) <FONT COLOR="#000000">)</FONT><BR>
<BR>
should do the trick.&nbsp; Or, maybe you need to add the c.getCoursewareModel() to the list of objects to validate if it isn't contained by c.<BR>
<BR>
In any case, the way you're doing it shouldn't fail to work; it should just be inefficient.&nbsp; It looks like there's some kind of bug, maybe in the client-context handling.&nbsp; If you can produce a small reproducible test case as a bugzilla attachment, that would be most cool.<BR>
<BR>
P.S.<BR>
<BR>
I see that you are casting to CaviarImpl.&nbsp; It is recommended practice to treat *Impls as &quot;internal&quot; code in the Eclipse sense and use only the interfaces; e.g., Caviar.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>

<FONT COLOR="#000000">Thanks again for all your help,</FONT>
<FONT COLOR="#000000">Mark</FONT>

<FONT COLOR="#000000">public void run(IAction action) {</FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> ValidationDelegateClientSelector.running = true;</FONT>

<FONT COLOR="#000000"> MIKAEL2hDiagramEditor mikaelEditor = </FONT>
<FONT COLOR="#000000"> (MIKAEL2hDiagramEditor)MIKAEL2hEditorPlugin.getPlugin().getW orkbench().getActiveWorkbenchWindow().getActivePage().getAct iveEditor(); </FONT>
<FONT COLOR="#000000"> CaviarImpl c = </FONT>
<FONT COLOR="#000000"> (CaviarImpl)mikaelEditor.getDiagram().getElement().eContaine r(); </FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> TreeIterator&lt;EObject&gt; l = c.eAllContents();</FONT>
<FONT COLOR="#000000"> this.selectedEObjects = new ArrayList&lt;EObject&gt;();</FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> this.selectedEObjects.addAll(c.getCoursewareModel().getTopic s()); </FONT>
<FONT COLOR="#000000"> while(l.hasNext()){</FONT>
<FONT COLOR="#000000"> EObject eObj = l.next();</FONT>
<FONT COLOR="#000000"> if(eObj instanceof Concept){</FONT>
<FONT COLOR="#000000"> this.selectedEObjects.add((Concept)eObj);</FONT>
<FONT COLOR="#000000"> //}else if(eObj instanceof Topic){</FONT>
<FONT COLOR="#000000"> // this.selectedEObjects.add((Topic)eObj);</FONT>
<FONT COLOR="#000000"> }else{}</FONT>
<FONT COLOR="#000000"> }</FONT>
<FONT COLOR="#000000"> // this.selectedEObjects.add((EObject)l.next());</FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> IBatchValidator validator = </FONT>
<FONT COLOR="#000000">(IBatchValidator)ModelValidationService.getInstance() </FONT>
<FONT COLOR="#000000"> .newValidator(EvaluationMode.BATCH);</FONT>
<FONT COLOR="#000000"> validator.setIncludeLiveConstraints(true);</FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> final IStatus status = validator.validate(selectedEObjects);</FONT>
<FONT COLOR="#000000"> </FONT>

<FONT COLOR="#000000">Christian W. Damus wrote:</FONT>

<FONT COLOR="#000000">&gt; Hi, Mark,</FONT>

<FONT COLOR="#000000">&gt; Sorry for not responding sooner.</FONT>

<FONT COLOR="#000000">&gt; Yeah, GMF provides an IAdaptableSelection interface that is implemented</FONT>
<FONT COLOR="#000000">&gt; by the selections in the diagrams, which provides convenient access to</FONT>
<FONT COLOR="#000000">&gt; the model elements (as opposed to the diagram views) that are selected.</FONT>
<FONT COLOR="#000000">&gt; Just adapt to EObject and you're cool.</FONT>

<FONT COLOR="#000000">&gt; If there's a bug in the action-delegate's handling of selection, perhaps</FONT>
<FONT COLOR="#000000">&gt; you could raise it? It won't do to have examples that don't demonstrate</FONT>
<FONT COLOR="#000000">&gt; working code. :-(</FONT>

<FONT COLOR="#000000">&gt; For debugging client-context issues, the best place to start is with a</FONT>
<FONT COLOR="#000000">&gt; breakpoint in the</FONT>

<FONT COLOR="#000000">&gt; getBindings(Collection&lt;IClientContext&gt;,</FONT >
<FONT COLOR="#000000">&gt; Collection&lt;IModelConstraint&gt;)</FONT>

<FONT COLOR="#000000">&gt; method of the</FONT>
<FONT COLOR="#000000">&gt; org.eclipse.emf.validation.internal.service.ClientContextMan ager. </FONT>

<FONT COLOR="#000000">&gt; You will see whether your constraint matches any of the incoming</FONT>
<FONT COLOR="#000000">&gt; client-contexts, which should suggest whether you are missing bindings</FONT>
<FONT COLOR="#000000">&gt; or whether you need to define an additional context. These contexts are</FONT>
<FONT COLOR="#000000">&gt; kind of notoriously tricky to get right (they're always tripping me up,</FONT>
<FONT COLOR="#000000">&gt; and I invented them!).</FONT>

<FONT COLOR="#000000">&gt; HTH,</FONT>

<FONT COLOR="#000000">&gt; Christian</FONT>


<FONT COLOR="#000000">&gt; On Tue, 2008-07-22 at 12:22 +0000, Mark Melia wrote:</FONT>

<FONT COLOR="#000000">&gt;&gt; Hi,</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; Just a quick update on this - in case anybody has the same problem.</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; I have established that the selectionChanged method of the </FONT>
<FONT COLOR="#000000">&gt;&gt; BatchValidateDelegate is called to any selection changes after the first </FONT>
<FONT COLOR="#000000">&gt;&gt; time the Validator is called. This means that the initial validation still </FONT>
<FONT COLOR="#000000">&gt;&gt; has no selectedEObjects but after the initial validation, the selected </FONT>
<FONT COLOR="#000000">&gt;&gt; element is found for any subsequent validations.</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; I have also noted that because our project is a GMF project, the </FONT>
<FONT COLOR="#000000">&gt;&gt; selectionChanged method had to be changed to handle editparts as opposed </FONT>
<FONT COLOR="#000000">&gt;&gt; to eObjects that were coming in the original EMF project. </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; The OCLConstraintProvider is now being invoked - but not giving the </FONT>
<FONT COLOR="#000000">&gt;&gt; correct result for the OCL I have defined - I think this might be a client </FONT>
<FONT COLOR="#000000">&gt;&gt; context issue.</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; Anybody with ideas, I would love to hear them.</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; Thanks,</FONT>
<FONT COLOR="#000000">&gt;&gt; Mark</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; Mark Melia wrote:</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; Sorry Christian for the confusion - that is the one i meant, the </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; org.eclipse.emf.validation.examples.ocl example.</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; I have included the plugin.xml below - thanks again:</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;plugin&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;extension point=&quot;org.eclipse.ui.editorActions&quot;&g t; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;editorContribution </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;org.eclipse.emf.validation.examples.general.edi torContribution&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; targetID=&quot;Mikael2High.diagram.part.MIKAEL2hDiagramE ditorID&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;menu</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;CAVIAr Validation&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; path=&quot;additions&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;Course.Validation&quot;&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;separator name=&quot;additions&quot;/&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/menu&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%ValidateElementsAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; icon=&quot;$nl$/icons/elcl16/validate_co.gif&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.BatchValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; menubarPath=&quot;Course.Validation/additions&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;org.eclipse.emf.validation.pde.example.general. ui.validateAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%EnableLiveValidationAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.EnableLiveValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; menubarPath=&quot;Course.Validation/additions&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.enableLiveValidationAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%ShowValidationEventsAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.ShowValidationEventsDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; style=&quot;toggle&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; state=&quot;false&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; menubarPath=&quot;Course.Validation/additions&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.showValidationEventsAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/editorContribution&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/extension&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; point=&quot;org.eclipse.ui.popupMenus&quot;&gt;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;viewerContribution</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; targetID=&quot;CaviarLow.presentation.CaviarLowEditorID& amp;quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;org.eclipse.emf.validation.examples.general.vie werContribution&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;menu</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%_UI_ValidationMenu_label&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; path=&quot;additions&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;org.eclipse.emf.validationMenuID&quot;& gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;separator name=&quot;additions&quot;/&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/menu&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%ValidateElementsAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; icon=&quot;$nl$/icons/elcl16/validate_co.gif&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.BatchValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; menubarPath=&quot;org.eclipse.emf.validationMenuID/addit ions&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;org.eclipse.emf.validation.pde.example.general. ui.validateAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%EnableLiveValidationAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.EnableLiveValidationDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; menubarPath=&quot;org.eclipse.emf.validationMenuID/addit ions&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.enableLiveValidationAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;action</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; label=&quot;%ShowValidationEventsAction.label&quot;</FONT >
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. actions.ShowValidationEventsDelegate&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; style=&quot;toggle&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; state=&quot;false&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; menubarPath=&quot;org.eclipse.emf.validationMenuID/addit ions&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> id=&quot;org.eclipse.emf.validation.pde.example.general. ui.showValidationEventsAction&quot;/&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/viewerContribution&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/extension&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; point=&quot;org.eclipse.emf.validation.constraintProvide rs&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;oclProvider&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;!-- Custom constraint provider using OCL documents --&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;constraintProvider</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; class=&quot;org.eclipse.emf.validation.examples.ocl.OCLC onstraintProvider&quot; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; category=&quot;Constraints from an OCL Document&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; cache=&quot;false&quot;&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;package namespaceUri=&quot;<A HREF="http://mikael.computing.dcu.ie/#2_0">http://mikael.computing.dcu.ie/#2_0&quot;/</A>&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;ocl path=&quot;constraints/library.ocl&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/constraintProvider&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/extension&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; point=&quot;org.eclipse.emf.validation.constraintBinding s&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;clientContext</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; default=&quot;false&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; id=&quot;MIKAEL2hClientContext&quot;&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;selector </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. constraints.ValidationDelegateClientSelector&quot;/& gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/clientContext&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;binding</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; context=&quot;MIKAEL2hClientContext&quot;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; category=&quot;mikael.validation&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/extension&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; point=&quot;org.eclipse.emf.validation.validationListene rs&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;listener </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"> class=&quot;org.eclipse.emf.validation.examples.general. listeners.ValidationListener&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;clientContext id=&quot;MIKAEL2hClientContext&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/listener&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/extension&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;extension</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; point=&quot;org.eclipse.emf.validation.ui.UIRegisteredCl ientContext&quot;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;clientContext id=&quot;MIKAEL2hClientContext&quot;/&gt;</FONT >
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/extension&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; &lt;/plugin&gt;</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; Christian W. Damus wrote:</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; Hi, Mark,</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; That example has nothing to do with validation. It's simply an</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; interactive OCL console. Perhaps you melded it with the</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; org.eclipse.emf.validation.examples.ocl example?</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; Perhaps if you can supply the plugin.xml that defines your</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; constraint-provider extension, that would help to diagnose your problem.</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; cW</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt; On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:</FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt;&gt; Hi Christian,</FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt;&gt; Thanks for helping once again. The example I am using is the Library </FONT>
<FONT COLOR="#000000">one </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt;&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000"><A HREF=" http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip"> http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip</A></FONT>
<FONT COLOR="#000000">&gt;&gt; </FONT>
<FONT COLOR="#000000">&gt;&gt;</FONT>


</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-mz9hryCaBRdDfhrrqHM+--
Re: Connecting editor action with OCL Constraint provider [message #59767 is a reply to message #59742] Fri, 25 July 2008 13:16 Go to previous message
Mark Melia is currently offline Mark MeliaFriend
Messages: 142
Registered: July 2009
Senior Member
Hi all,

Just to conclude this incase anyone is having a similar problem...

The problem seems to have been the way which in our project we load in the
OCL constraints everytime the validation is called, instead of just in the
initial validation as in the example code. This meant a series of boolean
checks were required to stop the loops, I think that these checks were
causing problems, but I am not sure.

I have reverted to the original OCLConstraintProvider written by Christian
and this works with the GMF version of the validation delegate. I still
have to figure out a better way to allow for OCL to be changed at runtime
(a business requirement), but will let the newsgroup know if I figure one
out. On the other hand if you have an idea let me know.

Mark

Christian W. Damus wrote:

> Hi, Mark,

> See some replies in-line, below.

> HTH,

> Christian


> On Wed, 2008-07-23 at 13:42 +0000, Mark Melia wrote:

>> Hey Christian,
>>
>> I nearly have this working, just trying to sort out one small context
>> issue. In my validation, I want to validate everthing in the model when
>> the user select validate. So the selected item is irrelevant, as all items
>> in the model will have to be validated.
>>
>> To do this, in the BatchValidateDelegate I set up my run method to read in
>> all elements of the model and add them to the selectedEObjects, but there


> Oo. By default, batch validation iterates over the objects contained by
> the selection, so you should only need to add the resource contents to
> your selection. Otherwise, you'll be iterating over all of the objects
> once to collect them, again to validate them, and in between the
> validator does a lot of work to remove from your selection all of the
> elements that are nested within other elements in the selection.


>> was context issues. I discovered when you add two different EObject types
>> to the selectedEObjects it doesnt work - is this correct? Do you have any
>> ideas why this is the case.


> What do you mean by "two different EObject types?" You can select
> instances of any number of different EClasses, from different EPackages,
> and even different client-contexts.




>> The below code works for me, but if I add in the commented out lines it
>> does not validate against the OCL constraints.


> I see that it is usurping the validator's job of determining which
> objects to evaluate constraints on by filtering the eAllContents().
> Except, as I mentioned, that it won't work that way because the
> validator will iterate contents anyway.

> Simply doing

> validator.validate(Collections.singletonList(c))

> should do the trick. Or, maybe you need to add the
> c.getCoursewareModel() to the list of objects to validate if it isn't
> contained by c.

> In any case, the way you're doing it shouldn't fail to work; it should
> just be inefficient. It looks like there's some kind of bug, maybe in
> the client-context handling. If you can produce a small reproducible
> test case as a bugzilla attachment, that would be most cool.

> P.S.

> I see that you are casting to CaviarImpl. It is recommended practice to
> treat *Impls as "internal" code in the Eclipse sense and use only the
> interfaces; e.g., Caviar.


>>
>> Thanks again for all your help,
>> Mark
>>
>> public void run(IAction action) {
>>
>>
>> ValidationDelegateClientSelector.running = true;
>>
>> MIKAEL2hDiagramEditor mikaelEditor =
>>
(MIKAEL2hDiagramEditor)MIKAEL2hEditorPlugin.getPlugin().getW orkbench().getActiveWorkbenchWindow().getActivePage().getAct iveEditor();
>> CaviarImpl c =
>> (CaviarImpl)mikaelEditor.getDiagram().getElement().eContaine r();
>>
>> TreeIterator<EObject> l = c.eAllContents();
>> this.selectedEObjects = new ArrayList<EObject>();
>>
>>
>> this.selectedEObjects.addAll(c.getCoursewareModel().getTopic s());
>> while(l.hasNext()){
>> EObject eObj = l.next();
>> if(eObj instanceof Concept){
>> this.selectedEObjects.add((Concept)eObj);
>> //}else if(eObj instanceof Topic){
>> // this.selectedEObjects.add((Topic)eObj);
>> }else{}
>> }
>> // this.selectedEObjects.add((EObject)l.next());
>>
>> IBatchValidator validator =
>> (IBatchValidator)ModelValidationService.getInstance()
>> .newValidator(EvaluationMode.BATCH);
>> validator.setIncludeLiveConstraints(true);
>>
>> final IStatus status = validator.validate(selectedEObjects);
>>
>>
>> Christian W. Damus wrote:
>>
>> > Hi, Mark,
>>
>> > Sorry for not responding sooner.
>>
>> > Yeah, GMF provides an IAdaptableSelection interface that is implemented
>> > by the selections in the diagrams, which provides convenient access to
>> > the model elements (as opposed to the diagram views) that are selected.
>> > Just adapt to EObject and you're cool.
>>
>> > If there's a bug in the action-delegate's handling of selection, perhaps
>> > you could raise it? It won't do to have examples that don't demonstrate
>> > working code. :-(
>>
>> > For debugging client-context issues, the best place to start is with a
>> > breakpoint in the
>>
>> > getBindings(Collection<IClientContext>,
>> > Collection<IModelConstraint>)
>>
>> > method of the
>> > org.eclipse.emf.validation.internal.service.ClientContextMan ager.
>>
>> > You will see whether your constraint matches any of the incoming
>> > client-contexts, which should suggest whether you are missing bindings
>> > or whether you need to define an additional context. These contexts are
>> > kind of notoriously tricky to get right (they're always tripping me up,
>> > and I invented them!).
>>
>> > HTH,
>>
>> > Christian
>>
>>
>> > On Tue, 2008-07-22 at 12:22 +0000, Mark Melia wrote:
>>
>> >> Hi,
>> >>
>> >> Just a quick update on this - in case anybody has the same problem.
>> >>
>> >> I have established that the selectionChanged method of the
>> >> BatchValidateDelegate is called to any selection changes after the first
>> >> time the Validator is called. This means that the initial validation
still
>> >> has no selectedEObjects but after the initial validation, the selected
>> >> element is found for any subsequent validations.
>> >>
>> >> I have also noted that because our project is a GMF project, the
>> >> selectionChanged method had to be changed to handle editparts as opposed
>> >> to eObjects that were coming in the original EMF project.
>> >>
>> >> The OCLConstraintProvider is now being invoked - but not giving the
>> >> correct result for the OCL I have defined - I think this might be a
client
>> >> context issue.
>> >>
>> >> Anybody with ideas, I would love to hear them.
>> >>
>> >> Thanks,
>> >> Mark
>> >>
>> >> Mark Melia wrote:
>> >>
>> >> > Sorry Christian for the confusion - that is the one i meant, the
>> >> > org.eclipse.emf.validation.examples.ocl example.
>> >>
>> >> > I have included the plugin.xml below - thanks again:
>> >> > <plugin>
>> >>
>> >> > <extension point="org.eclipse.ui.editorActions">
>> >> > <editorContribution
>> >>
>> >> > id=" org.eclipse.emf.validation.examples.general.editorContributi on "
>> >> > targetID="Mikael2High.diagram.part.MIKAEL2hDiagramEditorID" >
>> >> > <menu
>> >> > label="CAVIAr Validation"
>> >> > path="additions"
>> >> > id="Course.Validation">
>> >> > <separator name="additions"/>
>> >> > </menu>
>> >>
>> >> > <action
>> >> > label="%ValidateElementsAction.label"
>> >> > icon="$nl$/icons/elcl16/validate_co.gif"
>> >>
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
>> >> > menubarPath="Course.Validation/additions"
>> >>
>> >> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
>> >> > <action
>> >> > label="%EnableLiveValidationAction.label"
>> >>
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
>> >> > menubarPath="Course.Validation/additions"
>> >>
>> >> >
>> >>
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
>> >> > <action
>> >> > label="%ShowValidationEventsAction.label"
>> >>
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
>> >> > style="toggle"
>> >> > state="false"
>> >> > menubarPath="Course.Validation/additions"
>> >>
>> >> >
>> >>
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
>> >>
>> >> > </editorContribution>
>> >> > </extension>
>> >>
>> >> > <extension
>> >> > point="org.eclipse.ui.popupMenus">
>> >> > <viewerContribution
>> >> > targetID="CaviarLow.presentation.CaviarLowEditorID"
>> >>
>> >> > id=" org.eclipse.emf.validation.examples.general.viewerContributi on ">
>> >> > <menu
>> >> > label="%_UI_ValidationMenu_label"
>> >> > path="additions"
>> >> > id="org.eclipse.emf.validationMenuID">
>> >> > <separator name="additions"/>
>> >> > </menu>
>> >> > <action
>> >> > label="%ValidateElementsAction.label"
>> >> > icon="$nl$/icons/elcl16/validate_co.gif"
>> >>
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.actions.BatchVal idationDelegate "
>> >> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>> >>
>> >> > id=" org.eclipse.emf.validation.pde.example.general.ui.validateAc tion "/>
>> >> > <action
>> >> > label="%EnableLiveValidationAction.label"
>> >>
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.actions.EnableLi veValidationDelegate "
>> >> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>> >>
>> >> >
>> >>
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.enableLive ValidationAction "/>
>> >> > <action
>> >> > label="%ShowValidationEventsAction.label"
>> >>
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.actions.ShowVali dationEventsDelegate "
>> >> > style="toggle"
>> >> > state="false"
>> >> > menubarPath="org.eclipse.emf.validationMenuID/additions"
>> >>
>> >> >
>> >>
>>
id=" org.eclipse.emf.validation.pde.example.general.ui.showValida tionEventsAction "/>
>> >>
>> >> > </viewerContribution>
>> >> > </extension>
>> >>
>> >>
>> >>
>> >>
>> >> > <extension
>> >> > point="org.eclipse.emf.validation.constraintProviders"
>> >> > id="oclProvider">
>> >> > <!-- Custom constraint provider using OCL documents -->
>> >> > <constraintProvider
>> >>
>> >> > class=" org.eclipse.emf.validation.examples.ocl.OCLConstraintProvide r "
>> >> > category="Constraints from an OCL Document"
>> >> > cache="false">
>> >>
>> >> > <package namespaceUri="http://mikael.computing.dcu.ie/#2_0"/>
>> >>
>> >> > <ocl path="constraints/library.ocl"/>
>> >> > </constraintProvider>
>> >> > </extension>
>> >>
>> >>
>> >>
>> >> > <extension
>> >> > point="org.eclipse.emf.validation.constraintBindings">
>> >> > <clientContext
>> >> > default="false"
>> >> > id="MIKAEL2hClientContext">
>> >> > <selector
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.constraints.Vali dationDelegateClientSelector "/>
>> >> > </clientContext>
>> >> > <binding
>> >> > context="MIKAEL2hClientContext"
>> >> > category="mikael.validation"/>
>> >> > </extension>
>> >> > <extension
>> >> > point="org.eclipse.emf.validation.validationListeners">
>> >> > <listener
>> >> >
>> >>
>>
class=" org.eclipse.emf.validation.examples.general.listeners.Valida tionListener ">
>> >> > <clientContext id="MIKAEL2hClientContext"/>
>> >> > </listener>
>> >> > </extension>
>> >> > <extension
>> >> >
point="org.eclipse.emf.validation.ui.UIRegisteredClientContext ">
>> >> > <clientContext id="MIKAEL2hClientContext"/>
>> >> > </extension>
>> >> > </plugin>
>> >>
>> >> > Christian W. Damus wrote:
>> >>
>> >> >> Hi, Mark,
>> >>
>> >> >> That example has nothing to do with validation. It's simply an
>> >> >> interactive OCL console. Perhaps you melded it with the
>> >> >> org.eclipse.emf.validation.examples.ocl example?
>> >>
>> >> >> Perhaps if you can supply the plugin.xml that defines your
>> >> >> constraint-provider extension, that would help to diagnose your
problem.
>> >>
>> >> >> cW
>> >>
>> >>
>> >> >> On Mon, 2008-07-21 at 16:01 +0000, Mark Melia wrote:
>> >>
>> >> >>> Hi Christian,
>> >> >>>
>> >> >>> Thanks for helping once again. The example I am using is the Library
>> one
>> >> >>>
>> >> >
>> >>
>>
http://www.eclipse.org/downloads/download.php?file=/modeling /mdt/ocl/downloads/drops/1.2.0/R200806091714/mdt-ocl-example s-1.2.0.zip
>> >>
>> >>
>>
>>
Hi
Previous Topic:Parsing failed: ") unexpected token(s)" in helper.defineOperation(..) although number of p
Next Topic:OCL Expression
Goto Forum:
  


Current Time: Wed Nov 26 03:18:10 GMT 2014

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

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