Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to create an EReference programmatically?
icon5.gif  How to create an EReference programmatically? [message #1220042] Mon, 09 December 2013 10:07 Go to next message
Xiaoying Hu is currently offline Xiaoying HuFriend
Messages: 2
Registered: June 2013
Location: Aachen Germany
Junior Member
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);
		
if(commandConnection.canExecute()){
    commandConnection.execute();
}


but a NullPointerException for the command is thrown, that means the command is not initiated correctly. I really don't know why Sad .

Could anyone help, how to build the command correctly?


Thanks in advance.


  • Attachment: Student.png
    (Size: 15.04KB, Downloaded 50 times)
Re: How to create an EReference programmatically? [message #1220070 is a reply to message #1220042] Mon, 09 December 2013 13:13 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 146
Registered: July 2009
Senior Member
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);
Re: How to create an EReference programmatically? [message #1220093 is a reply to message #1220070] Mon, 09 December 2013 16:04 Go to previous message
Xiaoying Hu is currently offline Xiaoying HuFriend
Messages: 2
Registered: June 2013
Location: Aachen Germany
Junior Member
Hi Pierre-Charles,

thanks for your quick reply.

Quote:
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);


There is a problem here, the execute method is not applicable for a GEF command (org.eclipse.gef.commands.Command), it works only for EMF command(org.eclipse.emf.common.command.Command).

To run the GEF command is the second step, the first step is to get the GEF command, in my case using the code:

Command commandConnection = sourceEditPart.getCommand(createConnectionReques);


This doesn't work. So the question is, how can I get the correct command to run the request?

Any idea will be appreciated. Smile
Previous Topic:Connection creation throws exception
Next Topic:How to create a new project programatically?
Goto Forum:
  


Current Time: Mon Dec 22 04:21:17 GMT 2014

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

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