Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 15:20 Go to next message
Peacemoon  is currently offline Peacemoon Friend
Messages: 14
Registered: November 2010
Junior Member
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 07:13 Go to previous messageGo to next message
Asiri Rathnayake is currently offline Asiri RathnayakeFriend
Messages: 80
Registered: September 2010
Location: Colombo, Sri Lanka.
Member
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 12:09 Go to previous message
Peacemoon  is currently offline Peacemoon Friend
Messages: 14
Registered: November 2010
Junior Member
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 Mar 28 22:17:43 GMT 2024

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

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

Back to the top