Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Change location on creation
Change location on creation [message #232795] Sat, 06 June 2009 06:43 Go to next message
Giordano is currently offline GiordanoFriend
Messages: 21
Registered: July 2009
Junior Member
Hi, I have to move an object that is automatically create (with feature
seq initializer) when i drag on the diagram oneother node. By default GMF
draw this object in the center of the diagram but I need that this node
stay near its "parent" node (is not really parent because I don't use
child reference, but "parent" has a reference to "child"). I try to look
for a EditPolicy that handles node creation, so, when the "child" node is
created I can move it, but I didn't found an EditPolicy that do this job!
How can I do?
Thanks to everybody!
Re: Change location on creation [message #232841 is a reply to message #232795] Mon, 08 June 2009 06:37 Go to previous messageGo to next message
Javier is currently offline JavierFriend
Messages: 57
Registered: July 2009
Member
Hello,

these are the possible solutions I found when working with similar
problems:

1- Handling the position of the new element in the NewElementViewFactory,
using layout constraint on the View:
Node node = getViewService().createNode(...)
BoundsImpl bi = (BoundsImpl) node.getLayoutConstraint();
bi.setY(5);
bi.setX(250);

2- Modifying the CreationEditPolicy installed in the EditPart in which you
insert that new element. It implements this method:
protected Command getCreateElementAndViewCommand(
CreateViewAndElementRequest request)

3- Listening for the notification of the new addition in the
handleNotificationEvent() method of the parent EditPart

Hope this helps,

Javier.
Re: Change location on creation [message #232942 is a reply to message #232841] Mon, 08 June 2009 13:00 Go to previous messageGo to next message
Giordano is currently offline GiordanoFriend
Messages: 21
Registered: July 2009
Junior Member
Hi, thanks for your response!
I try with
Re: Change location on creation [message #232950 is a reply to message #232942] Mon, 08 June 2009 13:03 Go to previous messageGo to next message
Giordano is currently offline GiordanoFriend
Messages: 21
Registered: July 2009
Junior Member
Giordano wrote:

> Hi, thanks for your response!
> I try with

Hi thanks for your response!
I try with the second option but the method is not called when I create
figure A maybe because B is not a child of A but only a referenced
element.!

How can I do? The other 2 options also does not work for the same reason I
think!
Re: Change location on creation [message #233030 is a reply to message #232950] Tue, 09 June 2009 07:54 Go to previous messageGo to next message
Giordano is currently offline GiordanoFriend
Messages: 21
Registered: July 2009
Junior Member
Can anyone help me?
I need to move a referenced (accessible via "view.getElement().getNode()")
node B when I create another node A.
I try to use creationEditPolicy installed in A but doesn't work, node B
remains in original position. I override createView method in BViewFactory
but nothing..

Any ideas?

Thanks!!
Re: Change location on creation [message #233038 is a reply to message #233030] Tue, 09 June 2009 08:20 Go to previous messageGo to next message
Javier is currently offline JavierFriend
Messages: 57
Registered: July 2009
Member
So that child node isn't actually contained in the parent node, but just a
reference.... so then you have to handle the behavior in the
handleNotificationEvent() method of the container (the real one, maybe
it's the diagram), and there you should search for the parent of the
reference and act accordingly.
Re: Change location on creation [message #233054 is a reply to message #233038] Tue, 09 June 2009 08:47 Go to previous message
Giordano is currently offline GiordanoFriend
Messages: 21
Registered: July 2009
Junior Member
Javier wrote:

> So that child node isn't actually contained in the parent node, but just a
> reference.... so then you have to handle the behavior in the
> handleNotificationEvent() method of the container (the real one, maybe
> it's the diagram), and there you should search for the parent of the
> reference and act accordingly.

Hi Javier, thanks for your help!
I found a way using policies but I have a problem.

I write the code to move B near A. If I install the policy in B as an
OPEN_POLICY (double click on B) it works, if I install as a
DRAG_DROP_POLICY on A (When I create A this policy is called) it doesen't
work. I can access to B but the code doesn't work, B stay in the original
position.

This is the code to move b, i get b editPart looping on diagram's sons
looking for the right b (the one that as a reference to the same a of the
policy)


b = (BEditPart) a.getViewer().getEditPartRegistry().get(child);
Point aPoint = a.getLocation();
Point bPoint = b.getLocation();
//Calculate b new position
bPoint.x = aPoint.x - bPoint.x + (a.getSize().width / 2);
bPoint.y = aPoint.y - bPoint.y + (a.getSize().height / 2);
//Create the command
move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
move_req.setMoveDelta(bPoint);
move_req.setEditParts(b);

cmd = balloon.getCommand(move_req);
return cmd;

This code works in OpenEditPolicy installed in B, but not in DRAG_DROP
policy
Previous Topic:Cut/Copy/Paste of Diagram Files
Next Topic:CompartmentChildCreateCommand & RepositionEObjectCommand
Goto Forum:
  


Current Time: Fri Apr 03 11:56:18 GMT 2020

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

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

Back to the top