Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Move connected elements together to hold initial position of creation(When a node is moved, I would like its connected element to move along with it.)
Move connected elements together to hold initial position of creation [message #1714448] Thu, 12 November 2015 17:44 Go to next message
V Set is currently offline V SetFriend
Messages: 20
Registered: November 2012
Junior Member
Hi,

I have 2 rectangles ((R1, R2) with a connection in between. I have 2 requirements:
1. R1 is always created first. When R2 is created and connected, it must adhere to the top left corner of R1.

I could set the connection anchor on R2 to the top left corner but not R1.
2. When either one of the figures is moved the other must also move with it.

I tried editing the 'handleNotificationEvent' of R1. But is there a better way?


Thanks,

v set

Re: Move connected elements together to hold initial position of creation [message #1714789 is a reply to message #1714448] Mon, 16 November 2015 16:50 Go to previous message
V Set is currently offline V SetFriend
Messages: 20
Registered: November 2012
Junior Member
I resolved this using handleNotificationEvent in both R1EditPart and R2EditPart. R1 sets the 'Location' for R2 by getting the target from the sourceEdge. R2 uses the eventType notification.SET to call refreshBounds.

Tips for getting this.
In R1EditPart handleNotificationEvent(Notification event)


if (event.eventType == Notification.SET)
if (event.getNotifier() instanceof Bounds)
//notifier will have the x and y values.
Bounds notifier = (Bounds) event.getNotifier()
//get the target (R2) from the sourceEdges
edges = ((Node)notifier.eContainer().getSourceEdges()
for (Edge edge: edges)
if edge.getType = xxxx
//Get R2 View
View targetView = (View)edge.getTarget()
Node target = (Node)targetView
//create new location using the values from notifier
Location loc = NotationFactory.eInstance.createLocation();
location.setX(notifier.getX()); location.setY(notifier.getY());
target.setLayoutConstraint(location);


In R2EditPart handleNotificationEvent(Notification event)

if (event.eventType == Notification.SET)
//the location is already set in the node. Just refresh
refreshBounds()

Hope this helps somebody



V Set

[Updated on: Mon, 16 November 2015 17:57]

Report message to a moderator

Previous Topic:Create node's children programmatically on drag&drop
Next Topic:Old GMF application confilicting with Papyrus
Goto Forum:
  


Current Time: Mon Oct 23 10:11:06 GMT 2017

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

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