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 07:35 Go to next message
Han G is currently offline Han G
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 08:14 Go to previous messageGo to next message
Han G is currently offline Han G
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 08:21 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 761
Registered: July 2009
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 09:19 Go to previous messageGo to next message
Han G is currently offline Han G
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 09:30 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille Letavernier
Messages: 417
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
Re: Problems creating Papyrus models [message #1097296 is a reply to message #1097277] Thu, 29 August 2013 09:59 Go to previous messageGo to next message
Han G is currently offline Han G
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 03:46 Go to previous messageGo to next message
Miriam Hundemer is currently offline Miriam Hundemer
Messages: 9
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 04:07 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille Letavernier
Messages: 417
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
Re: Problems creating Papyrus models [message #1396582 is a reply to message #1385784] Tue, 08 July 2014 10:07 Go to previous message
Miriam Hundemer is currently offline Miriam Hundemer
Messages: 9
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
Previous Topic:Problems while generating new papyrus diagram since 1.0
Next Topic:CSS issues, nothing happens for style based on stereotype
Goto Forum:
  


Current Time: Thu Jul 24 00:38:49 EDT 2014

Powered by FUDForum. Page generated in 0.01765 seconds