Home » Modeling » Papyrus » Problems creating Papyrus models
| |
Re: Problems creating Papyrus models [message #1097237 is a reply to message #1097210] |
Thu, 29 August 2013 12:21 |
|
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 #1097277 is a reply to message #1097237] |
Thu, 29 August 2013 13:30 |
Camille Letavernier 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 #1385784 is a reply to message #1385778] |
Wed, 11 June 2014 08:07 |
Camille Letavernier 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
|
|
| | | | |
Goto Forum:
Current Time: Tue Sep 24 03:31:31 GMT 2024
Powered by FUDForum. Page generated in 0.04217 seconds
|