Skip to main content



      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 07:25 Go to next message
Eclipse UserFriend
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 07:26] by Moderator

Re: Creating Diagram and model file programmatically [message #809914 is a reply to message #809903] Wed, 29 February 2012 07:37 Go to previous messageGo to next message
Eclipse UserFriend
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 02:00 Go to previous messageGo to next message
Eclipse UserFriend
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 16:41 Go to previous messageGo to next message
Eclipse UserFriend
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 06:16 Go to previous message
Eclipse UserFriend
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,
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: Sun May 11 05:21:06 EDT 2025

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

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

Back to the top