Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How can I get the id of a element in the source code
How can I get the id of a element in the source code [message #956371] Wed, 24 October 2012 13:01 Go to next message
Joshua Yang is currently offline Joshua Yang
Messages: 11
Registered: October 2012
Junior Member
Recently´╝îI am working on a project using the source code of Papyrus.
when I select a node of the model,i expect to get the element id.
The sitituation is like this,I can get the name,type et al.However what I want is to locate the element in the file(midel.uml),so I want to get the id.

the core code I write is as below:
List<IGraphicalEditPart> editParts = getSelectedElements();
Iterator<IGraphicalEditPart> it = editParts.iterator();
while(it.hasNext()) {
IGraphicalEditPart editPart = it.next();
if(!(editPart instanceof DiagramEditPart)) {
NamedElementImpl selectedElement = (NamedElementImpl)(editPart.resolveSemanticElement());
System.out.println(selectedElement.getName());
}
...

Can you please give a helping hand?
Re: How can I get the id of a element in the source code [message #956403 is a reply to message #956371] Wed, 24 October 2012 13:34 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille Letavernier
Messages: 457
Registered: February 2011
Senior Member
Hello,


The ID of the element is not accessible in the UML API, as it is not part of the UML specification. To precisely identify an Element in a UML Model, we typically rely on its XMI ID (i.e. serialization ID)

Here's how to retrieve this ID:

Element umlElement = ...
Resource resource = umlElement.eResource();
if (resource != null){
    String id = resource.getURIFragment(umlElement);
    ...
}



Regards,
Camille


Camille Letavernier
Papyrus developer
Re: How can I get the id of a element in the source code [message #956433 is a reply to message #956403] Wed, 24 October 2012 14:03 Go to previous message
Joshua Yang is currently offline Joshua Yang
Messages: 11
Registered: October 2012
Junior Member
Wow~~~~~
It works!!!
Camille,this problem bothered me not a bit.
Thank you very much indeed!^_^


Regards,
Joshua
Previous Topic:papyrus for INDIGO
Next Topic:Juno class diagram - no assist to add attributes
Goto Forum:
  


Current Time: Mon Sep 22 04:19:33 GMT 2014

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

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