Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to create a papayrus model programatically(How to create a papayrus model programatically)
How to create a papayrus model programatically [message #893612] Wed, 04 July 2012 17:44 Go to next message
Michael Gärtner is currently offline Michael Gärtner
Messages: 8
Registered: June 2012
Junior Member
Hi at all,

I'm developing a plugin for eclipse that generates UML from JavaScript code.
I would like to know how to create a papyrus model and a corresponding diagram. e.g. Class diagram programatically.

Thanks for Help

Michael
Re: How to create a papayrus model programatically [message #893815 is a reply to message #893612] Thu, 05 July 2012 10:45 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille Letavernier
Messages: 399
Registered: February 2011
Senior Member
Hello Michael,

There's a tool in the Papyrus additional components (Extra plug-ins), which is dedicated to generating Diagrams from a Semantic UML Model, according to a template (The template describes which diagrams should be created, and which elements should be displayed).

You can download it from the Juno version of Papyrus ("Help", "Install Papyrus Additional Components"). If the tool doesn't match your needs, you can still look into its source code to see how it generates a diagram, programmatically. Please note that this generation tool is still experimental.


Regards,
Camille
Re: How to create a papayrus model programatically [message #894855 is a reply to message #893815] Tue, 10 July 2012 15:20 Go to previous messageGo to next message
Michael Gärtner is currently offline Michael Gärtner
Messages: 8
Registered: June 2012
Junior Member
Hi Camille,

this tool does not help. But Ifound the solution to create the Model.

I used the ModelSet implementation.

private void createModels(String path) {
    	umlModel = new UmlModel();
    	diModel = new DiModel();
    	notationModel = new NotationModel();
    	modelset = new ModelSet();
		try {
			modelset.registerModel(umlModel);
			modelset.registerModel(diModel);
			modelset.registerModel(notationModel);
			modelset.createsModels(jsProject.getFile(path));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


thanks anyway.

Now I faced another issue. In the um2 package from eclipse there is a UMLFactory class. Is there something similar in papyrus? I want do add a package or a class programmatically to the model. How I can do this?

Regards
Michael
Re: How to create a papayrus model programatically [message #896158 is a reply to message #894855] Tue, 17 July 2012 08:42 Go to previous messageGo to next message
Alexandra Bardiau is currently offline Alexandra Bardiau
Messages: 21
Registered: March 2012
Junior Member
Hi Michael,

Here's a way to programatically add elements to the model:


                 EObject model = null;
                 /*
		 * Get root element
		 */
		try {
			model = UmlUtils.getUmlModel().lookupRoot();
		} catch (NotFoundException e1) {
			e1.printStackTrace();
		} catch (NullPointerException ne) {
		}

		if (model != null) {

			/*
			 * Get the model package
			 */
			modelpackage = (org.eclipse.uml2.uml.Package) model;

                        /*
			 * Add new elements to the model
			 */
			TransactionalEditingDomain ted = TransactionUtil
					.getEditingDomain(model);
			ted.getCommandStack().execute(new RecordingCommand(ted) {

				modelpackage.createOwnedInterface("Itf");

                        }
                }



This question has been answered before on the Papyrus forum, as it is here that I've found out how to do it too. Use the forum's search function to find what you're looking for.

Cheers!
Re: How to create a papayrus model programatically [message #898956 is a reply to message #896158] Sun, 29 July 2012 06:26 Go to previous messageGo to next message
Michael Gärtner is currently offline Michael Gärtner
Messages: 8
Registered: June 2012
Junior Member
Thanks for your answers.

I successfully created the uml model with all the classes and their members and methods.

Now I want to create the corresponding diagram programatically.

I tried to do it like I did it with UML2TOOLS but it fails. I stuck again. Could anybody Help?

Regards Michael
Re: How to create a papayrus model programatically [message #899005 is a reply to message #898956] Mon, 30 July 2012 02:58 Go to previous message
Alexandra Bardiau is currently offline Alexandra Bardiau
Messages: 21
Registered: March 2012
Junior Member
Hi again,

Here's how to create and open a Class diagram programatically:


	public void createAndOpenInterfaceDiagram() {
		boolean creationDiagram = true;
		IEditorPart editorPart = getActiveEditor();
		ServicesRegistry serviceRegistry = (ServicesRegistry) editorPart
				.getAdapter(ServicesRegistry.class);
		try {
			IPageMngr pageMngr = ServiceUtils.getInstance().getIPageMngr(
					serviceRegistry);
			/*
			 * Detect if the interface diagram is already created
			 */
			for (Object id : pageMngr.allPages()) {
				DiagramImpl page = (DiagramImpl) id;
				if (page.getName().contains("Class Diagram")) {
					/*
					 * Set the focus of the interface diagram
					 */
					if (pageMngr.isOpen(id)) {
						pageMngr.closePage(id);
					}
					pageMngr.openPage(id);
					creationDiagram = false;
				}
			}
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		/*
		 * Creation of the interface diagram
		 */
		if (creationDiagram == true) {
			DiResourceSet diResourceSet = EditorUtils.getDiResourceSet();
			CreateClassDiagramCommand command = new CreateClassDiagramCommand();
			command.createDiagram(diResourceSet, null, "Class Diagram");
		}
	}



When you get stuck, try using the forum's search function, or browsing through the Papyrus source code, it can be quite useful when looking for how to do stuff programatically.

Good luck!

Alexandra
Previous Topic:Deployment Diagrams
Next Topic:Defining constraints in class diagrams
Goto Forum:
  


Current Time: Sat Apr 19 06:01:04 EDT 2014

Powered by FUDForum. Page generated in 0.05915 seconds