Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to link business model (file) to diagram instance?(Need some help)
How to link business model (file) to diagram instance? [message #1708690] Fri, 18 September 2015 18:52 Go to next message
Rafal Filipiuk is currently offline Rafal FilipiukFriend
Messages: 14
Registered: September 2015
Junior Member
So I have my plugin project and when I launch the editor and create a new diagram (of my type), the latter is not pointing to any particular business model. Some of the features themselves (such as create()) will instantiate the eObject, and only when the user saves the diagram will the eObject get serialized into I'm not entirely sure how it works in the background, but when a create() is called (via user creating the box representing the eObject) and the eObject is instantiated, the editingDomain of the diagram holds a LazyLinkingResource pointing to From then on, the diagram's editingDomain will point to

Currently, is statically initialized in a java file, so it's relatively easy to point to the resource, update it, and save it within a transaction. The problem is that, because is static, every new diagram will point to it. What I want to do is have the editingDomain point to when the diagram is created, while somehow initializing a non-static instance of The file should just be called

How would I go about doing that? When a user creates a new diagram of myType using the plugin, where can I create I'm just not sure of who should take ownership of the resource. My thought was for the Diagram itself to create and an instance of the object to be modified/serialized, but I don't know where to begin.

Note that I have no experience with GEF/EMF, so everything is kind of hacked together and my knowledge of the domain is quite cursory. Any doc, protips, would help.


P.S. I apologize if any of the above is difficult to understand. I will elaborate as much as I can.
Re: How to link business model (file) to diagram instance? [message #1708814 is a reply to message #1708690] Mon, 21 September 2015 13:21 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member

you can define the file to store your domain object freely, I would recommend to do that in the create feature.

Did you have a look into the CreateEClassFeature in the tutorial? The coding of the final plugin as it is contained in the Graphiti SDK download contains the coding to add the domain object into the same file as the diagram:
// create EClass
EClass newClass = EcoreFactory.eINSTANCE.createEClass();
// Add model element to resource.
// We add the model element to the resource of the diagram for
// simplicity's sake. Normally, a customer would use its own
// model persistence layer for storing the business model separately.

The last line will get the resource (basically the EMF file) of the diagram and add the new domain object (newClass) to the contents of the file.

Just below you will see some commented out lines that could instead of the last line above be used to store domain objects in another file:
// Use the following instead of the above line to store the model
// data in a seperate file parallel to the diagram file
// try {
// try {
// TutorialUtil.saveToModelFile(newClass, getDiagram());
// } catch (IOException e) {
// e.printStackTrace();
// }
// } catch (CoreException e) {
// e.printStackTrace();
// }

It will use a helper class that uses the diagram file name, change the file extension and add the domain object there, so pretty much what you intend to do if I understood correctly.

Re: How to link business model (file) to diagram instance? [message #1709044 is a reply to message #1708814] Wed, 23 September 2015 14:18 Go to previous message
Rafal Filipiuk is currently offline Rafal FilipiukFriend
Messages: 14
Registered: September 2015
Junior Member
Thanks Michael, that put me on the right track. My understanding of resources and editingDomains is a bit limited so I had the wrong approach.
Previous Topic:Marquee Tool Help
Next Topic:Undo/Redo not working with DiagramEditor subclass
Goto Forum:

Current Time: Wed Feb 28 07:33:41 GMT 2024

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

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

Back to the top