Skip to main content


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 21:44 Go to next message
Michael Gärtner is currently offline Michael GärtnerFriend
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 14:45 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
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


Camille Letavernier
Re: How to create a papayrus model programatically [message #894855 is a reply to message #893815] Tue, 10 July 2012 19:20 Go to previous messageGo to next message
Michael Gärtner is currently offline Michael GärtnerFriend
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 12:42 Go to previous messageGo to next message
Alexandra Bardiau is currently offline Alexandra BardiauFriend
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 10:26 Go to previous messageGo to next message
Michael Gärtner is currently offline Michael GärtnerFriend
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 06:58 Go to previous messageGo to next message
Alexandra Bardiau is currently offline Alexandra BardiauFriend
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
Re: How to create a papayrus model programatically [message #1404126 is a reply to message #899005] Tue, 29 July 2014 18:58 Go to previous message
Alexandre Giron is currently offline Alexandre GironFriend
Messages: 8
Registered: January 2014
Junior Member
Hi,

using this code I get the error

CreateClassDiagramCommand cannot be resolved to a type

and

DiagramImpl cannot be resolved to a type

I don't know where to find those imports. Can you post the complete code?

Thanks
Previous Topic:"Show/Hide Compartments" grayed out
Next Topic:Activity diagrams & Class operations definition
Goto Forum:
  


Current Time: Thu Apr 18 18:43:20 GMT 2024

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

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

Back to the top