Update diagram when drag and drop [message #1746982] |
Tue, 08 November 2016 10:53 |
Proutprout Canard Messages: 3 Registered: November 2016 |
Junior Member |
|
|
Hello,
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) {
super(fp);
}
@Override
public void internalMove(IMoveShapeContext context) {
super.internalMove(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();
System.out.println(newAnchor);
targetConnection.setEnd(newAnchor);
Connection connection = Graphiti.getPeCreateService().createFreeFormConnection(getDiagram());
Polyline p = Graphiti.getGaCreateService().createPolyline(connection);
GraphicsAlgorithm targetConnectionGraphicsAlgorithm = targetConnection.getGraphicsAlgorithm();
p.setLineWidth(targetConnectionGraphicsAlgorithm.getLineWidth());
p.setForeground(targetConnectionGraphicsAlgorithm.getForeground());
p.setLineStyle(targetConnectionGraphicsAlgorithm.getLineStyle());
connection.setStart(newAnchor);
connection.setEnd(oldEndAnchor);
}
}
}
}
}
Am I missing an already existing feature or something in my code?
Thank you in advance.
Best regards,
Philippe
-
Attachment: 1.jpg
(Size: 6.69MB, Downloaded 237 times)
|
|
|
Re: Update diagram when drag and drop [message #1747020 is a reply to message #1746982] |
Tue, 08 November 2016 15:25 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
Philippe,
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.
HTH,
Michael
|
|
|
Re: Update diagram when drag and drop [message #1747397 is a reply to message #1747020] |
Mon, 14 November 2016 10:06 |
Proutprout Canard Messages: 3 Registered: November 2016 |
Junior Member |
|
|
**EDIT : What a great community. Thanks for ignoring**
Michael,
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:
currentShape.getConnection.getStart()
Thanks in advance.
[Updated on: Wed, 23 November 2016 12:43] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03883 seconds