Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Creating new papyrus model programmatically with Oxygen(How to create a new papyrus model through code with Oxygen as part of a custom project)
Creating new papyrus model programmatically with Oxygen [message #1768979] Tue, 25 July 2017 11:30
Ouliana Badaoui is currently offline Ouliana BadaouiFriend
Messages: 6
Registered: July 2017
Junior Member

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());
	      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
			} 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); NullProgressMonitor());

			RecordingCommand command = new NewPapyrusModelCommand(modelSet, diPResURI);

			//Initializing the registry
			try {
			} catch (ServiceException ex) {
				// Ignore this exception: some services may not have been loaded, which is probably normal at this point

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 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 66 times)
Previous Topic:How to work around the lack of SysML diagram frames?
Next Topic:Use of Papyrus in Software Engineering Courses
Goto Forum:

Current Time: Sun Jul 12 13:42:52 GMT 2020

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

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

Back to the top