Java Reference
In-Depth Information
Connection EditParts
Although connection EditPart s are largely the same as other EditPart s, they
are created and managed in a shared manner by their source and target
EditPart s. EditPart s representing nodes on a diagram must override the
getModelSourceConnections() and getModelTargetConnections()
methods provided by the AbstractGraphicalEditPart class to return the
model object representing the connection. If the corresponding EditPart for a
connection model object has not been created by the node at the other end, GEF
requests its creation from the EditPartFactory . The source node is responsi-
ble for creating the connection figure and adding it to the diagram.
The Figure created by a connection EditPart must implement org.
eclipse.draw2d.Connection and typically is an instance of org.eclipse.
draw2d.PolylineConnection . In fact, the default implementation pro-
vided by AbstractConnectionEditPart.getFigure() returns a new
PolylineConnection . The connection EditPart maintains a reference to the
source and target EditPart s and sets its Figure 's anchors by casting these
references to NodeEditPart . Following is the implementation that
AbstractConnectionEditPart provided for getSourceConnection
Anchor() ; here, DEFAULT_SOURCE_ANCHOR is an XYAnchor at point ( 10, 10 ).
The getTargetConnectionAnchor() method is implemented similarly, set-
ting its default XYAnchor at ( 100, 100 ).
protected ConnectionAnchor getSourceConnectionAnchor() {
if (getSource() != null ) {
if (getSource() instanceof NodeEditPart) {
NodeEditPart editPart = (NodeEditPart) getSource();
return editPart.getSourceConnectionAnchor( this );
} IFigure f = ((GraphicalEditPart)getSource()).getFigure();
return new ChopboxAnchor(f);
}
return DEFAULT_SOURCE_ANCHOR;
}
To provide sensible anchor positions for your connections to use, it's important
first to implement NodeEditPart for those nodes that support connections, and
second to provide implementations for getSourceConnectionAnchor() and
getTargetConnectionAnchor() to return appropriate ConnectionAnchors .
Following is the implementation of ge tSourceConnectionAnchor() for the
LogicEditPart in the logic diagram example. Again, getTargetConnection
Anchor() is implemented similarly.
Search WWH ::




Custom Search