|
Re: How to create an EReference programmatically? [message #1220070 is a reply to message #1220042] |
Mon, 09 December 2013 13:13 |
|
Le 09/12/2013 13:58, Xiaoying Hu a écrit :
> Hi all,
>
>
> I am trying to programmatically create a connection(an EReference) between two EClass on a GMF-based Editor. (cf. picture - an ERefference bewteen the Student and the Lecture)
>
> I tried using CreateConnectionRequest, codes are as followed:
>
>
> CreateConnectionRequest createConnectionReques = new CreateConnectionRequest();
>
> createConnectionReques.setSourceEditPart(sourceEditPart);
>
> createConnectionReques.setTargetEditPart(targetEditPart);
>
> Command commandConnection = sourceEditPart.getCommand(createConnectionReques);
>
You don't execute the commands yourself, but must pass through the
command stack (which is responsible for undo/redo behavior):
TransactionalEditingDomain ted = sourceEditPart.getEditingDomain();
ted.getCommandStack().execute(commandConnection);
Pierre-Charles David - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Re: How to create an EReference programmatically? [message #1692795 is a reply to message #1220093] |
Sat, 18 April 2015 21:00 |
|
Hello there,
I encountered the same issue.
I came up with the following method which seems to solve the problem.
public void createAndExecuteConnectionRequestCommand(IElementType type, DiagramEditPart editPart, EditPart source, EditPart target) {
CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(type, ((IHintedType) type).getSemanticHint(), editPart.getDiagramPreferencesHint());
Command cmd = CreateConnectionViewAndElementRequest.getCreateCommand(request,
source, target);
System.out.println(cmd.getLabel());
diagramEditPart.getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
//hack to refresh visuals and show the connection!
diagramEditPart.addNotify();
}
Best, Nikos.
|
|
|
Powered by
FUDForum. Page generated in 0.03865 seconds