Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » setID() causes Connections to disappear
setID() causes Connections to disappear [message #214195] Sat, 27 December 2008 14:12 Go to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello everyone!

In my project I have Locations and Connections between the Locations.
Both Locations and Connections have an ID.

When I create Connections it works, but when I close my Editor and
reopen it, the Connections disappeared and the diagram is marked dirty.

I debugged my code multiple times and found out, that it doesn`t work,
when the ID is set during creation of the Connection. When the default
value for the ID is kept, everything works.

I try to describe it as detailed as possible:
In my project the IDs should counted up for each creation, like when I
create the third Location it has the ID 3 and when I create the second
Connection it has the ID 2.
I did this like it is described in this newsgroup article:"Label with
Feature Seq Initializer via OCL". This works perfect for Location but
not for Connection.

I found this out:
Because of the Feature Seq Initializer in the gmfmap file, the method
....diagram.edit.commands.ConnectionCreateCommand.doDefaultE lementCreation()
calls in addition to "normal state" the method
....diagram.providers.ElementInitializers.init_Connection_30 01, where I
can put my own code for the generation of the ID.
I debugged it multiple times and commented some lines here and there and
at least I commented out this above described call and put instead
"newElement.setID(2);", because thats what actual happens inside of
"init_Connection_3001".
Now the method looks like this:

protected EObject doDefaultElementCreation() {
Connection newElement = EditorFactory.eINSTANCE.createConnection();
getContainer().getShapes().add(newElement);
newElement.setSourceLocation(getSource());
newElement.setTargetLocation(getTarget());

//DsceditorElementTypes.init_Connection_3001(newElement); <- commented
out call

newElement.setID(2); // <- line I put instead

return newElement;
}

Now the surprise: When I comment out the line I put instead, everything
works fine. When not, the Connections disappear after restart of the
Editor.

But inside of setID nothing exciting happens. It just sets the ID...
The method setID is in the class ShapeImpl, because Connection and
Location both inherit the ID from Shape. It just looks like this,
nothing special:
public void setID(int newID) {
int oldID = iD;
iD = newID;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
EditorPackage.SHAPE__ID, oldID, iD));
}
And Location uses the exact same method to set its ID and everything
works fine!

How can such a little line cause such a big error??

Best wishes and thanks in advance!
Julia
Re: setID() causes Connections to disappear [message #214206 is a reply to message #214195] Sat, 27 December 2008 16:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

PS:
setID() is not just a problem during creation.
When I add a Connection and set the ID to 0 (no matter which ID was set
during creation) then the Connection survives the close and reopen of
the diagram.
When I set the ID to any other number, the Connection would disappear
after reopen.

This makes the whole issue even more cryptic...
Re: setID() causes Connections to disappear [message #214286 is a reply to message #214206] Tue, 30 December 2008 13:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

SOLUTION:

After a lot of testing and debugging I realized also a strange behaviour
on the other nodes as soon as they had another ID than 0.

And now I know what happened:
All of my nodes have an ID and somehow GMF started to use my own
Attribute "ID" instead of its own way to save and distinguish nodes.
I looked into the two diagram-files and saw, that nodes with ID=0 are
referenced with something like that: "sourceLocation="//@shapes.8"". As
soon as the node has an ID, it changes to "sourceLocation="2"".
That would be ok, as long as my ID would be unambiguous... but my ID is
just a bit like a name, its not an ID in the classical meaning. The
client wants it, that two nodes can have the same ID.
So you can imagine yourself what happens when there are more than one
node with the same ID: GMF mixes them all up, and I get strange
ClassCastExceptions from all over my code.

I think, I will make up a different attribute-name for the ID. I hope
this will prevent GMF from using my ID.
Re: setID() causes Connections to disappear [message #214293 is a reply to message #214286] Tue, 30 December 2008 14:08 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Cayla,

An EAttribute for which isID is true will be used as an ID whose value
must be unique within the resource regardless of the name of that attribute.


Cayla Sha wrote:
> SOLUTION:
>
> After a lot of testing and debugging I realized also a strange
> behaviour on the other nodes as soon as they had another ID than 0.
>
> And now I know what happened:
> All of my nodes have an ID and somehow GMF started to use my own
> Attribute "ID" instead of its own way to save and distinguish nodes.
> I looked into the two diagram-files and saw, that nodes with ID=0 are
> referenced with something like that: "sourceLocation="//@shapes.8"".
> As soon as the node has an ID, it changes to "sourceLocation="2"".
> That would be ok, as long as my ID would be unambiguous... but my ID
> is just a bit like a name, its not an ID in the classical meaning. The
> client wants it, that two nodes can have the same ID.
> So you can imagine yourself what happens when there are more than one
> node with the same ID: GMF mixes them all up, and I get strange
> ClassCastExceptions from all over my code.
>
> I think, I will make up a different attribute-name for the ID. I hope
> this will prevent GMF from using my ID.
Previous Topic:linking of properties with widgets.
Next Topic:delete references and update view
Goto Forum:
  


Current Time: Fri Dec 19 11:56:06 GMT 2014

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

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