Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Reusing validation in GMF editor
Reusing validation in GMF editor [message #985996] Sat, 17 November 2012 07:26 Go to next message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
Hi all,

I implemented validation constraints for a certain Xtext grammar. Earlier I
had implemented the constraints in Checks and injected them into a GMF
editor using the GMF Check adapter. Now I am trying to reuse the new
validation rules (in the Xtext grammar bundle) within the GMF editor(s). The
problem is that only the default EMF rules are used.

I found some threads and information about how to remove or override the EMF
default rules, for example
http://stackoverflow.com/questions/5861948/changing-default-validation-
messages recommends to add a fragment. My question relates to the other side
of the problem though: Why isn't validation from the Xtext DSL bundle
evaluated, too? I saw that the Xtext-based bundles are loaded in the product
(seen in the "Installed Software" dialog).

Could this behaviour be related to that the GMF editor is not using the
XtextResource yet, but still utilises the GMF Resource Factory? To put it
another way: Is it required to use the XtextResource in order to let
validation become work?
Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
because at the moment I am only using the GMF editor. Textual editor
integration is actually planned for another release.

Thanks for your help,

Axel
Re: Reusing validation in GMF editor [message #985999 is a reply to message #985996] Sat, 17 November 2012 10:32 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
The reason is that EMF, even though it offers an extension point to feed
all other registries, does not provide one to feed the EValidator.Registry.

In oAW, where the check adapter comes from, we've built our own EP,
initialized it with an IStartup and wrote the contributed validators
into EMF's registry.

In Xtext we no longer do that, as that is quite an invasive strategy
that could break other EMF clients.

So what you basically have to do is manually adding the validator to the
registry, e.g. when your editor starts.

Am 17.11.12 08:26, schrieb Axel Guckelsberger:
> Hi all,
>
> I implemented validation constraints for a certain Xtext grammar. Earlier I
> had implemented the constraints in Checks and injected them into a GMF
> editor using the GMF Check adapter. Now I am trying to reuse the new
> validation rules (in the Xtext grammar bundle) within the GMF editor(s). The
> problem is that only the default EMF rules are used.
>
> I found some threads and information about how to remove or override the EMF
> default rules, for example
> http://stackoverflow.com/questions/5861948/changing-default-validation-
> messages recommends to add a fragment. My question relates to the other side
> of the problem though: Why isn't validation from the Xtext DSL bundle
> evaluated, too? I saw that the Xtext-based bundles are loaded in the product
> (seen in the "Installed Software" dialog).
>
> Could this behaviour be related to that the GMF editor is not using the
> XtextResource yet, but still utilises the GMF Resource Factory? To put it
> another way: Is it required to use the XtextResource in order to let
> validation become work?
> Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
> because at the moment I am only using the GMF editor. Textual editor
> integration is actually planned for another release.
>
> Thanks for your help,
>
> Axel
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Reusing validation in GMF editor [message #986012 is a reply to message #985999] Sat, 17 November 2012 13:34 Go to previous messageGo to next message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
Hey Jan,

thank you for your quick reply which is very helpful.
My misunderstanding was indeed that I assumed Xtext doing the registration
itself (I think I had read this in an earlier post).

Working on it now.

Axel


Jan Koehnlein wrote:

> The reason is that EMF, even though it offers an extension point to feed
> all other registries, does not provide one to feed the
> EValidator.Registry.
>
> In oAW, where the check adapter comes from, we've built our own EP,
> initialized it with an IStartup and wrote the contributed validators
> into EMF's registry.
>
> In Xtext we no longer do that, as that is quite an invasive strategy
> that could break other EMF clients.
>
> So what you basically have to do is manually adding the validator to the
> registry, e.g. when your editor starts.
>
> Am 17.11.12 08:26, schrieb Axel Guckelsberger:
>> Hi all,
>>
>> I implemented validation constraints for a certain Xtext grammar. Earlier
>> I had implemented the constraints in Checks and injected them into a GMF
>> editor using the GMF Check adapter. Now I am trying to reuse the new
>> validation rules (in the Xtext grammar bundle) within the GMF editor(s).
>> The problem is that only the default EMF rules are used.
>>
>> I found some threads and information about how to remove or override the
>> EMF default rules, for example
>> http://stackoverflow.com/questions/5861948/changing-default-validation-
>> messages recommends to add a fragment. My question relates to the other
>> side of the problem though: Why isn't validation from the Xtext DSL
>> bundle evaluated, too? I saw that the Xtext-based bundles are loaded in
>> the product (seen in the "Installed Software" dialog).
>>
>> Could this behaviour be related to that the GMF editor is not using the
>> XtextResource yet, but still utilises the GMF Resource Factory? To put it
>> another way: Is it required to use the XtextResource in order to let
>> validation become work?
>> Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
>> because at the moment I am only using the GMF editor. Textual editor
>> integration is actually planned for another release.
>>
>> Thanks for your help,
>>
>> Axel
>>
>
>
Re: Reusing validation in GMF editor [message #986017 is a reply to message #985999] Sat, 17 November 2012 14:02 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4056
Registered: July 2009
Senior Member
Hi Jan

OCL has the same problem, requiring user installation and hoping that
layering a CompositeEValidator on top of whatever is already installed
won't do too much harm. This is partly to add validation and partly to
add an extended API that supports customizable diagnostics.

Do you think it's time for an EMF EValidator.Registry extension point
that addresses more recent requirements?

Regards

Ed Willink



On 17/11/2012 10:32, Jan Koehnlein wrote:
> The reason is that EMF, even though it offers an extension point to
> feed all other registries, does not provide one to feed the
> EValidator.Registry.
>
> In oAW, where the check adapter comes from, we've built our own EP,
> initialized it with an IStartup and wrote the contributed validators
> into EMF's registry.
>
> In Xtext we no longer do that, as that is quite an invasive strategy
> that could break other EMF clients.
>
> So what you basically have to do is manually adding the validator to
> the registry, e.g. when your editor starts.
>
> Am 17.11.12 08:26, schrieb Axel Guckelsberger:
>> Hi all,
>>
>> I implemented validation constraints for a certain Xtext grammar.
>> Earlier I
>> had implemented the constraints in Checks and injected them into a GMF
>> editor using the GMF Check adapter. Now I am trying to reuse the new
>> validation rules (in the Xtext grammar bundle) within the GMF
>> editor(s). The
>> problem is that only the default EMF rules are used.
>>
>> I found some threads and information about how to remove or override
>> the EMF
>> default rules, for example
>> http://stackoverflow.com/questions/5861948/changing-default-validation-
>> messages recommends to add a fragment. My question relates to the
>> other side
>> of the problem though: Why isn't validation from the Xtext DSL bundle
>> evaluated, too? I saw that the Xtext-based bundles are loaded in the
>> product
>> (seen in the "Installed Software" dialog).
>>
>> Could this behaviour be related to that the GMF editor is not using the
>> XtextResource yet, but still utilises the GMF Resource Factory? To
>> put it
>> another way: Is it required to use the XtextResource in order to let
>> validation become work?
>> Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
>> because at the moment I am only using the GMF editor. Textual editor
>> integration is actually planned for another release.
>>
>> Thanks for your help,
>>
>> Axel
>>
>
>
Re: Reusing validation in GMF editor [message #986023 is a reply to message #985999] Sat, 17 November 2012 15:58 Go to previous messageGo to next message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
Hi again,

in the meanwhile I wrote the following method:

    private void initValidationRegistry() {
        // unregister default validation rules from EMF
        final EValidator.Registry registry = EValidator.Registry.INSTANCE;
        final EcorePackage ecorePackage = EcorePackage.eINSTANCE;
        if (registry.containsKey(ecorePackage)) {
            registry.remove(ecorePackage);
        }

        // register validator from Xtext bundle
        final MyPackage myPackage = MyPackage.eINSTANCE;
        if (!registry.containsKey(myPackage)) {
            final Injector injector = new MyDslStandaloneSetup()
                    .createInjectorAndDoEMFRegistration();
            final MyDslJavaValidator validator = injector
                    .getInstance(MyDslJavaValidator.class);
            registry.put(myPackage, validator);
        }

        // testing output
        for (final Object v : registry.values()) {
            System.out.println(v.getClass());
        }
    }

It is called at the end of the preWindowOpen() method in the
DiagramEditorWorkbenchWindowAdvisor class.

Without applying this method the test output prints:
- class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1
- class org.eclipse.emf.ecore.impl.EcorePackageImpl$1
- class org.eclipse.xtext.validation.CompositeEValidator
This works fine, the default constraints from Ecore are validated.

After activating the method above I get:
- class org.example.xtext.validation.MyDslJavaValidator
- class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1

But then all diagram elements are broken. This happens always, even before starting any validation run at all. Also it happens independently of the Ecore package removal.

Is there anything obviously wrong in the initValidationRegistry() method?

I noticed that the CompositeEValidator is gone in the second test output.
Should I add my validator class to it instead of the registry?

Greetings,

Axel

[Updated on: Sat, 08 December 2012 19:26]

Report message to a moderator

Re: Reusing validation in GMF editor [message #986053 is a reply to message #986023] Sat, 17 November 2012 21:31 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
You have broken the holy rule of *never* using standalone setup in
Eclipse. It's meant for runtime only and will mess up all EMF registries.

This newsgroup is full of solutions to this problems.

Am 17.11.12 16:58, schrieb Axel Guckelsberger:
> Hi again,
>
> in the meanwhile I wrote the following method:
>
> private void initValidationRegistry() {
> // unregister default validation rules from EMF
> final EValidator.Registry registry = EValidator.Registry.INSTANCE;
> final EcorePackage ecorePackage = EcorePackage.eINSTANCE;
> if (registry.containsKey(ecorePackage)) {
> registry.remove(ecorePackage);
> }
>
> // register validator from Xtext bundle
> final MyPackage myPackage = MyPackage.eINSTANCE;
> if (!registry.containsKey(myPackage)) {
> final Injector injector = new MyDslStandaloneSetup()
> .createInjectorAndDoEMFRegistration();
> final MyDslJavaValidator validator = injector
> .getInstance(MyDslJavaValidator.class);
> registry.put(myPackage, validator);
> }
>
> // testing output
> for (final Object v : registry.values()) {
> System.out.println(v.getClass());
> }
> }
>
> It is called at the end of the preWindowOpen() method in the
> DiagramEditorWorkbenchWindowAdvisor class.
>
> Without applying this method the test output prints:
> - class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1
> - class org.eclipse.emf.ecore.impl.EcorePackageImpl$1
> - class org.eclipse.xtext.validation.CompositeEValidator
> This works fine, the default constraints from Ecore are validated.
> The attached file screen1.jpg shows how it looks like in the editor.
>
> After activating the method above I get:
> - class org.example.xtext.validation.MyDslJavaValidator
> - class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1
>
> The issue is shown in screen2.jpg
> - all diagram elements are broken
> - happens always, even before starting any validation run at all
> - happens independently of the Ecore package removal.
>
> Is there anything obviously wrong in the initValidationRegistry() method?
>
> I noticed that the CompositeEValidator is gone in the second test output.
> Should I add my validator class to it instead of the registry?
>
> Greetings,
>
> Axel


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Reusing validation in GMF editor [message #986054 is a reply to message #986017] Sat, 17 November 2012 21:34 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
Hi Ed,

my impression is that the EValidator API is not the best part of EMF,
maybe was even planned to be changed, and that this is why there hasn't
been a registry which would freeze an unfortunate solution.

Regards
Jan



Am 17.11.12 15:02, schrieb Ed Willink:
> Hi Jan
>
> OCL has the same problem, requiring user installation and hoping that
> layering a CompositeEValidator on top of whatever is already installed
> won't do too much harm. This is partly to add validation and partly to
> add an extended API that supports customizable diagnostics.
>
> Do you think it's time for an EMF EValidator.Registry extension point
> that addresses more recent requirements?
>
> Regards
>
> Ed Willink
>
>
>
> On 17/11/2012 10:32, Jan Koehnlein wrote:
>> The reason is that EMF, even though it offers an extension point to
>> feed all other registries, does not provide one to feed the
>> EValidator.Registry.
>>
>> In oAW, where the check adapter comes from, we've built our own EP,
>> initialized it with an IStartup and wrote the contributed validators
>> into EMF's registry.
>>
>> In Xtext we no longer do that, as that is quite an invasive strategy
>> that could break other EMF clients.
>>
>> So what you basically have to do is manually adding the validator to
>> the registry, e.g. when your editor starts.
>>
>> Am 17.11.12 08:26, schrieb Axel Guckelsberger:
>>> Hi all,
>>>
>>> I implemented validation constraints for a certain Xtext grammar.
>>> Earlier I
>>> had implemented the constraints in Checks and injected them into a GMF
>>> editor using the GMF Check adapter. Now I am trying to reuse the new
>>> validation rules (in the Xtext grammar bundle) within the GMF
>>> editor(s). The
>>> problem is that only the default EMF rules are used.
>>>
>>> I found some threads and information about how to remove or override
>>> the EMF
>>> default rules, for example
>>> http://stackoverflow.com/questions/5861948/changing-default-validation-
>>> messages recommends to add a fragment. My question relates to the
>>> other side
>>> of the problem though: Why isn't validation from the Xtext DSL bundle
>>> evaluated, too? I saw that the Xtext-based bundles are loaded in the
>>> product
>>> (seen in the "Installed Software" dialog).
>>>
>>> Could this behaviour be related to that the GMF editor is not using the
>>> XtextResource yet, but still utilises the GMF Resource Factory? To
>>> put it
>>> another way: Is it required to use the XtextResource in order to let
>>> validation become work?
>>> Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
>>> because at the moment I am only using the GMF editor. Textual editor
>>> integration is actually planned for another release.
>>>
>>> Thanks for your help,
>>>
>>> Axel
>>>
>>
>>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Reusing validation in GMF editor [message #986073 is a reply to message #986053] Sun, 18 November 2012 10:00 Go to previous messageGo to next message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
Hi Jan,

thanks for the pointer. Originally I used the activator but had the same
results which is why I tried out the standalone setup afterwards.

Now I replaced
final Injector injector = new
MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();

by
final Injector injector = MyDslActivator.getInstance()
..getInjector(MyDslActivator.ORG_EXAMPLE_MYDSL);


The test output prints the following values in the EValidator registry now:
- class org.eclipse.xtext.validation.CompositeEValidator
- class org.eclipse.emf.ecore.impl.EcorePackageImpl$1
- class org.example.xtext.validation.MyDslJavaValidator
- class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1

So the CompositeEValidator is not dropped anymore now. But beside this the
change does not change anything with regards to the behaviour in the editor
unfortunately.

I did also look at the MyDslExecutableExtensionFactory class, but first this
is not visible for being called by other bundles and second it delegates to
the activator again.

Axel

[Updated on: Sun, 18 November 2012 10:50]

Report message to a moderator

Re: Reusing validation in GMF editor [message #986081 is a reply to message #986073] Sun, 18 November 2012 15:10 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
Just getting the EValidator from the Injector should do the job, as all
the rest is performed by the method
AbstractInjectableValidator.register(EValidatorRegistrar)
which is automatically executed by the Injector.

Make sure your MyDslJavaValidator overrides getEPackages() to set the
EPackages for which it is evaluated.

If that still doesn't work, you have to debug the Diagnostician.

Am 18.11.12 11:00, schrieb Axel Guckelsberger:
> Hi Jan,
>
> thanks for the pointer. Originally I used the activator but had the same
> results which is why I tried out the standalone setup afterwards.
>
> Now I replaced
> final Injector injector = new
> MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
>
> by
> final Injector injector = MyDslActivator.getInstance()
> .getInjector(MyDslActivator.ORG_EXAMPLE_MYDSL);
>
>
> The test output prints the following values in the EValidator registry now:
> - class org.eclipse.xtext.validation.CompositeEValidator
> - class org.eclipse.emf.ecore.impl.EcorePackageImpl$1
> - class org.example.xtext.validation.MyDslJavaValidator
> - class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1
>
> So the CompositeEValidator is not dropped anymore now. But beside this the
> change does not change anything with regards to the behaviour in the editor
> unfortunately.
>
> I did also look at the MyDslExecutableExtensionFactory class, but first this
> is not visible for being called by other bundles and second it delegates to
> the activator again.
>
> Axel
>
>
>
> Jan Koehnlein wrote:
>
>> You have broken the holy rule of *never* using standalone setup in
>> Eclipse. It's meant for runtime only and will mess up all EMF registries.
>>
>> This newsgroup is full of solutions to this problems.
>>
>> Am 17.11.12 16:58, schrieb Axel Guckelsberger:
>>> Hi again,
>>>
>>> in the meanwhile I wrote the following method:
>>>
>>> private void initValidationRegistry() {
>>> // unregister default validation rules from EMF
>>> final EValidator.Registry registry =
>>> EValidator.Registry.INSTANCE; final EcorePackage ecorePackage =
>>> EcorePackage.eINSTANCE; if (registry.containsKey(ecorePackage))
>>> {
>>> registry.remove(ecorePackage);
>>> }
>>>
>>> // register validator from Xtext bundle
>>> final MyPackage myPackage = MyPackage.eINSTANCE;
>>> if (!registry.containsKey(myPackage)) {
>>> final Injector injector = new MyDslStandaloneSetup()
>>> .createInjectorAndDoEMFRegistration();
>>> final MyDslJavaValidator validator = injector
>>> .getInstance(MyDslJavaValidator.class);
>>> registry.put(myPackage, validator);
>>> }
>>>
>>> // testing output
>>> for (final Object v : registry.values()) {
>>> System.out.println(v.getClass());
>>> }
>>> }
>>>
>>> It is called at the end of the preWindowOpen() method in the
>>> DiagramEditorWorkbenchWindowAdvisor class.
>>>
>>> Without applying this method the test output prints:
>>> - class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1
>>> - class org.eclipse.emf.ecore.impl.EcorePackageImpl$1
>>> - class org.eclipse.xtext.validation.CompositeEValidator
>>> This works fine, the default constraints from Ecore are validated.
>>> The attached file screen1.jpg shows how it looks like in the editor.
>>>
>>> After activating the method above I get:
>>> - class org.example.xtext.validation.MyDslJavaValidator
>>> - class org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl$1
>>>
>>> The issue is shown in screen2.jpg
>>> - all diagram elements are broken
>>> - happens always, even before starting any validation run at all
>>> - happens independently of the Ecore package removal.
>>>
>>> Is there anything obviously wrong in the initValidationRegistry() method?
>>>
>>> I noticed that the CompositeEValidator is gone in the second test output.
>>> Should I add my validator class to it instead of the registry?
>>>
>>> Greetings,
>>>
>>> Axel
>>
>>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Reusing validation in GMF editor [message #989368 is a reply to message #985999] Wed, 05 December 2012 20:51 Go to previous messageGo to next message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
Hi Jan,

I debugged into the Diagnostician class and found out the reason for why
validation is not working.

In org.eclipse.xtext.validation.AbstractInjectableValidator the
isResponsible() returns false causing the validator to be skipped.

The logic in isResponsible() is as follows:

return !isLanguageSpecific() || Strings.equal(languageName,
getCurrentLanguage(context, eObject));

isLanguageSpecific() just checks whether the languageName member var is not
null, which returns true in my tests as languageName contains the name of my
xtext language.

The other option in the OR clause, that is the Strings.equal() call, returns
false because getCurrentLanguage() relies on either the context or a
XtextResource for determining the current language.
But the context is just created by Diagnostician#createDefaultContext() and
does therefore not contain CURRENT_LANGUAGE_NAME.

What can I do to resolve this?

I want to start using XtextResource anyway, so that might be the most
obvious possibility. But maybe there is also some way to define (read:
inject) the required information?

Axel



Jan Koehnlein wrote:

> The reason is that EMF, even though it offers an extension point to feed
> all other registries, does not provide one to feed the
> EValidator.Registry.
>
> In oAW, where the check adapter comes from, we've built our own EP,
> initialized it with an IStartup and wrote the contributed validators
> into EMF's registry.
>
> In Xtext we no longer do that, as that is quite an invasive strategy
> that could break other EMF clients.
>
> So what you basically have to do is manually adding the validator to the
> registry, e.g. when your editor starts.
>
> Am 17.11.12 08:26, schrieb Axel Guckelsberger:
>> Hi all,
>>
>> I implemented validation constraints for a certain Xtext grammar. Earlier
>> I had implemented the constraints in Checks and injected them into a GMF
>> editor using the GMF Check adapter. Now I am trying to reuse the new
>> validation rules (in the Xtext grammar bundle) within the GMF editor(s).
>> The problem is that only the default EMF rules are used.
>>
>> I found some threads and information about how to remove or override the
>> EMF default rules, for example
>> http://stackoverflow.com/questions/5861948/changing-default-validation-
>> messages recommends to add a fragment. My question relates to the other
>> side of the problem though: Why isn't validation from the Xtext DSL
>> bundle evaluated, too? I saw that the Xtext-based bundles are loaded in
>> the product (seen in the "Installed Software" dialog).
>>
>> Could this behaviour be related to that the GMF editor is not using the
>> XtextResource yet, but still utilises the GMF Resource Factory? To put it
>> another way: Is it required to use the XtextResource in order to let
>> validation become work?
>> Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
>> because at the moment I am only using the GMF editor. Textual editor
>> integration is actually planned for another release.
>>
>> Thanks for your help,
>>
>> Axel
>>
>
>
Re: Reusing validation in GMF editor [message #989370 is a reply to message #989368] Wed, 05 December 2012 20:57 Go to previous messageGo to next message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
> What can I do to resolve this?
>
> I want to start using XtextResource anyway, so that might be the most
> obvious possibility. But maybe there is also some way to define (read:
> inject) the required information?
>
To make this clear: I imagine something like injecting the
CURRENT_LANGUAGE_NAME into the context, so that validation would work also
with older model files which are still based on XML/XMI.
Re: Reusing validation in GMF editor [message #989543 is a reply to message #989368] Thu, 06 December 2012 16:44 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
I don't get it. Why don't you just override isLanguageSpecific() or
isResposible() in your validator to fit your needs?


Am 05.12.12 21:51, schrieb Axel Guckelsberger:
> Hi Jan,
>
> I debugged into the Diagnostician class and found out the reason for why
> validation is not working.
>
> In org.eclipse.xtext.validation.AbstractInjectableValidator the
> isResponsible() returns false causing the validator to be skipped.
>
> The logic in isResponsible() is as follows:
>
> return !isLanguageSpecific() || Strings.equal(languageName,
> getCurrentLanguage(context, eObject));
>
> isLanguageSpecific() just checks whether the languageName member var is not
> null, which returns true in my tests as languageName contains the name of my
> xtext language.
>
> The other option in the OR clause, that is the Strings.equal() call, returns
> false because getCurrentLanguage() relies on either the context or a
> XtextResource for determining the current language.
> But the context is just created by Diagnostician#createDefaultContext() and
> does therefore not contain CURRENT_LANGUAGE_NAME.
>
> What can I do to resolve this?
>
> I want to start using XtextResource anyway, so that might be the most
> obvious possibility. But maybe there is also some way to define (read:
> inject) the required information?
>
> Axel
>
>
>
> Jan Koehnlein wrote:
>
>> The reason is that EMF, even though it offers an extension point to feed
>> all other registries, does not provide one to feed the
>> EValidator.Registry.
>>
>> In oAW, where the check adapter comes from, we've built our own EP,
>> initialized it with an IStartup and wrote the contributed validators
>> into EMF's registry.
>>
>> In Xtext we no longer do that, as that is quite an invasive strategy
>> that could break other EMF clients.
>>
>> So what you basically have to do is manually adding the validator to the
>> registry, e.g. when your editor starts.
>>
>> Am 17.11.12 08:26, schrieb Axel Guckelsberger:
>>> Hi all,
>>>
>>> I implemented validation constraints for a certain Xtext grammar. Earlier
>>> I had implemented the constraints in Checks and injected them into a GMF
>>> editor using the GMF Check adapter. Now I am trying to reuse the new
>>> validation rules (in the Xtext grammar bundle) within the GMF editor(s).
>>> The problem is that only the default EMF rules are used.
>>>
>>> I found some threads and information about how to remove or override the
>>> EMF default rules, for example
>>> http://stackoverflow.com/questions/5861948/changing-default-validation-
>>> messages recommends to add a fragment. My question relates to the other
>>> side of the problem though: Why isn't validation from the Xtext DSL
>>> bundle evaluated, too? I saw that the Xtext-based bundles are loaded in
>>> the product (seen in the "Installed Software" dialog).
>>>
>>> Could this behaviour be related to that the GMF editor is not using the
>>> XtextResource yet, but still utilises the GMF Resource Factory? To put it
>>> another way: Is it required to use the XtextResource in order to let
>>> validation become work?
>>> Or is it even required to apply the Xtext-GMF-Glue-Code? I didn't yet
>>> because at the moment I am only using the GMF editor. Textual editor
>>> integration is actually planned for another release.
>>>
>>> Thanks for your help,
>>>
>>> Axel
>>>
>>
>>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Reusing validation in GMF editor [message #989584 is a reply to message #989543] Thu, 06 December 2012 20:49 Go to previous message
Axel Guckelsberger is currently offline Axel Guckelsberger
Messages: 224
Registered: July 2009
Senior Member
Thanks Jan,

I was just so happy that I found the problem cause that I oversaw that my validator is an inheriting class. Too easy to see Smile

Thanks again,

Axel
Previous Topic:xtext - creating a new EObject
Next Topic:Bug parsing Xtext file
Goto Forum:
  


Current Time: Tue Sep 30 13:50:52 GMT 2014

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

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