Prevent moving a figure outside parent's borders [message #539061] |
Wed, 09 June 2010 14:19 |
emil salageanu Messages: 94 Registered: June 2010 Location: Nice, France |
Member |
|
|
Hello,
I'm new to GMF.
I'mplementing a workflow editor. I noticed that, for some figures, when trying to move a child outside the parent borders it resizes the parent which seems correct.
For other cases, it just moves the child at a position which is no longer visible as its outside the parent client area (for example this happens, for some figures, in the Taipan example as well as the BPMN implementation ).
In order to prevent moving a child figure outside the parent, I added an edit policy to the EditPart of the child (installed for the key EditPolicy.PRIMARY_DRAG_ROLE).
My edit policy extends ResizableEditPolicyEx and implements the method getMoveCommand like this:
protected Command getMoveCommand(ChangeBoundsRequest request) {
Point moveDelta = request.getMoveDelta();
Rectangle myRect = getHostFigure().getClientArea();
myRect.translate(moveDelta);
Rectangle parentRectangle = ((GraphicalEditPart)this.getHost().getParent()).getFigure().getClientArea();
//cannot move outside parent left and up side
if (myRect.x<0 || myRect.y<0)
return null;
//cannot move outside parent bottom side
if (myRect.y+myRect.height>parentRectangle.height)
return null;
//cannot move outside parent right side
if (myRect.x+myRect.width>parentRectangle.width)
return null;
return super.getMoveCommand(request);
}
Well, just wanted to share this, anny comments wellcomed.
Emil.
|
|
|
|
|
|
Re: Prevent moving a figure outside parent's borders [message #556584 is a reply to message #556400] |
Wed, 01 September 2010 21:59 |
Fernando Herrera Messages: 49 Registered: January 2010 |
Member |
|
|
Thanks Emil. I fix the issue. i have replaced the following line installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ControlFlowSegmentCustomEditPolicy()); for it: installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new ControlFlowSegmentCustomEditPolicy()); and now the changeboundsrequest is firing. I need drag and drog support in this editpolicy. Is correct for me extends from ResizableEditPolicyEx or from the DragDropEditPolicy class?. Thanks for your time!
[Updated on: Wed, 01 September 2010 22:00] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03742 seconds