Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [Zest] How to use Drag and Drop (DND) with zest?
[Zest] How to use Drag and Drop (DND) with zest? [message #767598] Sun, 18 December 2011 12:58 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Does anyone have an example on how to use drag and drop with zest?

Re: [Zest] How to use Drag and Drop (DND) with zest? [message #767620 is a reply to message #767598] Sun, 18 December 2011 14:00 Go to previous messageGo to next message
Fabian Steeg is currently offline Fabian SteegFriend
Messages: 76
Registered: July 2009
Member
To drop things on a graph you could define a drop target for the Graph control:

Graph graphControl = viewer.getGraphControl();
DropTarget dropTarget = new DropTarget(graphControl, DND.DROP_MOVE | DND.DROP_COPY);
dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); // or your Transfer
dropTarget.addDropListener(new DropTargetListener() { /*...*/ });
Re: [Zest] How to use Drag and Drop (DND) with zest? [message #767632 is a reply to message #767620] Sun, 18 December 2011 14:36 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Sorry, I should have written that I am using GraphViewer:

I tried this:

				viewer.addDropSupport(DND.DROP_LINK,
				new Transfer[] { LocalTransfer.getInstance() },
				new ViewerDropAdapter(viewer) {

					@Override
					public boolean validateDrop(Object target, int operation,
							TransferData transferType) {
						if (target != null) {
							System.out.println(target);
						}
						
						return false;
					}

					@Override
					public boolean performDrop(Object data) {
						return true;
					}

					@Override
					protected Object determineTarget(DropTargetEvent event) {
						Graph g = viewer.getGraphControl();
						Point p = g.getDisplay().map(g.getShell(), g, event.x,
								event.y);
						IFigure fig = g.getFigureAt(p.x, p.y);
						return fig;
					}
				});


Problems:
- g.getFigureAt() does not seem to get the figure under mouse position at its correct location: i am not sure whether this is the right way to listen for a drag target...
- validateDrop() provides a GraphLabel, I would expect it to provide my model object...

Any hints?
Re: [Zest] How to use Drag and Drop (DND) with zest? [message #1772491 is a reply to message #767598] Mon, 11 September 2017 13:29 Go to previous message
Alessio Di Fazio is currently offline Alessio Di FazioFriend
Messages: 1
Registered: September 2017
Junior Member
Hi,

sorry for opening this old topic again, but I'd like to post the way to map the event coordinates to the Zest figure:
@Override
protected Object determineTarget(DropTargetEvent event)
{
    Graph g = ((GraphViewer) getViewer()).getGraphControl();
    Point p = g.getDisplay().map(null, g, event.x, event.y);
    IFigure fig = g.getFigureAt(p.x, p.y);
    return fig;
 }


The null control (as specified in the java doc) makes the mapper to use the display.
Previous Topic:Prevent nodes from being dragged out of parent bounds (GEF5)
Next Topic:Depth-first Traversal problem in large-scale model.
Goto Forum:
  


Current Time: Tue Oct 08 20:29:21 GMT 2024

Powered by FUDForum. Page generated in 0.05762 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top