Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » custom generation of UUID at save
custom generation of UUID at save [message #176458] Fri, 07 March 2008 14:01 Go to next message
Eclipse UserFriend
Originally posted by: mlooise.planet.nl

Hello,

I'm in need of a way to uniquely identify each EObject in my domain model. I
have therefore added a UUID attribute to every Eclass of my domain model. I
want to set this UUID uniquely (and automatically), upon a save action in
the GMF editor. What I've done until now is to add a custom function to the
doSaveDocument method in the DocumentProvider of the model. This sets the
UUID attribute of every EObject unique every time a document is altered. To
do this i had to create a custom AbstractTransactionalCommand, otherwise I
got problems with not being permitted to change the model in a direct way.

On new GMF diagrams this works ok, but on existing models, this gives
problems. Somehow the GMF resource (_diagram) isn't updated to use the new
UUID's. Instead the old UUID's still exist, causing the link between the
domain-model and the GMF-model-diagram to be lost. I am using the same
editing domain as the GMF editor (info.getEditingDomain()) from the
documentProvider.

Does anyone know of a method to explicitly maintain this link? Or even a
whole other way to perform this?

Any input is appreciated ,
Martin
Re: custom generation of UUID at save [message #176491 is a reply to message #176458] Sun, 09 March 2008 12:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.koehnlein.web.de

Martin -

the easiest way to get UUIDs is to use a customized XmiResourceImpl.
You'll find several descriptions how to do that in other posts in this
newsgroup. Basically it works as follows
1) Write a class that inherits from XMIResourceImpl and retruns true on
useUUIDS()
2) Write a ResourceFactory that creates instances of your Resource
implementation
3) Register that factory to the file extension of your model files.

Regards
Jan



Martin Looise wrote:
> Hello,
>
> I'm in need of a way to uniquely identify each EObject in my domain model. I
> have therefore added a UUID attribute to every Eclass of my domain model. I
> want to set this UUID uniquely (and automatically), upon a save action in
> the GMF editor. What I've done until now is to add a custom function to the
> doSaveDocument method in the DocumentProvider of the model. This sets the
> UUID attribute of every EObject unique every time a document is altered. To
> do this i had to create a custom AbstractTransactionalCommand, otherwise I
> got problems with not being permitted to change the model in a direct way.
>
> On new GMF diagrams this works ok, but on existing models, this gives
> problems. Somehow the GMF resource (_diagram) isn't updated to use the new
> UUID's. Instead the old UUID's still exist, causing the link between the
> domain-model and the GMF-model-diagram to be lost. I am using the same
> editing domain as the GMF editor (info.getEditingDomain()) from the
> documentProvider.
>
> Does anyone know of a method to explicitly maintain this link? Or even a
> whole other way to perform this?
>
> Any input is appreciated ,
> Martin
>
>
Re: custom generation of UUID at save [message #176534 is a reply to message #176491] Mon, 10 March 2008 09:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mlooise.planet.nl

Hello Jan,

I found a tutorial which I also examined before, using the technique that
you described at:
http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse. gmf.doc/tutorials/msl/clipboardTutorial.html

But here, they just basically only change the useUUIDs method, to return
true. I guess (haven't check it yet), that in this way UUID's will be
generated by the EMF framework (I thing using the EcoreUtil.generateUUID()).

But what I'm trying to do, is basically assiging the values of the ID field
of each class myself. Is this also supported in some way? ( I'm afraid not).
The problem is that I must be sure that the objects are identified uniquely,
also over multiple files (model instances). I don't think that the
UUIDgenerator can do this? This is why I implemented a custom ID generator,
that includes the project-folder, model-name, and element-id as its
identifier. This ID wil have to be set to an Eattribute that has isID =
true. (Every class in my model has such an attribute). Do you think this way
of working be combined with the customized XmiResourceImpl you suggested?

In short: Is it possible to use the useUUID = true method, together with a
customized ID assignment?

Thanks for the help,

Martin

"Jan K
Re: custom generation of UUID at save [message #176557 is a reply to message #176534] Mon, 10 March 2008 12:50 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------030704030604080605060503
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Martin,

Comments below.

Martin Looise wrote:
> Hello Jan,
>
> I found a tutorial which I also examined before, using the technique that
> you described at:
> http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse. gmf.doc/tutorials/msl/clipboardTutorial.html
>
> But here, they just basically only change the useUUIDs method, to return
> true. I guess (haven't check it yet), that in this way UUID's will be
> generated by the EMF framework (I thing using the EcoreUtil.generateUUID()).
>
Yes, and the resource itself will manage the two way mapping between
UUIDs and objects without need for features on the objects themselves to
manage that.
> But what I'm trying to do, is basically assiging the values of the ID field
> of each class myself. Is this also supported in some way? ( I'm afraid not).
>
Not directly. But your requirement isn't entirely clear yet.
> The problem is that I must be sure that the objects are identified uniquely,
> also over multiple files (model instances).
That's what UUIDs are for. As the name implies they are universally
unique identifiers. Even two separate machines generating UUIDs should
be producing unique ones.
> I don't think that the
> UUIDgenerator can do this?
It should!
> This is why I implemented a custom ID generator,
> that includes the project-folder, model-name, and element-id as its
> identifier.
UUIDs include things like the machines node address and use mechanisms
like a random number generator to seed the generation.
> This ID wil have to be set to an Eattribute that has isID =
> true.
Even when moving objects between resources, the UUID associated with it
should be properly maintained.
> (Every class in my model has such an attribute). Do you think this way
> of working be combined with the customized XmiResourceImpl you suggested?
>
I suppose you could specialize the setID method to store the UUID on the
instance but I don't think it's necessary.
> In short: Is it possible to use the useUUID = true method, together with a
> customized ID assignment?
>
With some customization, but I think this approach actually is worse
because when an object is copied the UUID attribute value will be copied
and that will result in the value not being universally unique. I think
you're solving a problem that doesn't need solving because it should
already be managed correctly by a resource that supports UUIDs.
> Thanks for the help,
>
> Martin
>
> "Jan K
Previous Topic:.options file
Next Topic:Custom property-sheet elements
Goto Forum:
  


Current Time: Sat Apr 20 04:08:33 GMT 2024

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

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

Back to the top