Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Validation Service(At ModelElement Level)
Validation Service [message #727617] Wed, 21 September 2011 16:28 Go to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member

I have a model where i have choice items as part of the model like name and qname, the qname is captured using two fields and when seralization is done I use custom xml value binding to take value form these fields

Can we have the Validation Service @ the model element level ? so that i can validate either of them is not null ? or any suggestions to do this ?

~Kamesh
Re: Validation Service [message #727639 is a reply to message #727617] Wed, 21 September 2011 18:20 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
There is an open enhancement request for 0.4 that tracks allowing ValidationService at model element level.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=329076

In this particular case, I would recommend attaching ValidationService to the individual properties as that will give you validation markers on the actual properties. Keep in mind that a ValidationService for a property can reference other properties as part of its validation logic. Just make sure to use @DependsOn annotation to mark the properties that validation is consuming or validation will not refresh when appropriate.

@Service( impl = PropAValidationService.class )
@DependsOn( { "PropB", "PropC" } )

...

@Service( impl = PropBValidationService.class )
@DependsOn( { "PropA", "PropC" } )

...

@Service( impl = PropCValidationService.class )
@DependsOn( { "PropA", "PropB" } )


- Konstantin

[Updated on: Wed, 21 September 2011 18:20]

Report message to a moderator

Re: Validation Service [message #728206 is a reply to message #727639] Thu, 22 September 2011 18:04 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
Is this the same case for properties that look up other properties using RefrenceService?
Re: Validation Service [message #728221 is a reply to message #728206] Thu, 22 September 2011 18:32 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Yes. You need to add @DependsOn declaration any time your property's value, default value, validation, enablement, etc. is dependent on state of other properties. In the case of a ReferenceValue property, there is a system validation service that contributes an error if ReferenceService is unable to resolve the reference. Thus, you need to specify a dependency on the target of the reference so that validation can be refreshed.

- Konstantin
Re: Validation Service [message #728231 is a reply to message #728221] Thu, 22 September 2011 18:51 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member

"In the case of a ReferenceValue property, there is a system validation service that contributes an error if ReferenceService is unable to resolve the reference. Thus, you need to specify a dependency on the target of the reference so that validation can be refreshed."

Can you please explain this ? am not getting you. I am facing a refresh problem with refrence values and when the refrence value is changed and the property thats is using the stale refrence is not showing the validation messages unless i touch it.
Re: Validation Service [message #728237 is a reply to message #728231] Thu, 22 September 2011 19:05 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Let's say you have a model with some entities and each entity has a property called id. Then suppose you have a property that references these entities...

@Reference( target = Entity.class )
@DependsOn( "/Entities/Id" )
@Service( impl = EntityReferenceService.class )

If you don't have the @DependsOn declaration, your reference validation will not refresh when it should. Take a look in samples. Like the IComponentDependency.Name in the architecture sample.

Makes sense?

- Konstantin
Re: Validation Service [message #728245 is a reply to message #728237] Thu, 22 September 2011 19:18 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
Thanks for detailing it. will look at the architecture sample
Re: Validation Service [message #728250 is a reply to message #728245] Thu, 22 September 2011 19:36 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
yeah it worked and references are now getting refreshed a nice learning thanks for the same.
Re: Validation Service [message #728370 is a reply to message #728250] Fri, 23 September 2011 06:52 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
Is it possible to trigger Sapphire Model refresh on when an project resource is created ?

e.g. I have a model which has resource bundles and locales, i show a warning to the user if there is no resource bundle available in the project for a given locale(s).
Now the user on the seeing he warning decides to create the respective locale which is IResource. Once the resource is created can I trigger the refresh of model ?

~Kamesh
Re: Validation Service [message #728556 is a reply to message #728370] Fri, 23 September 2011 13:26 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Sure. Just register a resource change listener through normal Eclipse facilities and when needed call refresh methods on IModelElement. You can register a resource change listener in your validation service init method and remove it in the dispose method.

- Konstantin
Re: Validation Service [message #728629 is a reply to message #728556] Fri, 23 September 2011 14:59 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
Also when i refresh the Root Model element will get cascaded to all child elements ?

any eclipse pointers/docs i can refer to create the listener ?
Re: Validation Service [message #728635 is a reply to message #728629] Fri, 23 September 2011 15:08 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
i am doing like this ResourcesPlugin.getWorkspace().addResourceChangeListener( listener ); in init and ResourcesPlugin.getWorkspace().removeResourceChangeListener( listener ); in dispose. in the resourceChanged method of the listener i can call modelElelement.refresh(). Correct me if am wrong ?
Re: Validation Service [message #728638 is a reply to message #728635] Fri, 23 September 2011 15:13 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
That looks correct. The important thing to keep in mind is that you will get notice of all changes to workspaces resources. It's very important to examine the delta provided in the event to determine if it is an event that you care about before calling refresh. There are various permutations of the refresh methods that allow you to control refresh granularity as appropriate. Of course, ideally you constrain refresh to the affected area, that's why I suggest doing listener registration in the validation service as that will give you a handle on the exact property that needs to be refreshed.

- Konstantin

Re: Validation Service [message #728643 is a reply to message #728638] Fri, 23 September 2011 15:24 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
I am filtering by .properties thats required for my current scenario and rightly in side the init/dispose method.

Also tell me how to get the asyncExec object inside validation service ?
Re: Validation Service [message #728661 is a reply to message #728643] Fri, 23 September 2011 15:50 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
The Display class has static methods to retrieve the default display, but you should not be referencing UI classes like Display from your model code or using asyncExec from the model. Is something not working when you do not do this?

- Konstantin
Re: Validation Service [message #728683 is a reply to message #728661] Fri, 23 September 2011 16:27 Go to previous messageGo to next message
Kamesh Sampath is currently offline Kamesh SampathFriend
Messages: 213
Registered: July 2009
Senior Member
i was referring a help where they showed like that, so is it enough i just call modelelement.refresh(property) from my listener ?
Re: Validation Service [message #728689 is a reply to message #728683] Fri, 23 September 2011 16:41 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
The general recommendation in resource change listeners is to not spend a lot of time in your event handler as workspace is locked during resource event notification and Eclipse can appear frozen to users. There are many ways to accomplish this beyond asyncExec. For instance, you can start a thread.

On whether it's appropriate to do a refresh of a single property inline, it's subjective. You can try and see if you observe any problems. If I was writing the code, I would be inclined to use a thread to be on the safe side.

- Konstantin
Previous Topic:Sapphire.Jump
Next Topic:Generating Code
Goto Forum:
  


Current Time: Thu Mar 28 23:18:54 GMT 2024

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

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

Back to the top