[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.gef] Re: Connecting connections in the Shape example

Thanks for pointing out the problem with the coordinates, Steve!

Meanwhile, I finally found and solved the problem.

It seems that ConnectionAnchors for Connections must not extend AbstractConnectionAnchor but ConnectionAnchorBase. AbstractConnectionAnchor adds the Anchor as an AncestorListener to its owner. This causes an infinite loop of revalidation because PolylineConnection listens to the anchor and the anchor listens to the PolylineConnection. Somehow PolylineConnection says it has moved which in turn causes the anchor to say it has moved which in turn causes PolylineConnection to say it has moved, and so on:

PolylineConnection.revalidate() -> ... -> AbstractConnectionAnchor.ancestorMoved(PolylineConnection) -> PolylineConnection.anchorMoved(AbstractConnectionAnchor) -> PolylineConnection.revalidate()

The attached archive contains the Shapes example extended by the possibility to connect connections to each other. Especially, it contains a PolylineConnectionAnchor which returns the midpoint of the connection as the anchor location. The modifications are documented in the code.

I'll try to create a Howto for connecting connection in the Wiki when I have some free time.

Best regards
Adrian

Steven Shaw wrote:
One thing I noticed is that you're not returning the point in absolute
coordinates.  The points in the polyline connection are in relative
coordinates.  Anchors always operate in absolute coordinates.  You need to
make a call to:

getOwner().translateToAbsolute(midpoint);
return midpoint;

-Steve

"Adrian Gygax" <adrian.gygax@xxxxxxx> wrote in message
news:du49el$6cg$1@xxxxxxxxxxxxxxxxxxxx
Hi!

I'm trying to extend the Shape example so there can be Connections
connecting Connections. This is what I did so far:

- Pulled up Connection handling stuff from Shape to a new Class
"ConnectableElements". Both, Shape and Connection extend this class
- Adapted ConnectionCreateCommand to take ConnectableElements instead of
only Shapes
- In ConnectionEditPart I'm installing a GraphicalNodeEditPolicy under
the EditPolicy.GRAPHICAL_NODE_ROLE which I copied from ShapeEditPart
- I wrote a custom ConnectionAnchor which returns the midpoint of a
PolylineConnection as Location

Now I have a similar problem like Brian Fernandez in the "Connecting
connections to connections ..." thread: As soon as I try to connect a
Connection the tool ends up in an endless loop calling getLocation()
from my CustomConnectionAnchor. If I use an XYAnchor instead, the
endless loop vanishes (But the resulting connection's display is useless
because start/end points are always at the same place, of course).
Unfortunately, I don't understand what he did to solve the problem. Can
anybody help me? I attached my extended Shapes example for reference.

Best regards,
Adrian




Attachment: ConnectingConnectionsShapesExampleWorking.zip
Description: Zip compressed data