Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Problems creating Papyrus models
Problems creating Papyrus models [message #1097210] Thu, 29 August 2013 11:35 Go to next message
Han G is currently offline Han GFriend
Messages: 11
Registered: August 2013
Junior Member
Hi,
I am trying to create a Papyrus model (*.uml, *.di and *.notation files) as is done here http://www.eclipse.org/forums/index.php/t/366898/

My snippet looks like this:
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.uml.tools.model.UmlModel;

...

UmlModel umlModel = new UmlModel();
DiModel diModel = new DiModel();
NotationModel notationModel = new NotationModel();
ModelSet modelSet = new ModelSet();
try {
      modelSet.registerModel(umlModel);
      modelSet.registerModel(diModel);
      modelSet.registerModel(notationModel);
      modelSet.createModels(URI.createPlatformResourceURI(<some path>, true));
}
catch (Exception e) {
      e.printStackTrace();
}

...


But this doesn't do anything (no resources are created and no exceptions thrown). I tried to create the UML model alone with:

UmlModel umlModel = new UmlModel();
umlModel.initializeEmptyModel();
umlModel.createModel(URI.createPlatformResourceURI("", true));


But this throws a NullPointerException at initializeEmptyModel() (if I remove this call, the NullPointerException is thrown at createModel(...))

Any ideas what I might have missed? I cannot create any model (DiModel or NotationModel) either without getting NullPointerExceptions.

Thanks for help
Han
Re: Problems creating Papyrus models [message #1097231 is a reply to message #1097210] Thu, 29 August 2013 12:14 Go to previous messageGo to next message
Han G is currently offline Han GFriend
Messages: 11
Registered: August 2013
Junior Member
Oh no!
I forgot the save call:
modelSet.save(monitor);

But now I get a BasicEList$BasicIndexOutOfBoundsException: index=0, size=0...
I noticed that it is caused by the DiModel (not adding diModel to the modelSet will produce the *.uml and .*notation files without errors)

Any ideas?
Re: Problems creating Papyrus models [message #1097237 is a reply to message #1097210] Thu, 29 August 2013 12:21 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi,

Is it possible that creating models requires services that are obtained
from the ServicesRegistry? You might try creating an
ExtensionServicesRegistry, asking it for the ModelSet (which will
actually be a more specialized implementation, such as for lazy-loading
or even CDO support), and using that. Of course, the service registry
would have be disposed when you've finished.

HTH,

Christian


On 2013-08-29 11:35:18 +0000, Han G said:

> Hi,
> I am trying to create a Papyrus model (*.uml, *.di and *.notation
> files) as is done here http://www.eclipse.org/forums/index.php/t/366898/
>
> My snippet looks like this:
>
> import org.eclipse.papyrus.infra.core.resource.ModelSet;
> import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
> import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
> import org.eclipse.papyrus.uml.tools.model.UmlModel;
>
> ..
>
> UmlModel umlModel = new UmlModel();
> DiModel diModel = new DiModel();
> NotationModel notationModel = new NotationModel();
> ModelSet modelSet = new ModelSet();
> try {
> modelSet.registerModel(umlModel);
> modelSet.registerModel(diModel);
> modelSet.registerModel(notationModel);
> modelSet.createModels(URI.createPlatformResourceURI(<some path>, true));
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> ..
>
>
> But this doesn't do anything (no resources are created and no
> exceptions thrown). I tried to create the UML model alone with:
>
>
> UmlModel umlModel = new UmlModel();
> umlModel.initializeEmptyModel();
> umlModel.createModel(URI.createPlatformResourceURI("", true));
>
>
> But this throws a NullPointerException at initializeEmptyModel() (if I
> remove this call, the NullPointerException is thrown at
> createModel(...))
>
> Any ideas what I might have missed? I cannot create any model (DiModel
> or NotationModel) either without getting NullPointerExceptions.
>
> Thanks for help
> Han
Re: Problems creating Papyrus models [message #1097268 is a reply to message #1097237] Thu, 29 August 2013 13:19 Go to previous messageGo to next message
Han G is currently offline Han GFriend
Messages: 11
Registered: August 2013
Junior Member
Quote:

Hi,

Is it possible that creating models requires services that are obtained
from the ServicesRegistry? You might try creating an
ExtensionServicesRegistry, asking it for the ModelSet (which will
actually be a more specialized implementation, such as for lazy-loading
or even CDO support), and using that. Of course, the service registry
would have be disposed when you've finished.

HTH,

Christian


I don't know much about ServiceRegistries but according to http://wiki.eclipse.org/Papyrus_Developer_Guide/How_To_Code_Examples I can get a ModelSet by
EObject eobject = ...; // You should know how to get your EObject :-)
ModelSet modelSet = ServiceUtilsForResource.getInstance().getModelSet(eobject.eResource());


where eobject would be a org.eclipse.uml2.uml.Model (which I created previously). But the registry call throws a ServiceNotFoundException. Do I really need a registry for just creating the files? It worked perfectly for the *.uml and *.notation file, just the *.di file breaks the save operation...

Regards,
Han
Re: Problems creating Papyrus models [message #1097277 is a reply to message #1097237] Thu, 29 August 2013 13:30 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi,


For the ModelSet tests, I use the following code:

ModelSet modelSet = new DiResourceSet();
modelSet.createsModels(diFile);
ServicesRegistry registry = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
try {
	registry.add(ModelSet.class, Integer.MAX_VALUE, modelSet);
	registry.startRegistry();
} catch (ServiceException ex) {
	//Ignore
}

IModelCreationCommand creationCommand = new CreateUMLModelCommand();
creationCommand.createModel(modelSet);
modelSet.save(new NullProgressMonitor());


This initializes basic Papyrus model (di + notation + uml), with a root Model in the UML resource

It relies on a little bit of deprecated code, as you're now supposed to use EMF URIs instead of Eclipse IFiles, and the DiResourceSet itself is deprecated, but you could replace it with the following code:

ModelSet modelSet = new ModelSet();

ModelsReader reader = new ModelsReader(); //Standard ModelsReader for Di + UML + Notation
reader.readModel(modelSet);

modelSet.createModels(diURI); //Use an EMF URI instead of an Eclipse IFile
ServicesRegistry registry = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
try {
	registry.add(ModelSet.class, Integer.MAX_VALUE, modelSet);
	registry.startRegistry();
} catch (ServiceException ex) {
	//Ignore
}

IModelCreationCommand creationCommand = new CreateUMLModelCommand();
creationCommand.createModel(modelSet);
modelSet.save(new NullProgressMonitor());


I didn't test the second snippet, but it should work, without using any deprecated code.


Regards,
Camille


Camille Letavernier
Re: Problems creating Papyrus models [message #1097296 is a reply to message #1097277] Thu, 29 August 2013 13:59 Go to previous messageGo to next message
Han G is currently offline Han GFriend
Messages: 11
Registered: August 2013
Junior Member
Hi,
your second snippet worked like a charm!

Thanks a lot and best regards
Han
Re: Problems creating Papyrus models [message #1385778 is a reply to message #1097277] Wed, 11 June 2014 07:46 Go to previous messageGo to next message
Miriam Hundemer is currently offline Miriam HundemerFriend
Messages: 12
Registered: February 2013
Junior Member
Hi Camille,

I read your post about the creation of a new ModelSet and I found the code in the Papyrus CreateModelWizard where a new Papyrus Model is created.

What I still don't get is what URI you are using. In the Papyrus code the URI is created from a diagramCategoryID somehow. But even after searching what felt like the whole papyrus code, I still don't have a clue what the diagramCategoryID is and where I could get one to create an new and empty UML Diagram Sad

As far as I understand, an already existing object can have a URI. So if I already had a .di file or a UML model I could use their URIs (maybe). But as I am trying to create a new ModelSet what do I use for my URI? I feel a bit stupid and I am quite sure I am missing something very obvious.

Could you please explain?

Thanks for help
Miriam
Re: Problems creating Papyrus models [message #1385784 is a reply to message #1385778] Wed, 11 June 2014 08:07 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Miriam,

A URI works more or less like a filesystem path. So, it doesn't need to exist. In EMF, URIs can reference either a "Resource" (i.e. a file), or a specific EObject in a Resource. In this case, we need the Resource URI.

The ModelSet#createModels(URI) method expects the URI of the *.di resource. So, if you want to create the model "myModel", in your current Workspace, in the project "myProject", and in the folder "myFolder", you can use this URI:

URI diURI = URI.createPlatformResourceURI("myProject/myFolder/myModel.di", true);


Also note that the project needs to be created first. You may also need to refresh the project afterwards, otherwise the model may not show up in the project explorer.

Camille


Camille Letavernier
Re: Problems creating Papyrus models [message #1396582 is a reply to message #1385784] Tue, 08 July 2014 14:07 Go to previous messageGo to next message
Miriam Hundemer is currently offline Miriam HundemerFriend
Messages: 12
Registered: February 2013
Junior Member
Hi Camille

thanks so much for your answer!! Everything works just fine now! I don't really know now what caused so many problems, but back then I was at a complete loss.

Thanks again and best regards

Miriam
Re: Problems creating Papyrus models [message #1404122 is a reply to message #1097210] Tue, 29 July 2014 17:52 Go to previous messageGo to next message
Alexandre Giron is currently offline Alexandre GironFriend
Messages: 8
Registered: January 2014
Junior Member
Hello,

I need some help for creating diagrams programatically (modelSet: di, notation and uml)

Can anyone post some complete code for that? I tried those snippets but doesn't work for me (maybe I'm missing imports?).

And
Is there any tutorial for creating SysML diagrams programatically??

Sorry, I'm a beginner and I really need that. Thanks anyway.

Re: Problems creating Papyrus models [message #1410006 is a reply to message #1385784] Tue, 19 August 2014 14:44 Go to previous messageGo to next message
Miriam Hundemer is currently offline Miriam HundemerFriend
Messages: 12
Registered: February 2013
Junior Member
Hi Camille,

after successfully creating my sequencediagram, I am now trying to create nice looking state machines Smile
So far I managed to create the .di, .notaion and .uml files without any problems. What I am trying to find now is a nice way to arrange the individual components of the diagram. Right now they are, initially, all drawn on top of each other and I am using the "ArrangeAll" function of papyrus afterwards to display everything neatly.

This works fine, but I was wondering if there is any way to either call the "ArrangeAll" command programmatically or to arrange the diagram components some other way.
I could of course assing a LayoutConstraint to each component, but then I would have to consider the logic of the diagram (e.g. states after a fork state should probably be displayed parallel, whereas after a join they should be one after the other etc.). This appears to quite complex and cumbersome and I don't really want to do it that way Confused
Additionally I am quite sure that there is a much easier way out there.

Have you got any Idea what I could do to arrange my states and edges nicely? I am happy for every input.

Miriam
Re: Problems creating Papyrus models [message #1410012 is a reply to message #1410006] Tue, 19 August 2014 15:02 Go to previous message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Miriam,

Papyrus doesn't provide any specific support for layout. However, you may have a look at Zest and/or Kieler. Both projects provide some powerful layout algorithms for GEF/GMF.

Zest is part of the Eclipse Release Train and can be installed from this update site: http://download.eclipse.org/releases/luna

Kieler is a separate project: http://www.informatik.uni-kiel.de/en/rtsys/kieler/

HTH,
Camille


Camille Letavernier
Previous Topic:Using Papyrus SysML table, possible to show stereotype?
Next Topic:Executable Models: How to model non trivial guard with Papyrus and Moka
Goto Forum:
  


Current Time: Thu Mar 28 12:02:47 GMT 2024

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

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

Back to the top