Attach EObject to Sirius Session [message #1700839] |
Tue, 07 July 2015 10:11  |
Eclipse User |
|
|
|
Hi all,
I have a running Session, created from a given representations file. Since I create the Session using the .aird-file and not a given EObject, no EObject is associated with the Session.
During the creation of a Diagram representation, the call
SessionManager.INSTANCE.getSession(EObject target)
is made, which is intended to retrieve the Session associated with the EObject. However, that is not possible for me since the EObject is not connected to the Session.
Is there a way for me to connect the two? What I want is basically a method like
session.attachEObject(EObject object)
or something like that.
It is possible my entire approach is wrong and I would greatly appreciate any potential help.
Best regards,
Axel Niklasson
|
|
|
|
Re: Attach EObject to Sirius Session [message #1700902 is a reply to message #1700854] |
Wed, 08 July 2015 01:13  |
Eclipse User |
|
|
|
Francois Cabrol wrote on Tue, 07 July 2015 15:41 From my understanding, you have to:
- either get the EObject from the semantic model (ie the set of EObjects) referenced by your .aird file
- or if the EObject has been initialized manually and is not already referenced in your .aird file, attach the resource containing your EObject (ie the file where your EObject is serialized) to the session
- or if the EObject is not intended to be serialized at all, use Sirius's transient attachment mechanism
Get the EObject from a resource referenced by an .aird file
Collection<Resource> resources = session.getSemanticResources();
/* Iterate through resources */
for (Resource resource : resources) {
/* Iterate through EObjects */
for (EObject eObject : resource.getContents()) {
...
}
}
Attach the resource containing an EObject to a session
session.getTransactionalEditingDomain().getCommandStack().execute(
new RecordingCommand(session.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
/* The eObject must be contained in an XMI resource */
/* See § "Data Management" here => http://eclipsesource.com/blogs/tutorials/emf-tutorial/ */
session.addSemanticResource(eObject.eResource().getURI(), monitor);
}
}
Attach a transient EObject to a session
eObject.eAdapters().add(new SessionTransientAttachment(session));
Hope it helps,
François
The third alternative was exactly what I was looking for. Now the session can be loaded in the diagram creation and I can finally continue working.
Thank you, good sir!
[Updated on: Wed, 08 July 2015 02:54] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04793 seconds