Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Update diagram when drag and drop(Update model and diagram when drag and dropping an existing element)
Update diagram when drag and drop [message #1746982] Tue, 08 November 2016 10:53 Go to next message
Proutprout Canard is currently offline Proutprout CanardFriend
Messages: 3
Registered: November 2016
Junior Member

I am completely new to Graphiti and I have to add a feature to an existing project.
Assuming I have three elements A -> B -> C in my diagram. I would like to be able to drag the element C, drop it in between A & B and update their connections in the same time in order to have A -> C -> B

A ---> B ---> C would become A ---> C ---> B

I found an existing question in the forum, but the provided code doesn't work completely in my case. When I drag an existing element onto another connection, the connection turns orange and nothing happens on drop. I modified the code with my knowledge and understanding of Graphiti, but I haven't reached any better result (see attached image).

Here is the code:

public class MoveShapeFeature extends DefaultMoveShapeFeature {
	public MoveShapeFeature(IFeatureProvider fp) {
	public void internalMove(IMoveShapeContext context) {

		Connection targetConnection = context.getTargetConnection();
		if (targetConnection != null) {
			if (context.getSourceContainer().equals(context.getTargetContainer())) {

				Shape shape = context.getShape();
				GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();

				Graphiti.getGaService().setLocation(ga, context.getX() - (ga.getWidth() / 2), context.getY() - (ga.getHeight() / 2));

				Collection<Anchor> anchors = shape.getAnchors();
				if (anchors.size() > 0) {
					Anchor newAnchor = anchors.iterator().next();

					Anchor oldEndAnchor = targetConnection.getEnd();

					Connection connection = Graphiti.getPeCreateService().createFreeFormConnection(getDiagram());
					Polyline p = Graphiti.getGaCreateService().createPolyline(connection);

					GraphicsAlgorithm targetConnectionGraphicsAlgorithm = targetConnection.getGraphicsAlgorithm();


Am I missing an already existing feature or something in my code?
Thank you in advance.

Best regards,
  • Attachment: 1.jpg
    (Size: 6.69MB, Downloaded 212 times)
Re: Update diagram when drag and drop [message #1747020 is a reply to message #1746982] Tue, 08 November 2016 15:25 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member

the coding you have appenrently copied from our Sktech example (the link I provided in the other forum posting) is intended as a small example what needs to be done for achieving such a split-connection functionality. It works in the very simple setup of our Sketch test tool and uses some assumptions that are true in this tool but apparently not in yours.

Also the examlpe code will not care about removing the moved shape from the original location and will not merge the 2 open connections of the original location. You might try if it works with a shape that is placed within the same flow (parent shape has to stay the same, that is another of the assumptions) but has no connections attached so far. In not sure but that may work at least partly.

One more thing that will be missing are the decorators on the new connection. You will need to create them as well.

Basically you would need to do these steps:
1) Check any precoditions in your diagram
2) Remove the shape from the original location, e.g. detach the connections and unify the 2 dangling connections into 1 (not sure how you would deal with different properties of the connection)
3) Take the new connection (drop target, the one onto you drop the shape) and split it, e.g. take the connection and attach it to a suitable anchor in your shape (Input), then create a new connection (best reusing your create connection feature) to create a second connection from the dragged shape to the target of the original connection. Not sure if all properties of the connection should be the same as the original connection your dropped the shape onto.

I'm afraid, this is a rather tricky task to start with on Graphiti. The concrete coding will pretty much depend on the structure and additional tool related boundary conditions. The best advice I can give here is to split this into the above steps and try to reuse as much existing functionality (e.g. create feature, attach connection functionality) as possible.

Re: Update diagram when drag and drop [message #1747397 is a reply to message #1747020] Mon, 14 November 2016 10:06 Go to previous message
Proutprout Canard is currently offline Proutprout CanardFriend
Messages: 3
Registered: November 2016
Junior Member
**EDIT : What a great community. Thanks for ignoring**


Thanks for the roadmap, I see now more clearly how I am supposed to achieve it.

However, is there a way to get the connections of a shape ?

E.g. if I have
Shape currentShape = context.getShape();

Is there a way to get this pseudo-code:


Thanks in advance.

[Updated on: Wed, 23 November 2016 12:43]

Report message to a moderator

Previous Topic:Dropping Shape onto Connection
Next Topic:Vertical alignment
Goto Forum:

Current Time: Sun Mar 03 10:36:25 GMT 2024

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

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

Back to the top