Simone Gianni
Simone Gianni

Reputation: 11672

GEF : automatic scrolling during drag and drop

I have a graphical editor written with GEF. In this editor it's possible to drag and drop elements around and create connection by dragging and dropping on specific anchor points.

Everything works fine, except that the diagram does not automatically scroll when the user drags stuff around.

I would expect the diagram to scroll automatically when the user reaches the side of it while dragging something.

Is such a feature supported by GEF? Which class/setter should be called to enable it?

If it's not directly supported, how to proceed to achieve it?

Upvotes: 2

Views: 800

Answers (2)

Georgian
Georgian

Reputation: 8960

First step is to make your canvas scrollable. This is explained in this book, pages 96 - 101.

Assuming you are already drawing your figures on a FigureCanvas and you're using FreeformFigures and FreeformLayer, you can do the following:

Add a MouseMoveListener on your Figure in its EditPart. Each time a drag is detected, in the mouseDragEvent method, reveal your figure with getViewer().reveal(EditPart.this).

This will cause your Figure to always be constantly revealed when it's being dragged.

Upvotes: 3

Calon
Calon

Reputation: 4212

It's been a while since I last fiddled with GEF.

Does drag and drop not work at all or just in the direction of negative coordinates? What Layout are you using?

IIRC, there were different layouts with one of them (FreeForm?) supporting negative coordinates, so if you just have trouble with negative coords, you could try to change the Layout.

Here is an example of a Scrolling Graphical editor (the author says ;)) which might give you a good hint.

And there is a class named org.eclipse.gef.ui.parts.ScrollingGraphicalViewer that might help, too.

Only hints, though, since I don't know your code.

Upvotes: 3

Related Questions