Skip to main content


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 YangFriend
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 LetavernierFriend
Messages: 952
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
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 YangFriend
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: Thu Apr 25 00:19:22 GMT 2024

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

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

Back to the top