How can I add nodes with the CreateElementRequest [message #848723] |
Wed, 18 April 2012 10:14  |
Eclipse User |
|
|
|
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 10:15  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.26350 seconds