Skip to main content



      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 09:01 Go to next message
Eclipse UserFriend
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 09:34 Go to previous messageGo to next message
Eclipse UserFriend
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
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 10:03 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 12:48:31 EDT 2025

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

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

Back to the top