1

I am working through the examples in 'The Eclipse Graphical Framework (GEF)' book and the included Genealogy example(Draw2d chapters) seems to have the z order of figures messed up. When a figure is dragged or selected its z order remains unchanged which causes strange/unnatural behavior where the dragged figure can be dragged under other figures.

I would like to be able to change figures' z order when the figures are selected so they are moved to the top of the children list and appear at the top of the z dimension of the chart. What is the best way to do that?

Mr1159pm
  • 774
  • 1
  • 10
  • 21

2 Answers2

0

I have found that removing the figure and adding back will screw up the event system such that if your intent, for example, is, when a figure is dragged to another location, you want to bring that figure to the front, the dragging is interrupted and you will no longer get any events for that figure. To bring a figure to the top, use the following code:

final IFigure child = <figure you want to bring to the front>;
final IFigure parent = child.getParent();
final List children = child.getParent().getChildren();
children.remove( child );
children.add( child );
child.repaint();

This is manipulate the raw list of children, moving the particular child to the fron of the z-order. Then, a repaint of the child is issued to show this change. This solution is specific to Draw2d, and has nothing to do with GEF.

Eric Vasilik
  • 362
  • 2
  • 14
0

The z-order of the figures in draw2d is defined either by order of addition (last figure on top) or can be set in Figure.add.

I guess the easiest (but probably not very efficient) way of doing what you want is removing the figure from the parent and adding it again. This will make it the last figure added, therefore also the top figure

vainolo
  • 6,907
  • 4
  • 24
  • 47
  • Interesting. I tried to debug GEF yesterday trying to understand why this happens, but could not understand. I found another way to do it, which is installing a new `ResizableEditPolicy` on the `EditPart`, overriding the `showSelection` method and there invoking `reorderChild` on the parent `EditPart`, but in this case it the resize feedback while dragging is destroyed.... Oh well. If I find something I'll post again. – vainolo Mar 11 '12 at 07:58