Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText & Validation
XText & Validation [message #730002] Tue, 27 September 2011 13:03 Go to next message
Matteo Miraz is currently offline Matteo MirazFriend
Messages: 38
Registered: March 2011
Member
Hi,

I'm relatively new to XText & the whole Eclipse Modeling world.

I have to create an RCP application that provides the user with several ways to edit a model, including a textual editor (here I thought of XText) and a graphical one (I'm going to use graphiti).

The model itself has several semantic constraints, hence I have to provide some validation rules. There are simple constraints (for example those on the ID) and complex ones (e.g., the graph represented by the model must be acyclic).

I discovered that both EMF and XText provide support for validation, and I was wondering which is the one I should use. I would like to write the validation rules once and be able to use them both in the graphical editor and in the textual editor.

Does anybody have any suggestion?
Re: XText & Validation [message #730009 is a reply to message #730002] Tue, 27 September 2011 13:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Xtext can automatically use EMF constraints, which may be manually coded
in Java, or defined in OCL (see OCLinEcore). In due course you may also
be able to use Xcore, I presume that graphiti can access these too.

Xtext also supports a declarative CHECKS language, but I'm not sure
whether that is readily accessible outside Xtext.

Regards

Ed Willink

On 27/09/2011 14:03, Matteo wrote:
> Hi,
>
> I'm relatively new to XText & the whole Eclipse Modeling world.
>
> I have to create an RCP application that provides the user with
> several ways to edit a model, including a textual editor (here I
> thought of XText) and a graphical one (I'm going to use graphiti).
>
> The model itself has several semantic constraints, hence I have to
> provide some validation rules. There are simple constraints (for
> example those on the ID) and complex ones (e.g., the graph represented
> by the model must be acyclic).
>
> I discovered that both EMF and XText provide support for validation,
> and I was wondering which is the one I should use. I would like to
> write the validation rules once and be able to use them both in the
> graphical editor and in the textual editor.
>
> Does anybody have any suggestion?
Re: XText & Validation [message #730377 is a reply to message #730002] Wed, 28 September 2011 09:26 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Xtext offers a Java annotation based framework to add validation rules
for your DSL. Personally, I'd recommend this as it's realtively easy to
grasp for Java developers, IDE integrated, performs well, and reduces
the amount of boiler plate code necessary in other frameworks. The
validator is registered with EMF's low-level API for EValidators, so
they should work in any context (e.g. graphical, textual or tree editors).

Check (form the Xpand project) is a DSL for validation with an adapter
to register it to EMF, but is somehow outdated. There is also OCL, EMF
Validation and GMF's audit rules.

So in the end it's a matter of taste which framework you use as long as
they comply to the basic EMF mechanisms.


Am 27.09.11 15:03, schrieb Matteo:
> Hi,
>
> I'm relatively new to XText & the whole Eclipse Modeling world.
>
> I have to create an RCP application that provides the user with several
> ways to edit a model, including a textual editor (here I thought of
> XText) and a graphical one (I'm going to use graphiti).
>
> The model itself has several semantic constraints, hence I have to
> provide some validation rules. There are simple constraints (for example
> those on the ID) and complex ones (e.g., the graph represented by the
> model must be acyclic).
>
> I discovered that both EMF and XText provide support for validation, and
> I was wondering which is the one I should use. I would like to write the
> validation rules once and be able to use them both in the graphical
> editor and in the textual editor.
>
> Does anybody have any suggestion?


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: XText & Validation [message #730971 is a reply to message #730377] Thu, 29 September 2011 16:03 Go to previous messageGo to next message
Matteo Miraz is currently offline Matteo MirazFriend
Messages: 38
Registered: March 2011
Member
Hi,

I successfully created some constraint for my language by using XText's facilities, as explained in the XText guide.

Everything works pretty well, even with elements created programmatically. However I noticed that my validation rules are checked only if the element belongs to a resource (either directly or by containment in another element belonging to that resource). Is this the correct behavior, or I have made some mistakes?

I can understand that some constraints might depend on the other elements in the model (e.g., unique must analyze also the other elements), but other constraints are simple and only verify properties within a single element. Is it possible to execute this kind of constraints?

Thanks again,
Matteo
Re: XText & Validation [message #730988 is a reply to message #730971] Thu, 29 September 2011 16:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

(1) the validation is called by xtexts org.eclipse.xtext.validation.IResourceValidator
(2) why not simply navigating from one object to the others? or placing the validation rule at the root element of the dsl? this is how it ususally is done.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText & Validation [message #731007 is a reply to message #730971] Thu, 29 September 2011 17:01 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Matteo
> However I noticed that my validation rules are checked only if the
> element belongs to a resource (either directly or by containment in
> another element belonging to that resource). Is this the correct
> behavior, or I have made some mistakes?
All sorts of EMF functionalities depend on the resource. It is strongly
recommended.

Regards

Ed Willink
Previous Topic:Unable to run Xtext parser from JBoss 3.2.7
Next Topic:View encompassing multiple files
Goto Forum:
  


Current Time: Tue Apr 16 19:47:05 GMT 2024

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

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

Back to the top