Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Creating models (uml,notation and di) programatically tutorial
Creating models (uml,notation and di) programatically tutorial [message #1404359] Thu, 31 July 2014 13:46 Go to next message
Alexandre Giron is currently offline Alexandre GironFriend
Messages: 8
Registered: January 2014
Junior Member
Hi,

I'm trying to create some models by programming in Eclipse modelling tools, and I would like to view them in papyrus. Is there any tutorial or code snippet for creating di models? (Specially sysml models)

PS: I'm a beginner but I already see those topics (and the uml2 tools getting started):
www.eclipse.org/forums/index.php/m/1404122/
www.eclipse.org/forums/index.php/t/781914/


Any help is appreciated.
Thanks in advance,

Alexandre
Re: Creating models (uml,notation and di) programatically tutorial [message #1424271 is a reply to message #1404359] Mon, 15 September 2014 18:54 Go to previous messageGo to next message
András Dobreff is currently offline András DobreffFriend
Messages: 3
Registered: September 2014
Junior Member
Hi!

I'm also trying with this. After lots of search on this forum and in the papyrus repository:
eclipse.googlesource.com/papyrus/org.eclipse.papyrus/+/master
I've managed to build up an eclipse plugin that creates a papyrus project, inserts an existing .uml file, creates the Class Diagrams and drops the Classes on the diagrams.

I think the two links that you found are the best helps.


Here is a code, that creates a papyrus model
(path is a string and stands for Projectname/Modelname e.g. MyPapyrusProject/mypapyrusmodel, where you have a folder MyPapyrusProject with the 3 files: mypapyrusmodel.uml, mypapyrusmodel.di, mypapyrusmodel.notation )
I'm not saying that it is the best way but works Smile

ModelSet modelSet = new ModelSet();
		
		ModelsReader reader = new ModelsReader(); //Standard ModelsReader for Di + UML + Notation
		reader.readModel(modelSet);
		
		String sourceUmlPath = "C:\\uml.uml";
		String diFilePath = path+".di";
		String umlFilePath = path+".uml";

		URI diFileURI =  URI.createFileURI(diFilePath);
		URI umlFileURI = URI.createFileURI(umlFilePath);
		
		URI diPResURI =  URI.createPlatformResourceURI(diFilePath, true);
		URI umlPResURI =  URI.createPlatformResourceURI(umlFilePath, true);
		
		URI resolvedFile = CommonPlugin.resolve(diFileURI);
		IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resolvedFile.toFileString()));

		modelSet.createModels(diPResURI);
		
		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
		}
		
		modelSet.save(new NullProgressMonitor());
		modelSet.loadModels(umlPResURI);
		

URI UmlFileResURI = CommonPlugin.resolve(umlFileURI);
			IFile UmlFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(UmlFileResURI.toFileString()));
			InputStream  is = new FileInputStream(sourceUmlPath);
			
			modelSet.save(new NullProgressMonitor());
			UmlFile.setContents(is, true, false, new NullProgressMonitor());
			modelSet.loadModels(umlPResURI);

			IModelCreationCommand creationCommand = new CreateUMLModelCommand();
			creationCommand.createModel(modelSet);
Re: Creating models (uml,notation and di) programatically tutorial [message #1451154 is a reply to message #1424271] Thu, 23 October 2014 12:12 Go to previous messageGo to next message
Alexandre Giron is currently offline Alexandre GironFriend
Messages: 8
Registered: January 2014
Junior Member
Hi András,

thanks for the reply, but I'm having problems with imports.
Can you post some complete code?

Also, the 3 files (di, uml, notation) must be created first?

Thanks in advance!
Re: Creating models (uml,notation and di) programatically tutorial [message #1494848 is a reply to message #1451154] Mon, 01 December 2014 20:20 Go to previous messageGo to next message
András Dobreff is currently offline András DobreffFriend
Messages: 3
Registered: September 2014
Junior Member
Hello Alexandre,

first of all the 3 files don't need to be created. These files will be created as the ModelSet.save() function is called.

For the imports: In my code I use the followings:

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.extension.commands.IModelCreationCommand;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ModelsReader;
import org.eclipse.papyrus.infra.core.services.ExtensionServicesRegistry;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

(I'm not sure that all of them are necessary)

For debugging I think these imports will be enough. But if you want to export your plugin you have to add some plugin dependencies. (Open the plugin.xml and switch to the dependencies tab)
I use the followings:
org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.papyrus.infra.gmfdiag.common,
org.eclipse.papyrus.infra.core,
org.eclipse.papyrus.uml.tools,
org.eclipse.papyrus.uml.diagram.wizards,
org.eclipse.papyrus.uml.diagram.common,
org.eclipse.ui.ide,
org.eclipse.papyrus.infra.gmfdiag.commands,
org.eclipse.papyrus.uml.diagram.clazz,
org.eclipse.papyrus.uml.diagram.activity,
org.eclipse.papyrus.editor,
org.eclipse.jdt.core,
org.eclipse.core.expressions,
org.eclipse.ui.workbench,
org.junit,
org.eclipse.gef,
org.eclipse.gmf.runtime.diagram.ui

(and again I think you won't need all of these)

András
Re: Creating models (uml,notation and di) programatically tutorial [message #1496085 is a reply to message #1494848] Tue, 02 December 2014 19:25 Go to previous message
Alexandre Giron is currently offline Alexandre GironFriend
Messages: 8
Registered: January 2014
Junior Member
Thank you very much for your attention!

It's working now.
Previous Topic:Preferences functions
Next Topic:Value LifeLine in Papyrus
Goto Forum:
  


Current Time: Sun Mar 01 08:42:23 GMT 2015

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

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