Question

In GEF connections are in the Z-order default on top of the shapes.

What is the correct way to:
1. Show a shape in the Z-order on top of a connection?
2. Set the Z-order of the connections relative to each other?

Was it helpful?

Solution

Of course you can, let me explain how to achieve both of your goals:

GEF/Draw2d uses distinct layers for shapes/connections, they are identified respectively by LayerConstants.PRIMARY_LAYER and LayerConstants.CONNECTION_LAYER constants. You can change the Z-order between shapes and connections by changing the order their layers are added to the LayeredPane in your RootEditPart.

As an example, override ScalableRootEditPart.createPrintableLayers() the following way to invert layer drawing:

protected LayeredPane createPrintableLayers() {
    LayeredPane pane = new LayeredPane();

    Layer layer = new ConnectionLayer();
    layer.setPreferredSize(new Dimension(5, 5));
    pane.add(layer, CONNECTION_LAYER);

    layer = new Layer();
    layer.setLayoutManager(new StackLayout());
    pane.add(layer, PRIMARY_LAYER);

    return pane;
}

To achieve your second goal, you have to modify the connections paint algorithm by overriding the ConnectionLayer.paintChidren() because all the connection figures are child figure of the ConnectionLayer (note that the default implementation inherits from Figure.paintChidren()).

I suggest you to add an integer Z-order property to the connection figures (those created by your connection parts) to be used by the algorithm to actually paint them in the correct order. Then implement in your connection parts the relative ordering strategy, which will have the responsibility to update the Z-order property in their respective figures.

OTHER TIPS

I don't think you can do this. From what I know, the shapes and the connections are in different layers, with the shapes layer below the connection layer. You probably won't be able to change the Z-order of the connections either, because it is all managed by the framework

When using frameworks like GEF, you trade automatic functionality for freedom :-).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top