Skip to main content



      Home
Home » Eclipse Projects » Sirius » Attach EObject to Sirius Session
Attach EObject to Sirius Session [message #1700839] Tue, 07 July 2015 10:11 Go to next message
Eclipse UserFriend
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 11:41 Go to previous messageGo to next message
Eclipse UserFriend
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 01:13 Go to previous message
Eclipse UserFriend
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

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


Current Time: Thu May 15 06:53:00 EDT 2025

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

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

Back to the top