Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Attach EObject to Sirius Session
Attach EObject to Sirius Session [message #1700839] Tue, 07 July 2015 14:11 Go to next message
Axel Niklasson is currently offline Axel NiklassonFriend
Messages: 11
Registered: June 2015
Junior Member
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 #1700854 is a reply to message #1700839] Tue, 07 July 2015 15:41 Go to previous messageGo to next message
Francois Cabrol is currently offline Francois CabrolFriend
Messages: 32
Registered: January 2015
Member
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
Re: Attach EObject to Sirius Session [message #1700902 is a reply to message #1700854] Wed, 08 July 2015 05:13 Go to previous message
Axel Niklasson is currently offline Axel NiklassonFriend
Messages: 11
Registered: June 2015
Junior Member
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 06:54]

Report message to a moderator

Previous Topic:No dialects avaliable when creating representation programmatically
Next Topic:Edge Visualization & Creation Problems
Goto Forum:
  


Current Time: Sun Jan 17 20:19:11 GMT 2021

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

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

Back to the top