Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Create a node programmatically when open new document
Create a node programmatically when open new document [message #638534] Thu, 11 November 2010 10:20 Go to next message
Eclipse UserFriend
Hello,

i want to create a default node when a new diagram is opened. But i don't know where i should write the code into?
Re: Create a node programmatically when open new document [message #639057 is a reply to message #638534] Mon, 15 November 2010 02:13 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

In your model factory implementation class, there should be a method like createPackageNameDiagramModelObject() like method. Here PackageName should be your model package name and DiagramModelObject would be the model object you selected as the diagram element. In this create method you need to create the model object corresponding to the node you want to be created and add it to the diagram model object (into the corresponding containment feature). This will automatically initialize your diagram with a node corresponding to the object you added to the diagram element.

Hope this helps.

- Asiri
Re: Create a node programmatically when open new document [message #639136 is a reply to message #638534] Mon, 15 November 2010 07:09 Go to previous message
Eclipse UserFriend
Thanks for the answer.
But i could have solved already it.
I post my solution hereIt could be useful for someone else
Just extend the performFinish method in XXXCreationWizard class with the code, which add both view and element to the model.
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IEditorPart ep = page.getActiveEditor();
		DiagramEditPart diagramEditPart = ((DiagramEditor)ep).getDiagramEditPart();
		
		TopEvent topEvent = FtaFactory.eINSTANCE.createTopEvent(); 
		topEvent.setName("Top Event");
		CreateViewAndElementRequest.ViewAndElementDescriptor veDescriptor = new CreateViewAndElementRequest.ViewAndElementDescriptor(
																						new CreateElementRequestAdapter(new CreateElementRequest(FtaElementTypes.getElementType(TopEventEditPart.VISUAL_ID))), 
																						Node.class, 
																						((IHintedType) FtaElementTypes.getElementType(TopEventEditPart.VISUAL_ID)).getSemanticHint(), 
																						diagramEditPart.getDiagramPreferencesHint()
																				);
		CreateViewAndElementRequest veRequest = new CreateViewAndElementRequest(veDescriptor);
		Command veCommand = diagramEditPart.getCommand(veRequest);
		veCommand.execute();
Previous Topic:Prevent adding new Node
Next Topic:GMF navigator: include resourceContent as navigatorContent
Goto Forum:
  


Current Time: Thu Jul 03 21:11:57 EDT 2025

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

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

Back to the top