Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Constraint problem (one instance constraint)
Constraint problem (one instance constraint) [message #207555] Tue, 30 September 2008 16:26 Go to next message
Eclipse UserFriend
Originally posted by: balancedblend.gmx.de

Hello,

I just tested the gmf constraints. Link constraints work well, I
successfully prohibited linking to certain nodes.

Now however I want to ensure, that "node x" (inheriting from "node y")
might only be created once, whereas "node y" can exist arbitrary often.
I added a constraint to "node x's" node mapping, but the mechanism seems
not to work at all. Regardless of what I specify in the constraint body
(even "awdwadaw"), the effect is always the same:
When I create a node x, the editor is dirty, but no visible node was
created. If I create a node y now, it appears twice, one of them being a
node x looking like node y.
Validation is enabled. What am I doing wrong? And could you make a
suggestion for a "one instance" constraint?

Thanks in advance!

Regards,
Johannes
Re: Constraint problem (one instance constraint) [message #207619 is a reply to message #207555] Wed, 01 October 2008 12:13 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Johannes,

looks like you have to add following constraint to Node Y mapping: "not oclIsKindOf(X)"

-----------------
Alex Shatalin
Re: Constraint problem (one instance constraint) [message #207674 is a reply to message #207619] Thu, 02 October 2008 09:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: balancedblend.gmx.de

Hello Alex,

thanks for your help. To be honest, I don't really understand yet, how
to correctly formulate ocl constraints for gmf and where to place them.
I searched around a lot, but found nothing helpful.

So far, I added my constraints to the node mapping. This always caused
errors upon creation of the node (editor was dirty, but no visual
representation). The constraint you suggested was the first one that did
not destroy the node creation, but I don't really understand what it does.
I've tried the following to get a singleton contraint for node x:

self.allInstances()->size() < 2

after assuming "self" refers to an object instance I tried
X.allInstances()->size() < 2

I also tried
context X inv:
self.allInstances()->size() < 2
which also didn't work.

I followed the mindmap tutoria's validation part and created an audit
containter, but my constraint was always disabled.

So to sum it up, my questions are:
What is the difference between putting a constraint into an audit
container and adding it directly to the node mapping?
And how can I enforce, that only one instance of node X is created?


Alex Shatalin schrieb:
> Hello Johannes,
>
> looks like you have to add following constraint to Node Y mapping: "not
> oclIsKindOf(X)"
>
> -----------------
> Alex Shatalin
>
>
Re: Constraint problem (one instance constraint) [message #207786 is a reply to message #207674] Fri, 03 October 2008 09:23 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Johannes,

>The constraint you suggested was the first one that did not destroy the
node creation,
>but I don't really understand what it does
AFAIU you have a one of hte tipical configurations in your model and this
is why I suggested you adding this constraint. AFAIU in your domain model
EClass "X" has a supertype "Y", both has dedicated node mappings. As a result
particular domain model element XImpl is instance of X metaclass and in the
same time is instance of Y metaclass. As a result GMF-generatedd code can
not handle this situation correctly because it's unclear wich particular
diagram element should be created for this very XImpl (XNode or YNode). To
help GMF and resolve this ambiguity i suggested you adding constraint "not
oclIsKindOf(X)" to the node mapping for Y metaclass. In this case GMF rules
for the diagram representation was changed - all elements that are instances
of Y metaclass and NOT instances of X metaclass should be visualized as YNode,
so we resolved this indeterminacy and GMF-generated code should be working
properly for this use case.


> What is the difference between putting a constraint into an audit
> container and adding it directly to the node mapping?
Constraints formulated as "audits" should be processed on diagram validation
execution. As a result you'll see a set of problems in problem view representing
corresponding audit violations in the selected model.
Constraints specified in the node mapping should be checked on element creation/diagram
update to enable/disable or update diagram contents in accordance. In other
words particular diagram element should be visible on a diagram only if corresponding
constraint is satisfied.

> And how can I enforce, that only one instance of node X is created?
I think you should keep back reference from X to it's container and specify
constraint like: "self.xContainer.x->size() < 2".


BTW, you have another option - you can create JAVA constraint and code it
in java.
-----------------
Alex Shatalin
Previous Topic:Creation of a node without link to the model
Next Topic:GMF 2.0.2 messes up the text of the figures
Goto Forum:
  


Current Time: Tue Jan 19 06:47:02 GMT 2021

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

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

Back to the top