Skip to main content



      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 09:25 Go to next message
Eclipse UserFriend
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 216 times)
Re: Prevent nodes from being dragged out of parent bounds (GEF5) [message #1770449 is a reply to message #1770448] Fri, 11 August 2017 10:09 Go to previous messageGo to next message
Eclipse UserFriend
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 10:10] by Moderator

Re: Prevent nodes from being dragged out of parent bounds (GEF5) [message #1772337 is a reply to message #1770449] Fri, 08 September 2017 04:55 Go to previous message
Eclipse UserFriend
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: Fri Apr 25 03:00:17 EDT 2025

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

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

Back to the top