Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Is it possible to create a connection before its source and target elements are created?
Is it possible to create a connection before its source and target elements are created? [message #94863] Mon, 22 January 2007 04:14 Go to next message
Eclipse UserFriend
Originally posted by: xiaoxiaoleemin.gmail.com

hi,everyone
Now I have such an application like this(please see the attachement):
the biggest rectangle on the canvas is a NClass ;
the rectangle in the compartment of NClass is a NLifeNode;
the connection from one NLifeNode to another one is a NMessage.
In the model, I define the source and target of the connection(NMessage)
are NLifeNodes, so only when the mouse is over the NLifeNode, the creation
of a NMessage is enabled.

And now I wonder if such function can be possible: When I move the mouse
on the compartment of NClass(Now no NLifeNode is created), the creation of a
connection(NMessage) is enabled, and when I drag the mouse from point A in
one compartment to point B in another compartment, a connection is creation
from A to B, and at the same time, two NLifeNodes at point A and point B
are created too.

If it is possible, what should I do to achieve it? Should I install any
edit policy or modify any code?

Best wishes:)


  • Attachment: a.JPG
    (Size: 17.89KB, Downloaded 90 times)
Re: Is it possible to create a connection before its source and target elements are created? [message #95129 is a reply to message #94863] Mon, 22 January 2007 14:08 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Min,

I think you should modify generated SemanticItemEditPolicy of NClass to allow
incoming NMessage and return command creating first NLifeNode and then NMessage.
You can take a look on the generated SemanticItemEditPolicy for NLifeNode
to gather an information on required command structure.

-----------------
Alex Shatalin
Re: Is it possible to create a connection before its source and target elements are created? [message #96022 is a reply to message #95129] Wed, 24 January 2007 12:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: xiaoxiaoleemin.gmail.com

hi, Alex:
thank you for the tips.
I have tried to modify the NClassItemSemanticEditPolicy class according
to the NLifeNodeItemSemanticEditPolicy class, and now I have made some
progress, but have not solve the problem totally.
The modification I made is as follows:
(1)by adding the getCreateRelationshipCommand, creation of a NMessage
connection is enable when the mouse moves on the NClass.
protected Command getCreateRelationshipCommand(CreateRelationshipRequest
req) {
if (SequenceElementTypes.NMessage_4001 == req.getElementType()) {


return req.getTarget() == null ?
getCreateStartOutgoingNMessage4001Command(req)
: getCreateCompleteIncomingNMessage4001Command(req);
}

return super.getCreateRelationshipCommand(req);
}
(2) add the method getCreateStartOutgoingNMessage4001Command(), and
getCreateCompleteIncomingNMessage4001Command(), the former one is the same
as that of the NLifeNodeItemSemanticEditPolicy, just return a new Command,
and in the later one, I made such modifications
protected Command getCreateCompleteIncomingNMessage4001Command(
CreateRelationshipRequest req) {

//here, both getSource() and getTarget() return a NClass object, so I delete
the checking code.
//if (!(req.getSource() instanceof NLifeNode)) {
// return UnexecutableCommand.INSTANCE;
// }

//here, I create two NLifeNode object, and set the source and target of the
request to these newly
//created NLifeNode respectively
EObject srcContainer = null;
EObject destContainer = null;
if(!req.getSource().equals(req.getTarget())) //get the real source and
target of the request
{

final NPackage element = (NPackage) getRelationshipContainer(req
.getSource(), NPackagePackage.eINSTANCE.getNPackage(), req
.getElementType());
if (element == null) {
return UnexecutableCommand.INSTANCE;
}

srcContainer = req.getSource();//now the source of the request is a
NClass, and I should create a NLifeNode in it.
destContainer = req.getTarget();

NLifeNode firstLifeNode = NPackageFactory.eINSTANCE.createNLifeNode();
NLifeNode secondLifeNode = NPackageFactory.eINSTANCE.createNLifeNode();

TransactionalEditingDomain domain =
TransactionUntil.getEditingDomain(getHost().getModel());
CreateChildCommand firstCommand = new CreateChildCommand(domain,
srcContainer, NPackagePackage.eINSTANCE.getNClass_TimeNodes(),
firstLifeNode, null);
CreateChildCommand secondCommand = new CreateChildCommand(domain,
destContainer, NPackagePackage.eINSTANCE.getNClass_TimeNodes(),
secondLifeNode, null);

firstCommand.execute();
secondCommand.execute();

req.setSource(firstLifeNode);
req.setTarget(secondLifeNode);

if (req.getContainmentFeature() == null) {
req.setContainmentFeature(NPackagePackage.eINSTANCE
.getNPackage_Messages());
}
return getMSLWrapper(new CreateIncomingNMessage4001Command(req) {

protected EObject getElementToEdit() {
return element;
}
});
}
else return null;
}

(4) Just the same as NLifeNodeItemSemanticEditPolicy, an inner class
CreateIncomingNMessage4001Command is created here.

I think the key point is before creating the
CreateIncomingNMessage4001Command, the parameter passed to it (Req) should
be set correctly. The previous source and target object of the request is
NClass( I made it by adding the getCreateRelationshipCommand), now it should
be set to two newly created NLifeNode in the previous source and target
NClass respectively. I do this job using the CreateChildCommand,.
Now if I create a NMessage between two NClass, when I push the "save"
button, an error saying "the newly created NLifeNode can't be saved because
it is not in a resource set" occurred. When debugging, I found these two
commands are not executed correctly, so the NLifeNodes are not created
correctly. I don't know whether the EMF command can be executed here.
I also try the GMF command CreateElementCommand instead of
CreateChildCommand , but I find it impossible to execute a
TransactionalCommand immediately(because only after execution of the
command, can the NLifeNode be really created, then I call the setSource()
and setTarget() of the req). When I call the execute() method of
CreateElementCommand directly, an error "Cannot activate read/write
transaction in read-only transaction context" happened, So I put the
execution code of these two CreateElementCommand in a TransactionalCommand,
then when should these TransactionalCommand execute?...



"Alex Shatalin" <vano@borland.com> д
Re: Is it possible to create a connection before its source and target elements are created? [message #96078 is a reply to message #96022] Wed, 24 January 2007 16:04 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello min,

I suggest you to move code creating MLifeNodes into CreateIncomingNMessage4001Command.doDefaultElementCreation()
method. In this method you can simply call EMF API and forget about TransactionalEditingDomain
+ commands - all this job should be done automatically for you.

So, I suggest you to reimplement doDefaultElementCreation() like this:

NLifeNode firstLifeNode = NPackageFactory.eINSTANCE.createNLifeNode();
NLifeNode secondLifeNode = NPackageFactory.eINSTANCE.createNLifeNode();
getSource().getNLifeNodes.add(firstNode);
getTarget().getNLifeNodes.add(secondNode);

NMessage message = NPackageFactory.eINSTANCE.createNMessage();
firstLifeNode.getNMessages().add(message);
message.setTarget(secondLifeNode);

In addition you can create first/secondLifeNodes conditionally here i.e.
use existing NLifeNodes as source/target of the links if corresponding nodes
was already created.

-----------------
Alex Shatalin
Previous Topic:multiple views of a model
Next Topic:How to call up the Add/Remove dialog linking for a node
Goto Forum:
  


Current Time: Wed Jul 17 09:42:29 GMT 2024

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

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

Back to the top