Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Validation on EAttributes
EMF Validation on EAttributes [message #897573] Tue, 24 July 2012 14:47 Go to next message
Simon Barnett is currently offline Simon BarnettFriend
Messages: 28
Registered: July 2012
Junior Member
Hi,

Is there any way to perform an EMF validation on individual EAttribute's of an EObject?

What I want to be able to do is to add an error message to a text field which represents the name of my EObject (which is an EAttribute of it) when that name is empty.

I can think of a way of doing it which would involve adding a constraint method to the overall EObject and setting the Diagnostic I create in that method's source value to be something which I can recognise in the UI and match it up but that seems wrong to me.

What I would really like is to be able to call something like validateName() on the field and for it to validate it for me in the same way that calling validate() on the entire model validates the model.

Any ideas?

Thanks,
Simon
Re: EMF Validation on EAttributes [message #897578 is a reply to message #897573] Tue, 24 July 2012 15:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30359
Registered: July 2009
Senior Member
Simon,

Comments below.

On 24/07/2012 4:47 PM, Simon Barnett wrote:
> Hi,
>
> Is there any way to perform an EMF validation on individual
> EAttribute's of an EObject?
Constraints can only be declared for an EClassifier. Of course it can
validate one or the attributes.
>
> What I want to be able to do is to add an error message to a text
> field which represents the name of my EObject (which is an EAttribute
> of it) when that name is empty.
You could also define an EDataType that wraps java.lang.String...
>
> I can think of a way of doing it which would involve adding a
> constraint method to the overall EObject and setting the Diagnostic I
> create in that method's source value to be something which I can
> recognise in the UI and match it up but that seems wrong to me.
It's the only direct way.
>
> What I would really like is to be able to call something like
> validateName() on the field
Of course fields don't have methods...
> and for it to validate it for me in the same way that calling
> validate() on the entire model validates the model.
If you define a constraint on the EClass, the generated validator will
have a method you can call directly.
>
> Any ideas?
>
> Thanks,
> Simon
Re: EMF Validation on EAttributes [message #897598 is a reply to message #897578] Tue, 24 July 2012 16:31 Go to previous messageGo to next message
Simon Barnett is currently offline Simon BarnettFriend
Messages: 28
Registered: July 2012
Junior Member
Hi Ed,

Yes, sorry, I didn't mean literally "call a method on the field" - I meant that I'd like to be able to call a method on the EAttribute to which the field is linked, if that makes sense. So maybe something like a validation method on the "name" attribute of the model which I can call when I know that the Text field is bound to that attribute.

Does that make sense?

I've already experimented with adding constraint methods to the overall EClass which represents the entire model and I *think* I've got that all working - it just seems hacky somehow to have to map the source of a diagnostic to a UI form element so that I can validate that particular attribute. But hey, if it's the only way, I suppose that's the only choice I have.
Re: EMF Validation on EAttributes [message #897601 is a reply to message #897598] Tue, 24 July 2012 16:44 Go to previous messageGo to next message
Simon Barnett is currently offline Simon BarnettFriend
Messages: 28
Registered: July 2012
Junior Member
Just to add to my reply, I think I'd be right in saying that in order to validate a field which was bound to the name attribute (for instance) I'd then be validating the entire model every time, no? This would be the case for the validation of any given field for any given attribute - the entire model would be validated?
Re: EMF Validation on EAttributes [message #897604 is a reply to message #897601] Tue, 24 July 2012 17:01 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30359
Registered: July 2009
Senior Member
Simon,

Comments below.

On 24/07/2012 6:44 PM, Simon Barnett wrote:
> Just to add to my reply, I think I'd be right in saying that in order
> to validate a field which was bound to the name attribute (for
> instance) I'd then be validating the entire model every time, no?
For each constraint on an EClass, there is a generated method in the
validator that can you can call directly with the one instance object,
e.g., EcoreValidator.validateEClass_AtMostOneID. (Sorry it's a
metamodel example; hopefully that doesn't confuse the issue.)
> This would be the case for the validation of any given field for any
> given attribute - the entire model would be validated?
Previous Topic:What is the best way to translate an EMF model instance to a standard XML model instance
Next Topic:URI mapping not including last (empty) segment
Goto Forum:
  


Current Time: Thu Aug 22 09:59:27 GMT 2019

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

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

Back to the top