Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to set the xmi:id in the generated XML based file
How to set the xmi:id in the generated XML based file [message #1015760] Sat, 02 March 2013 11:45 Go to next message
Philipp El is currently offline Philipp ElFriend
Messages: 14
Registered: September 2012
Junior Member
Hi,

the code below adds a new node "SemanticElement" to the domain.

public final String fileSource = "models/PhilippDA.brms";
public final String fileDest = "models/PhilippDA_gen.brms";

Resource resource = ModelUtils.loadFileResource(new File(fileSource));
Domain domain = ModelUtils.getDomain(resource);
Diagram diagram = ModelUtils.getDiagram(resource);

SemanticElement se = CmFactory.eINSTANCE.createSemanticElement();
se.setName("test");
ModelUtils.addToDomain(se, domain, null).execute();
ModelUtils.saveToFile(domain, new File(fileDest));



in the generated file it looks as follows:

<contains xsi:type="cm:SemanticElement" name="test"/>

My first question: How can is set the xmi:id attribute, so that it looks as follow:

<contains xsi:type="cm:SemanticElement" xmi:id="_BG05gI3wEeG4R6fg5itl5w" name="test"/>


My second question: How can i add the SemanticElement to the diagram, so that it looks as follows:

<children xmi:id="_BG380I3wEeG4R6fg5itl5w" type="2002" element="_BG05gI3wEeG4R6fg5itl5w">
      <children xsi:type="notation:DecorationNode" xmi:id="_BG4j4I3wEeG4R6fg5itl5w" type="5002"/>
      <styles xsi:type="notation:DescriptionStyle" xmi:id="_BG380Y3wEeG4R6fg5itl5w"/>
      <styles xsi:type="notation:FontStyle" xmi:id="_BG380o3wEeG4R6fg5itl5w" fontName="Segoe UI"/>
      <styles xsi:type="notation:FillStyle" xmi:id="_BG38043wEeG4R6fg5itl5w"/>
      <styles xsi:type="notation:HintedDiagramLinkStyle" xmi:id="_BG381I3wEeG4R6fg5itl5w"/>
      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_BG381Y3wEeG4R6fg5itl5w" x="624" y="108"/>
    </children>


Thank you very much!
Best regards,

Philipp

[Updated on: Sat, 02 March 2013 11:47]

Report message to a moderator

Re: How to set the xmi:id in the generated XML based file [message #1015764 is a reply to message #1015760] Sat, 02 March 2013 13:06 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi Philipp,

your first question:

the used resource implementation is responsible for generating and persisting the xmi ids. I don't know the class ModelUtils you are using to get the resource implementation, but normally, if you receive a Resource implementation via a ResourceSet, the class ResourceFactoryRegistryImpl is used to map the file extension to a resource implementation.
Ensure, that your file extension 'brms' is registered to a resource implementation that returns true in the method protected boolean useUUIDs(). (For example the GMFResourceImpl)

your second question:

You can add your semantic element to the diagram via diagram.setElement(semanticElement).

Best regards,

Andreas
Re: How to set the xmi:id in the generated XML based file [message #1016443 is a reply to message #1015764] Wed, 06 March 2013 13:25 Go to previous messageGo to next message
Philipp El is currently offline Philipp ElFriend
Messages: 14
Registered: September 2012
Junior Member
Andreas Muelder wrote on Sat, 02 March 2013 08:06
Hi Philipp,

your first question:

the used resource implementation is responsible for generating and persisting the xmi ids. I don't know the class ModelUtils you are using to get the resource implementation, but normally, if you receive a Resource implementation via a ResourceSet, the class ResourceFactoryRegistryImpl is used to map the file extension to a resource implementation.
Ensure, that your file extension 'brms' is registered to a resource implementation that returns true in the method protected boolean useUUIDs(). (For example the GMFResourceImpl)

your second question:

You can add your semantic element to the diagram via diagram.setElement(semanticElement).

Best regards,

Andreas


Hi Andreas,

the first problem is fixed, but the second one doesn't work so.
My code looks as follows:

SemanticElement se = CmFactory.eINSTANCE.createSemanticElement();
se.setName("Test");
diagram.setElement(se);
....


The position (x,y) of the element should be a constant value, for example (0,0).
Thank you very much!

Best regards,

Philipp
Re: How to set the xmi:id in the generated XML based file [message #1016558 is a reply to message #1016443] Wed, 06 March 2013 22:24 Go to previous message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi Philipp,

find the appropriate Node for your semantic model element. (It may be a children of your Diagram.). Then you can set a layout constraint with the location like this:

Node view = ...;
Bounds bounds = NotationFactory.eINSTANCE.createBounds();
bounds.setX(10);
bounds.setY(10);
view.setLayoutConstraint(bounds);


Best regards,

Andreas
Previous Topic:Dsl.provider cannot be resolved to a type
Next Topic:Connection Constraint
Goto Forum:
  


Current Time: Tue Apr 16 09:47:24 GMT 2024

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

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

Back to the top