Create representation error [message #1703153] |
Tue, 28 July 2015 23:04 |
Jim S. Messages: 17 Registered: October 2014 |
Junior Member |
|
|
Hi,
I try to create a model and a representation. However, I get an "Could not find a session for model element System[TRANSIENT]" error. This is the code I use for the creation:
final ResourceSet resourceSet = new ResourceSetImpl();
final Resource systemResource = resourceSet.createResource(systemURI);
final System newSystem = SystemFactory.eINSTANCE.createSystem();
newSystem.setEntityName(NEW_SYSTEM_NAME);
systemResource.getContents().add(newSystem);
systemResource.save(Collections.EMPTY_MAP);
progressMonitor.worked(50);
if (representationName != null) {
final URI representationFileURI = URI
.createPlatformResourceURI("/" + systemURI.segment(1) + "/representations.aird", true);
final Session session = SessionManager.INSTANCE.getExistingSession(representationFileURI);
if (session == null) {
throw new RuntimeException("Not a modelling project");
}
Viewpoint systemViewpoint = null; // FIXME expose with a constant
for (Viewpoint possibleViewpoint : session.getSelectedViewpoints(true)) {
if (ComposedProvidingRequiringEntityEditorConstants.SYSTEM_DESIGN_NAME.equals(possibleViewpoint.getName())) {
systemViewpoint = possibleViewpoint;
break;
}
}
if (systemViewpoint == null) { // FIXME expose with a constant
throw new RuntimeException("No suitable Viewpoint is registered");
}
RepresentationDescription representationDescription = null;
for (RepresentationDescription possibleRepresentationDescription : DialectManager.INSTANCE
.getAvailableRepresentationDescriptions(
Collections
.singleton(systemViewpoint),
newSystem)) {
representationDescription = possibleRepresentationDescription;
break;
}
if (representationDescription == null) {
throw new RuntimeException("No suitable RepresentationDescription has been found");
}
DRepresentation representation = DialectManager.INSTANCE.createRepresentation(representationName,
newSystem, representationDescription, session, progressMonitor);
DialectUIManager.INSTANCE.openEditor(session, representation, progressMonitor);
}
I already searched the forum for solutions but the ones that have been posted did not work for me. Do you know what I am doing wrong?
|
|
|
Re: Create representation error [message #1703180 is a reply to message #1703153] |
Wed, 29 July 2015 07:15 |
|
Le 29/07/2015 01:04, Jim S. a écrit :
> Hi,
>
> I try to create a model and a representation. However, I get an "Could
> not find a session for model element System[TRANSIENT]" error. This is
> the code I use for the creation:
>
> final ResourceSet resourceSet = new ResourceSetImpl();
> final Resource systemResource = resourceSet.createResource(systemURI);
Why do you not use the resource set of your current session ?
>
> final System newSystem = SystemFactory.eINSTANCE.createSystem();
> newSystem.setEntityName(NEW_SYSTEM_NAME);
> systemResource.getContents().add(newSystem);
>
> systemResource.save(Collections.EMPTY_MAP);
> progressMonitor.worked(50);
>
> if (representationName != null) {
> final URI representationFileURI = URI
> .createPlatformResourceURI("/" + systemURI.segment(1) +
> "/representations.aird", true);
> final Session session =
> SessionManager.INSTANCE.getExistingSession(representationFileURI);
Did you already open the session ?
> if (session == null) {
> throw new RuntimeException("Not a modelling project");
> }
> Viewpoint systemViewpoint = null; // FIXME expose with a constant
> for (Viewpoint possibleViewpoint :
> session.getSelectedViewpoints(true)) {
> if
> (ComposedProvidingRequiringEntityEditorConstants.SYSTEM_DESIGN_NAME.equals(possibleViewpoint.getName()))
> {
> systemViewpoint = possibleViewpoint;
> break;
> }
> }
> if (systemViewpoint == null) { // FIXME expose with a constant
> throw new RuntimeException("No suitable Viewpoint is registered");
> }
> RepresentationDescription representationDescription = null;
> for (RepresentationDescription possibleRepresentationDescription :
> DialectManager.INSTANCE
> .getAvailableRepresentationDescriptions(
> Collections
> .singleton(systemViewpoint),
> newSystem)) {
> representationDescription = possibleRepresentationDescription;
> break;
> }
> if (representationDescription == null) {
> throw new RuntimeException("No suitable
> RepresentationDescription has been found");
> }
>
> DRepresentation representation =
> DialectManager.INSTANCE.createRepresentation(representationName,
> newSystem, representationDescription, session,
> progressMonitor);
newSystem comes from the resourceSet created by you and not from the
resourceSet of your session.
> DialectUIManager.INSTANCE.openEditor(session, representation,
> progressMonitor);
> }
>
> I already searched the forum for solutions but the ones that have been
> posted did not work for me. Do you know what I am doing wrong?
Regards
--
Maxime - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Re: Create representation error [message #1703182 is a reply to message #1703180] |
Wed, 29 July 2015 07:25 |
|
Hi Jim,
Le 29/07/2015 09:15, Maxime Porhel a écrit :
> Le 29/07/2015 01:04, Jim S. a écrit :
>> Hi,
>>
>> I try to create a model and a representation. However, I get an "Could
>> not find a session for model element System[TRANSIENT]" error. This is
>> the code I use for the creation:
>>
>> final ResourceSet resourceSet = new ResourceSetImpl();
>> final Resource systemResource = resourceSet.createResource(systemURI);
>
> Why do you not use the resource set of your current session ?
You could use your own resource set to create and populate and save your
resource.
But you have to make sure the session reloaded it.
In a standard environment, the workspace will detect that you modified
the file and Sirius will reload the modified resources for each session
using this file.
>
>>
>> final System newSystem = SystemFactory.eINSTANCE.createSystem();
>> newSystem.setEntityName(NEW_SYSTEM_NAME);
>> systemResource.getContents().add(newSystem);
>>
>> systemResource.save(Collections.EMPTY_MAP);
>> progressMonitor.worked(50);
>>
>> if (representationName != null) {
>> final URI representationFileURI = URI
>> .createPlatformResourceURI("/" + systemURI.segment(1) +
>> "/representations.aird", true);
>> final Session session =
>> SessionManager.INSTANCE.getExistingSession(representationFileURI);
>
> Did you already open the session ?
>
>> if (session == null) {
>> throw new RuntimeException("Not a modelling project");
>> }
>> Viewpoint systemViewpoint = null; // FIXME expose with a constant
>> for (Viewpoint possibleViewpoint :
>> session.getSelectedViewpoints(true)) {
>> if
>> (ComposedProvidingRequiringEntityEditorConstants.SYSTEM_DESIGN_NAME.equals(possibleViewpoint.getName()))
>>
>> {
>> systemViewpoint = possibleViewpoint;
>> break;
>> }
>> }
>> if (systemViewpoint == null) { // FIXME expose with a constant
>> throw new RuntimeException("No suitable Viewpoint is
>> registered");
>> }
>> RepresentationDescription representationDescription = null;
>> for (RepresentationDescription possibleRepresentationDescription :
>> DialectManager.INSTANCE
>> .getAvailableRepresentationDescriptions(
>> Collections
>> .singleton(systemViewpoint),
>> newSystem)) {
>> representationDescription = possibleRepresentationDescription;
>> break;
>> }
>> if (representationDescription == null) {
>> throw new RuntimeException("No suitable
>> RepresentationDescription has been found");
>> }
>>
>> DRepresentation representation =
>> DialectManager.INSTANCE.createRepresentation(representationName,
>> newSystem, representationDescription, session,
>> progressMonitor);
>
> newSystem comes from the resourceSet created by you and not from the
> resourceSet of your session.
>
>> DialectUIManager.INSTANCE.openEditor(session, representation,
>> progressMonitor);
>> }
>>
>> I already searched the forum for solutions but the ones that have been
>> posted did not work for me. Do you know what I am doing wrong?
>
> Regards
>
--
Maxime - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Re: Create representation error [message #1703215 is a reply to message #1703212] |
Wed, 29 July 2015 12:30 |
|
Le 29/07/2015 14:14, Jim S. a écrit :
> Thanks for your reply!
>
> I created my own ResourceSet because I do not know how to access the
> Session`s ResourceSet. For the same reason I don`t know how I can make
> the session reload its ResourceSet.
>
> I tried opening the Session after retrieving it but that did not change
> the behavior. I was not sure whether the Session was already open since
> I retrieved it from the SessionManager.
If you retrieve it from the SessionManager, this indicates that it exist
and is opened.
Is your modified resource in the workspace ?
Do you have a Modeling Project ? (it will automatically add contained
files as semantic resources if EMF can load them.)
Did you already add your systemResource as semantic resources of the
current session ?
See
org.eclipse.sirius.business.api.session.Session.addSemanticResource(URI,
IProgressMonitor)
>
> Regards, Jim
Regards
--
Maxime - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Re: Create representation error [message #1703259 is a reply to message #1703215] |
Wed, 29 July 2015 20:57 |
Jim S. Messages: 17 Registered: October 2014 |
Junior Member |
|
|
I tried adding the Resource to the set which required wrapping it in a command. Both did not work. The project I work in is a Modeling Project.
I also refactored the code a bit:
final Session session = SessionManager.INSTANCE.getSession(
URI.createPlatformResourceURI("/" + systemURI.segment(1) + "/representations.aird", true),
monitor);
final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
monitor.worked(25);
final CreateSystemModelCommand createSystemModelCommand = new CreateSystemModelCommand(domain, systemURI);
domain.getCommandStack().execute(createSystemModelCommand);
final System createdSystem = createSystemModelCommand.getCreatedSystem();
monitor.worked(50);
if (createRepresentation) {
final CreateRepresentationCommand createRepresentationCommand = new CreateRepresentationCommand(session,
Activator.getDefault().COMPOSED_PROVIDING_REQUIRING_ENTITY_DIAGRAM, createdSystem, representationName,
monitor);
domain.getCommandStack().execute(createRepresentationCommand);
final DRepresentation createdRepresentation = createRepresentationCommand.getCreatedRepresentation();
monitor.worked(75);
DialectUIManager.INSTANCE.openEditor(session, createdRepresentation, monitor);
}
monitor.worked(100);
The execute method of the "CreateSystemModelCommand"
final System system = SystemFactory.eINSTANCE.createSystem();
system.setEntityName(systemURI.segment(systemURI.segmentCount() -1).split("\\.")[0]);
final Resource resource = resourceSet.createResource(systemURI);
resource.getContents().add(system);
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
throw new RuntimeException(e);
}
createdSystem = system;
I now use the session`s resource set (shouldn`t this take care the the resource is available to the session?).
Regards, Jim
[Updated on: Thu, 30 July 2015 16:48] Report message to a moderator
|
|
|
Re: Create representation error [message #1705608 is a reply to message #1703259] |
Mon, 17 August 2015 19:08 |
Jim S. Messages: 17 Registered: October 2014 |
Junior Member |
|
|
I still wasn't able to resolve this issue. Does anyone have an idea what I might be doing wrong?
EDIT: I was able to solve the problem:
I had difficulties reproducing it, because while debugging the created resource was added to the session automatically, in a normal environment it was not.
I now use a AddSemanticResourceCommand to make sure the Resource is attached to the Session.
[Updated on: Tue, 18 August 2015 15:57] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03979 seconds