Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Prevent nodes from being dragged out of parent bounds (GEF5)
Prevent nodes from being dragged out of parent bounds (GEF5) [message #1770448] Fri, 11 August 2017 13:25 Go to next message
Thomas Oberle is currently offline Thomas OberleFriend
Messages: 11
Registered: April 2017
Junior Member
Hello,

In my GEF5 project I am adding child nodes (Components) to a parent node (System).
I use TransformPolicy to enable drag and drop for my Component nodes.
Unfortunately I am able to drag Component nodes outside of the bounds of my System node (picture attached).

Is there some out-of-the-box functionality to prevent child nodes from beeing dragged outside the bounds of the parent node?

For the momemt I have implemented some code inside the getContentTransform() method of my ComponentPart.
This code changed the component node position if it was draged outside the bounds of the System.
-> I assume this not how it is supposed to be? :/
What is the proper way to solve this?

Furthermore this code will only be executed after the node has been dropped.
Is there any method which is permanently called during drag operation providing the current position data ?

Thanks,
Thomas
  • Attachment: drag.png
    (Size: 3.32KB, Downloaded 182 times)
Re: Prevent nodes from being dragged out of parent bounds (GEF5) [message #1770449 is a reply to message #1770448] Fri, 11 August 2017 14:09 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Thomas,

there are multiple alternatives available for solving this issue:

A) Exchange child node part's TransformPolicy and prevent translation out of its parent's bounds, e.g. ParentRestrictedTransformPolicy. Then, you can bind it for all parts that should be restricted to their parent's bounds. No special code in the child parts is needed.

B) Override child node part's setVisualTransform() method and prevent translation out of its parent's bounds there. The ITransformableContentPart#setVisualTransform() method is called during interaction to apply the translation to the part's visual. The final visual transform (getVisualTransform()) is applied to the model using setContentTransform(). When choosing this alternative, you should probably factor out a RestrictToParentSupport that can simply be called.

Alternative B) is closer to your current status, so you can try it out easily. However, alternative A) allows for easier re-use, although a little more difficult to set-up.

Best regards,
Matthias

[Updated on: Fri, 11 August 2017 14:10]

Report message to a moderator

Re: Prevent nodes from being dragged out of parent bounds (GEF5) [message #1772337 is a reply to message #1770449] Fri, 08 September 2017 08:55 Go to previous message
Thomas Oberle is currently offline Thomas OberleFriend
Messages: 11
Registered: April 2017
Junior Member
Hi Matthias,

thanks a lot, this is exactly what I needed!

Best regards,
Thomas
Previous Topic:Save selected node as png file (GEF5)
Next Topic:[Zest] How to use Drag and Drop (DND) with zest?
Goto Forum:
  


Current Time: Tue Apr 23 16:40:00 GMT 2024

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

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

Back to the top