Problem : Create VSM programatically during execution [message #1794369] |
Wed, 29 August 2018 15:59 |
Alejandro Rodriguez Messages: 1 Registered: August 2018 |
Junior Member |
|
|
Hi,
I have been these days trying to create a "virtual" VSM in runtime. What I try to do is, given a project with an "model.ecore" model, and by pressing a button, to create a VSM (originally just with group > viewpoint > diagram description) and the "model.aird" of this model get the option to use the new VSM right after created.
The way I am trying to do is:
FIRST:
Create the elements that the VSM will contain:
Group group = DESCRIPTION_FACTORY.createGroup();
group.setName("virtualCPN");
Viewpoint viewpoint = DESCRIPTION_FACTORY.createViewpoint();
viewpoint.setName("virtualCPNviewpoint");
viewpoint.setModelFileExtension("ecore");
group.getOwnedViewpoints().add(viewpoint);
DiagramDescription dd = DESCRIPTION_FACTORY_DIAGRAM.createDiagramDescription();
dd.setName("virtualCPNdiagram");
dd.setDomainClass("ecore.EPackage");
dd.setInitialisation(true);
viewpoint.getOwnedRepresentations().add(dd);
SECOND:
Register the viewpoint in the ViewpointRegistry (with the registerFromWorkspace method, since the plugins have been already loaded).
Set<Viewpoint> vps = new HashSet<Viewpoint>();
vps.add(viewpoint);
ViewpointRegistry.getInstance().registerFromWorkspace(vps);
THIRD:
Get the session from the "model.aird" and create the representation with the DialectManager:
DialectManager.INSTANCE.createRepresentation("virtualCPN", semanticRoot, dd, session, new NullProgressMonitor());
Command createViewCommand = new CreateRepresentationCommand(createdSession, dd, rootObject," virtualCPN" , monitor);
createdSession.getTransactionalEditingDomain().getCommandStack().execute(createViewCommand);
SessionManager.INSTANCE.notifyRepresentationCreated(session);
session.save(new NullProgressMonitor());
I am doing something feasible? I am not sure if I am far away from a solution or it's just some adjusts to be done.
This is the further I have got, in spite of I get recognised the entry when I right click in the model.aird and go to Viewpoints selection, I get a "Not found" in the representations view of the model.aird (see image below).
Edit: updated
[Updated on: Fri, 31 August 2018 06:58] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03194 seconds