Creating new papyrus model programmatically with Oxygen [message #1768979] |
Tue, 25 July 2017 11:30 |
Ouliana Badaoui Messages: 6 Registered: July 2017 |
Junior Member |
|
|
Hello,
I'm new to papyrus and I'm currently trying to create a new papyrus model programmatically. The model such created should be part of a custom project type that I've already created.
I've already seen some solutions to this question for previous versions of papyrus; a few topics I used for my solution are this, this, and this. They seemed clear enough for me, except they don't work in my program. I'm working on Oxygen and some of the classes used in those solutions have been replaced so I'm stuck...
Here is what I do so far thanks to the solutions listed above:
/* Project created! */
// create files:
IFolder folder = project.getFolder(project.getName()); // project has same name as folder
IFile model = folder.getFile(project.getName()+".di"); // creation of the .di file
IFile notation = folder.getFile(project.getName()+".notation"); // creation of the .di file
IFile uml = folder.getFile(project.getName()+".uml"); // creation of the .di file
//at this point, no resources have been created
if (!project.isOpen()) project.open(null);
if (!folder.exists())
folder.create(IResource.NONE, true, null);
if (!model.exists()) {
byte[] bytes = "File contents".getBytes();
InputStream source = new ByteArrayInputStream(bytes);
model.create(source, IResource.NONE, null);
notation.create(source, IResource.NONE, null);
uml.create(source, IResource.NONE, null);
}
//create the model .di
ServicesRegistry registry = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
try {
// have to create the model set and populate it with the DI model
// before initializing other services that actually need the DI
// model, such as the SashModel Manager service
registry.startServicesByClassKeys(ModelSet.class);
} catch (ServiceException ex) {
// Ignore this exception: some services may not have been loaded,
// which is probably normal at this point
}
ModelSet modelSet = registry.getService(ModelSet.class);
modelSet.save(new NullProgressMonitor());
RecordingCommand command = new NewPapyrusModelCommand(modelSet, diPResURI);
modelSet.getTransactionalEditingDomain().getCommandStack().execute(command);
//Initializing the registry
try {
registry.startRegistry();
} catch (ServiceException ex) {
// Ignore this exception: some services may not have been loaded, which is probably normal at this point
}
registry.getService(IPageManager.class);
The project (and everything happening in this code snippet) are created on the performFinish() of a wizard I coded. The wizard is supposed to create a new custom project.
I attached to this topic a screenshot of the error I get when I launch my program. I can sort of understand where it comes from (the notation file) but I don't know how to fix it. I thought the modelSet.save was supposed to create the three files (.di, .notation, .uml) automatically but it didn't work before (hence why I create the files myself). I'm aware I'm probably doing a lot of things wrong but I don't know how to fix it.
Would anyone have a lead?
Thank you for reading through.
-
Attachment: test.png
(Size: 54.01KB, Downloaded 105 times)
|
|
|
Powered by
FUDForum. Page generated in 0.02555 seconds