Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Drag From Viewpart, Drop In Diagram Editor
Drag From Viewpart, Drop In Diagram Editor [message #185877] Thu, 08 May 2008 17:26 Go to next message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
Hey!

I have a ListViewer populated with various EObjects contained in its own
Viewpart. I'd like for the user to be able to drop these onto the diagram.
I've overridden initializeGraphicalViewer() in my DiagramEditor.java, to
add a DropTargetListener, containing this method:

protected List getObjectsBeingDropped()
{
System.out.println(LocalSelectionTransfer.getTransfer().getS election());
return null;
}

However, the getSelection constantly returns null, indicating the
selection hasn't been set.

My DragSourceAdapter looks like this:

public class DragSrcAdapter extends DragSourceAdapter
{

Viewer viewer

... constructor ...

public void dragStart(DragSourceEvent event)
{
event.doit = !viewer.getSelection().isEmpty();
super.dragStart(event);
}

}

I've added drag support to the ListViewer in the ViewPart like so:

listViewer.addDragSupport(DND.DROP_COPY, transfers, new
DragSrcAdapter(listViewer));

Any idea why the selection isn't set when my DropTargetListener is called?

Thanks!

Maurice
Re: Drag From Viewpart, Drop In Diagram Editor [message #185946 is a reply to message #185877] Fri, 09 May 2008 09:42 Go to previous message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
The drag data is not being set properly, so my solution is to change the
method in my DragSrcAdapter and set it it there. Now I have:

public void dragStart(DragSourceEvent event) {
event.doit = !viewer.getSelection().isEmpty();
// Now set the selection

LocalSelectionTransfer.getTransfer().setSelection(viewer.get Selection());
super.dragStart(event);
}

Where the viewer is passed into the DragSrcAdapter Constructor:

listViewer.addDragSupport(DND.DROP_COPY, transfers, new
DragSrcAdapter(listViewer));

This is a bit ugly (well, it looks that way to me) but it does have the
advantage of working! Hopefully I'm going about this the right way, please
pipe up if you think otherwise...

Maurice
Previous Topic:How to make the node in the middle of a compartment?
Next Topic:My diagram freezes when I validate my semantic model
Goto Forum:
  


Current Time: Thu Apr 25 00:56:47 GMT 2024

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

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

Back to the top