Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How can I add nodes with the CreateElementRequest(I want to add nodes to the actual shown diagram)
How can I add nodes with the CreateElementRequest [message #848723] Wed, 18 April 2012 14:14 Go to next message
Marco Franke is currently offline Marco FrankeFriend
Messages: 10
Registered: April 2012
Location: Bremen
Junior Member
Hello,

I have some EObjects and want to add them to the actual shown diagram ((DiagramEditor)k).getDiagramGraphicalViewer()). Unfortunately, I don't know how I can extend them to a Editpart and finally add them to the active diagramm.

I have already tried this one:

Action m = CTEFactoryImpl.eINSTANCE.createAction();
             		m.setName("kkkk");
             		CreateElementRequest kommschon = new CreateElementRequest(k.getEditingDomain(),m,ActivityElementTypes.Action_2001);
             		
             		CreateElementCommand createElementCommand = new CreateElementCommand(kommschon);

             		k.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(createElementCommand));


If I run this source code, I get now execption but nothing happens. I don't see any added figures to the diagramm
Can somebody tell me, what I have forgotten.

Best Regards,

Marco
Re: How can I add nodes with the CreateElementRequest [message #853967 is a reply to message #848723] Mon, 23 April 2012 14:15 Go to previous message
Michael Golubev is currently offline Michael GolubevFriend
Messages: 383
Registered: July 2009
Senior Member
Hello,

You should not create the CreateElementCommand directly, its just a helper for editpolicies that handles creation.
The good news is that the code that manipulates with CreateElementCommands is already in place, so you need only to find a way to delegate to policies.

If you want to follow what is done from the creation tools the code will look like:

List types = Collections.singletonList(ActivityElementTypes.Action_2001);
CreateUnspecifiedTypeRequest gefRequest = new CreateUnspecifiedTypeRequest(types, PreferencesHint.USE_DEFAULTS);
gefRequest.setLocation(...);
gefRequest.setSize(...);
EditPart containerEP = .... //find EP that should host the new element, DiagramEditPart for top-level elements.
Command gefCommand = containerEP.getCommand(gefRequest);
if (gefCommand.canExecute()) {
   //execute 
}


Hope that helps,
Regards,
Michael "Borlander" Golubev
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zürich, Switzerland
Previous Topic:GMF deploying problems --Please help--
Next Topic:Highlight the lines/connections
Goto Forum:
  


Current Time: Sun May 05 14:03:14 GMT 2024

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

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

Back to the top