Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Creating Diagram and model file programmatically(Creating Diagram and model file programmatically)
Creating Diagram and model file programmatically [message #809903] Wed, 29 February 2012 12:25 Go to next message
ganesh ram is currently offline ganesh ramFriend
Messages: 26
Registered: January 2012
Junior Member
Hi,

Am trying to create the Diagram and model file programmatically.

I used the code similar to what is there in XXDiagramEditorUtil.createDiagram().

In the normal case (when i have an empty domain ie nothing is set into the domain object), the diagram and the domain file gets created and works fine.

Assume my model is of type XX, and that has a list of YY.
i create YY and set it inside XX.
Now when i create the domain file, the <YY> is set correctly inside <XX>.
But in the diagram file, i dont see the <children/> tags corresponding to the YY.

How would the appropriate <children/> tags be generated ?

i tried diagram.createChild(yy.eClass()), but the diagram file does not get generated.

Pls help.


AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain,
				Messages.XXXDiagramEditorUtil_CreateDiagramCommandLabel,
				Collections.EMPTY_LIST) {
				protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)	throws ExecutionException {
				
				XXX model = createInitialModel();
				YYY yyy = XXXFactory.eINSTANCE.createYYY();
				
				yyy.setAttribute1("2");
				yyy.setAttribute2("name");
				
				model.getYYYs().add(yyy);
				
				attachModelToResource(model, modelResource);

				Diagram diagram = ViewService.createDiagram(model, XXXEditPart.MODEL_ID,XXXEditorPlugin.DIAGRAM_PREFERENCES_HINT);
				if (diagram != null) {
					
					diagramResource.getContents().add(diagram);
					diagram.setName(diagramName);
					diagram.setElement(model);
					
					//diagram.createChild(yyy.eClass());
					//diagram.insertChild(arg0);
					
					
				}

				try {
					modelResource.save(.getSaveOptions());
					diagramResource.save(getSaveOptions());
				} catch (IOException e) {
				}
				return CommandResult.newOKCommandResult();
			}
		};

[Updated on: Wed, 29 February 2012 12:26]

Report message to a moderator

Re: Creating Diagram and model file programmatically [message #809914 is a reply to message #809903] Wed, 29 February 2012 12:37 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi ganesh,

you have two options to get it working.

The first one is using a CanonicalEditPolicy, which creates all Nodes and Edges for you based on your semantic model. This is easy to implement, but it has some drawbacks. Your editor will get dirty after opening it, because your Notation Model is changes and no layout information is available.

The better way is to create Nodes and Edges for each semantic element you created.

For your code snippet it might look like this:
XXX model = createInitialModel();
YYY yyy = XXXFactory.eINSTANCE.createYYY();	
yyy.setAttribute1("2");
yyy.setAttribute2("name");
model.getYYYs().add(yyy);
attachModelToResource(model, modelResource);
Diagram diagram = ViewService.createDiagram(model, XXXEditPart.MODEL_ID,XXXEditorPlugin.DIAGRAM_PREFERENCES_HINT);


Node yyyView = ViewService.createNode(diagram, yyy, SemanticHints.YYY,
   ,XXXEditorPlugin.DIAGRAM_PREFERENCES_HINT);
//Set some layout information assuming you use a XYLayout	
Bounds bounds = NotationFactory.eINSTANCE.createBounds();
bounds.setX(70);
bounds.setY(20);
yyyView.setLayoutConstraint(bounds);
...


Regards,
Andreas
Re: Creating Diagram and model file programmatically [message #810501 is a reply to message #809914] Thu, 01 March 2012 07:00 Go to previous messageGo to next message
ganesh ram is currently offline ganesh ramFriend
Messages: 26
Registered: January 2012
Junior Member
Hi Andreas,

The second way worked perfectly, thanks Smile
Re: Creating Diagram and model file programmatically [message #1698353 is a reply to message #810501] Sun, 14 June 2015 20:41 Go to previous messageGo to next message
wang wang is currently offline wang wangFriend
Messages: 1
Registered: June 2015
Junior Member
Dear,ganesh,
I see you rely in the forum, http://www.eclipse.org/forums/index.php/t/300804/,
I am now try to use ViewService.createDiagram create the GMF diagram, But I didnt create sucessefully, can you send me your code to me for a reference, Thank you so so much.

Denzel, Wang
Re: Creating Diagram and model file programmatically [message #1703697 is a reply to message #1698353] Tue, 04 August 2015 10:16 Go to previous message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 633
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

you can take a look to this example https://github.com/bonitasoft/bonita-studio/blob/bos-studio-7.0.1-201507021345/bundles/plugins/org.bonitasoft.studio.diagram.custom/src/org/bonitasoft/studio/diagram/custom/repository/NewDiagramFactory.java

Regards,


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Previous Topic:How Can I add a new tab in property section of GMF editor with table or grid layout
Next Topic:Application error java.lang.RuntimeException: Application "org.eclipse.ui.ide.workbench" c
Goto Forum:
  


Current Time: Tue Jun 27 15:52:24 GMT 2017

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

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