Home » Eclipse Projects » Sirius » Simplify diagram creation
|
Re: Simplify diagram creation [message #1403355 is a reply to message #1403342] |
Wed, 23 July 2014 08:00 |
|
Hi Richard,
You do not have to be in a Modeling Project to be able to select
Viewpoints and Create Diagrams. You just need a "Representation File"
(.aird), as this is this file that holds the Viewpoint Selection and
stores the created representations.
The Modeling Project is just a convenience to create the aird file and
automatically associate any model created in this project to this aird
file. We cannot go much further in easing representation creation as we
do not know which models, viewpoints and representations should be created.
Regarding your question to "simply the creation of a diagram", if you
already know which kind of model should be created and which kind of
Viewpoint activated, you could decide to write your own Wizard that
would do these steps automatically.
Here are some APIs that may interest you in this context:
- Create a representation file
SessionManager.INSTANCE.getSession(myAirdURI, myProgressMonitor)
- Select a Viewpoint
Have a look at "ViewpointSelection", this class provides utility methods
to add a ViewpointSelection page to your own Wizards. If you do not want
to leave the end-user make the choice, you can use the
ChangeViewpointSelectionCommand
- Create a representation
DialectManager.INSTANCE.createRepresentation()
- Open an editor
DialectUIManager.INSTANCE.openEditor()
I also may take a look at what is done in the Ecore Tools Project Wizard
(far more complex operations but same idea)
http://git.eclipse.org/c/ecoretools/org.eclipse.ecoretools.git/tree/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/wizard/EcoreModelerWizard.java
Please let me know if I was not clear or if you have further question.
Regards,
Alex
Le 23/07/2014 08:20, Richard Meyer a écrit :
> Hi,
>
> I have successfully created a Sirius diagram editor and deployed to our
> RCP. Till now, to create a new diagram, the user has to do the following
> steps: - create a Modeling Project - create the EMF model file
> - select the viewpoint
> - create a new representation
>
> Is there a way to simplify the creation of a diagram for the end user
> (New-> DiagramXY)?
>
> Is the creation of a diagram only possible in a "Modeling Project"?
>
> Thanks in advance.
>
|
|
|
Re: Simplify diagram creation [message #1405051 is a reply to message #1403342] |
Wed, 06 August 2014 13:02 |
Richard Meyer Messages: 40 Registered: June 2012 |
Member |
|
|
Hy Alex,
many thanks for your quick response.
Unfortunately I have some problems with the implementation.
I think the first problem is that the viewpoint is not added:
//create viewpoint
IFile airdFile = project.getFile("representations.aird");
if(!airdFile.exists())
throw new Exception("could not found file:" + airdFile.getLocationURI());
Session session = SessionManager.INSTANCE.getSession(URI.createURI(airdFile.getLocationURI().toASCIIString()), monitor);
//adding the resource to Sirius session
AddSemanticResourceCommand addCommandToSession = new AddSemanticResourceCommand(session, fileURI, monitor );
session.getTransactionalEditingDomain().getCommandStack().execute(addCommandToSession);
//find and add viewpoint
Set<Viewpoint> viewpoints = ViewpointSelection.getViewpoints(FILE_EXTENSION);
if(viewpoints.isEmpty())
throw new Exception("Could not found viewpoint for file extension " + FILE_EXTENSION);
ViewpointSelection.Callback callback = new ViewpointSelectionCallbackWithConfimation();
@SuppressWarnings("restriction")
RecordingCommand command = new ChangeViewpointSelectionCommand(
session,
callback,
viewpoints, new HashSet<Viewpoint>(), monitor);
session.getTransactionalEditingDomain().getCommandStack().execute(command);
In the .aird file I can see that the resource file is successfully added, but the viewpoint is still missing.
If I debug the project I can see that ViewpointSelection.getViewpoints(FILE_EXTENSION); method returns the correct viewpoint.
Any help would be greatly appreciated.
Richard
|
|
|
Re: Simplify diagram creation [message #1405935 is a reply to message #1405051] |
Fri, 08 August 2014 14:40 |
|
Le 06/08/2014 15:02, Richard Meyer a écrit :
> //find and add viewpoint
> Set<Viewpoint> viewpoints =
> ViewpointSelection.getViewpoints(FILE_EXTENSION);
> if(viewpoints.isEmpty())
> throw new Exception("Could not found viewpoint for file extension
> " + FILE_EXTENSION);
>
> ViewpointSelection.Callback callback = new
> ViewpointSelectionCallbackWithConfimation();
> @SuppressWarnings("restriction")
> RecordingCommand command = new ChangeViewpointSelectionCommand(
> session,
> callback,
> viewpoints, new HashSet<Viewpoint>(),
> monitor);
>
> session.getTransactionalEditingDomain().getCommandStack().execute(command);
>
>
> In the .aird file I can see that the resource file is successfully
> added, but the viewpoint is still missing. If I debug the project I can
> see that ViewpointSelection.getViewpoints(FILE_EXTENSION); method
> returns the correct viewpoint.
I'm not sure this is the cause of your problem, but the instances of
Viewpoint you get from ViewpointSelection.getViewpoints(FILE_EXTENSION)
are the ones loaded in the global ViewpointRegistry (the central
registry which knows about all the viewpoints installed in the system).
Each individual Session is isolated into its own ResourceSet, so it must
have its own copy of the Viewpoints it uses loaded in its context. You
can use
SiriusResourceHelper.getCorrespondingViewpoint(session, viewpoint);
to transform the instances you get from ViewpointSelection into
equivalent instances loaded in the Session's own ResourceSet
(SiriusResourceHelper will take care of loading the .odesign needed in
the session if they are not already).
Try passing the "transformed" Viewpoint instances to
ChangeViewpointSelectionCommand.
--
Pierre-Charles David - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Pierre-Charles David - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Re: Simplify diagram creation [message #1409972 is a reply to message #1403342] |
Tue, 19 August 2014 13:00 |
Richard Meyer Messages: 40 Registered: June 2012 |
Member |
|
|
Hy Pierre,
many thanks for your help.
With your hint the code now is working.
Only one thing...
rootObject = session.getSemanticResources().iterator().next().getContents().get(0);
Did you know a smarter solution for translating my resource root object to the "session semantic root object" of sirius?
//create a sirius modeling project
IProject project = ModelingProjectManager.INSTANCE.createNewModelingProject(projectName, locationPath, true, monitor);
//create a resource file
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createPlatformResourceURI("/" + projectName + "/" + projectName + "." + FILE_EXTENSION, true);
Resource resource = resourceSet.createResource(fileURI);
EObject rootObject = MyFactory.eINSTANCE.createRootObject();
resource.getContents().add(rootObject);
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
resource.save(options);
//create viewpoint
IFile airdFile = project.getFile("representations.aird");
if(!airdFile.exists())
throw new Exception("could not found file:" + airdFile.getLocationURI());
URI airdFileURI = URI.createPlatformResourceURI(airdFile.getFullPath().toOSString(), true);
Session session = SessionManager.INSTANCE.getSession(airdFileURI, monitor);
//adding the resource also to Sirius session
AddSemanticResourceCommand addCommandToSession = new AddSemanticResourceCommand(session, fileURI, monitor );
session.getTransactionalEditingDomain().getCommandStack().execute(addCommandToSession);
session.save(monitor);
//find and add viewpoint
Set<Viewpoint> availableViewpoints = ViewpointSelection.getViewpoints(FILE_EXTENSION);
if(availableViewpoints.isEmpty())
throw new Exception("Could not found viewport for fileextension " + FILE_EXTENSION);
Set<Viewpoint> viewpoints = new HashSet<Viewpoint>();
for(Viewpoint p : availableViewpoints)
viewpoints.add(SiriusResourceHelper.getCorrespondingViewpoint(session, p));
ViewpointSelection.Callback callback = new ViewpointSelectionCallbackWithConfimation();
@SuppressWarnings("restriction")
RecordingCommand command = new ChangeViewpointSelectionCommand(
session,
callback,
viewpoints, new HashSet<Viewpoint>(), true, monitor);
TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
domain.getCommandStack().execute(command);
rootObject = session.getSemanticResources().iterator().next().getContents().get(0);
//create representation
Collection<RepresentationDescription> descriptions = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), rootObject );
if(descriptions.isEmpty())
throw new Exception("Could not found representation description for object: " + rootObject);
RepresentationDescription description = descriptions.iterator().next();
DialectManager viewpointDialectManager = DialectManager.INSTANCE;
Command createViewCommand = new CreateRepresentationCommand(session,
description, rootObject, projectName, monitor);
session.getTransactionalEditingDomain().getCommandStack().execute(createViewCommand);
SessionManager.INSTANCE.notifyRepresentationCreated(session);
//open editor
Collection<DRepresentation> representations = viewpointDialectManager.getRepresentations(description, session);
DRepresentation myDiagramRepresentation = representations.iterator().next();
DialectUIManager dialectUIManager = DialectUIManager.INSTANCE;
dialectUIManager.openEditor(session,
myDiagramRepresentation, monitor);
//save session and refresh workspace
session.save(monitor);
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
|
|
| | | |
Re: Simplify diagram creation [message #1700002 is a reply to message #1699990] |
Mon, 29 June 2015 15:06 |
|
Hi 'qwer qwer' (would be 'azer azer' on a French keyboard..)
Le 29/06/2015 16:30, qwer qwer a écrit :
> Hi,
>
> I'm using the code from Richard Meyer but I'm getting following exception:
I think you forgot to add your element to a resource and maybe also to
create and save it.
See the code from Richard Meyer:
EObject rootObject = MyFactory.eINSTANCE.createRootObject();
resource.getContents().add(rootObject);
>
>
> !MESSAGE Impossible to find an interpreter - Could not find a session
> for model element : mypackage.impl.RootObjectImpl@38657ca8 (name: "test)
> (id: "dsds") (description: "some test descr.")
> !STACK 0
> java.lang.RuntimeException
> at
> org.eclipse.sirius.tools.api.interpreter.InterpreterRegistry.getInterpreter(InterpreterRegistry.java:70)
>
> at
> org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:143)
> [...]
> org.eclipse.sirius.business.internal.dialect.DialectManagerImpl.createRepresentation(DialectManagerImpl.java:151)
>
> at
> org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand.doExecute(CreateRepresentationCommand.java:115)
> [...]
> org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
>
> at
> org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
>
> mypackage.gui.MyWizard.performFinish(MyWizard.java:177)
> [...]
The following NPE comes from the same cause: the semantic element has no
resource and Sirius cannot find a session for it.
> !ENTRY org.eclipse.ui 4 0 2015-06-29 16:18:44.318
> !MESSAGE Unhandled event loop exception
> !STACK 0
> java.lang.NullPointerException
> at
> org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.getAllInitialyActiveLayers(DDiagramSynchronizer.java:287)
>
> at
> org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.activateInitialLayers(DDiagramSynchronizer.java:270)
>
> at
> org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.initDiagram(DDiagramSynchronizer.java:226)
>
> at
> org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.initDiagram(DDiagramSynchronizer.java:57)
>
> at
> org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:147)
>
> at
> org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:160)
>
> at
> org.eclipse.sirius.business.internal.dialect.DialectManagerImpl.createRepresentation(DialectManagerImpl.java:151)
>
> at
> org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand.doExecute(CreateRepresentationCommand.java:115)
> [...]
> org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
>
> at mypackage.gui.MyWizard.performFinish(MyWizard.java:177)
> at
>
> The exception is coming from here:
>
> session.getTransactionalEditingDomain().getCommandStack().execute(createViewCommand);
>
> Does anyone have an idea how to solve this problem?
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
|
|
|
Goto Forum:
Current Time: Thu Sep 26 08:59:24 GMT 2024
Powered by FUDForum. Page generated in 0.04855 seconds
|