Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Drag and Drop(EMF Drag and Drop)
EMF Drag and Drop [message #1750898] Sat, 31 December 2016 20:49 Go to next message
Michael Maenz is currently offline Michael MaenzFriend
Messages: 3
Registered: December 2016
Junior Member
Hello,

I have 4 Trees and want to drag and drop items from one tree to another.
I looked at the emf generated editor code but I need something else.

The first treeview has a library which exposes the metamodel and the others have the actual EObjects. I like to drag and drop items from the metamodel to the other trees depending on the superclass in the metamodel. I added EditingDomainViewerDropAdapter and ViewerDragAdapter to all treeviews. Drag and drop works between all trees except the library with the metamodel. I need a way to create new instances on drop but don't know how to achieve this (DragAndDropCommand?)

I also like to know how to do a check (validateDrop) in each tree before the drop if the item is suitable. I used ViewerDropAdapter in the past but EditingDomainViewerDropAdapter seems not to have a feature like that.

Thanks
-Michael
Re: EMF Drag and Drop [message #1751001 is a reply to message #1750898] Tue, 03 January 2017 15:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Mostly you can specialize drag and drop behavior by specializing the createXyzCommand methods in the generated XyzItemProvider of the receiver/target. If the created command is not executable, drag and drop will not be allowed. So you can specialize the org.eclipse.emf.edit.provider.ItemProviderAdapter.createAddCommand(EditingDomain, EObject, EStructuralFeature, Collection<?>, int) to either allow an add or to now allow it. In the case where you need to somehow convert what's dropped to something else, you can specialize org.eclipse.emf.edit.provider.ItemProviderAdapter.getChildFeature(Object, Object) on the receiver (which is called by org.eclipse.emf.edit.provider.ItemProviderAdapter.factorAddCommand(EditingDomain, CommandParameter)) so that it returns the appropriate feature where you want that object's converted result to be added, and then specialize the createAddCommand to filter the collection to convert the object to be added to some type of object that can really be added.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Drag and Drop [message #1751609 is a reply to message #1751001] Wed, 11 January 2017 20:51 Go to previous messageGo to next message
Michael Maenz is currently offline Michael MaenzFriend
Messages: 3
Registered: December 2016
Junior Member
Thanks for your fast reply.

It seems like I have a platform specific problem here. I'm using a Mac as development machine. The drop always fails with a NullPointerException. On Windows (tested in VirtualBox) the drag source data is available from the very beginning, given to the LocalTransfer-Class on dragStart and stored the right way. On Mac the drag data is provided first after the actual drop event and thus not available at dragStart in ViewerDragAdapter.dragStart and EditingDomainViewerDropAdapter.dragEnter.

Second seems like a EMF LocalTransfer bug? If I store the data in extended/overriden ViewerDragAdapter.dragStart to LocalTransfer.javaToNative with (Object)viewer.getSelection, the data is stored in the javaToNative method to an object (short-circuit) but the data in event.data will stay null as ByteArrayTransfer.javaToNative returns null. On drop, the data of event.data is still null and nativeToJava fails but should/doesn't return the short-circuit-object with the selection set in javaToNative. The object in LocalTransfer is set but never used again.

My workaround is a singleton class. An extended/overriden ViewerDragAdapter.dragStart sets the object directly from the viewer.getSelection and an extended/overriden EditingDomainViewerDropAdapter.dragEnter sets super.source to the data from the singleton. Didn't try on linux/solaris but may fails too?

If LocalTransfer.nativeToJava would return the object (when ByteArrayTransfer.nativeToJava returns null and object != null), everything would work better.

Or do I have a wrong understanding?

Thanks!
-Michael
Re: EMF Drag and Drop [message #1751638 is a reply to message #1751609] Thu, 12 January 2017 07:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Your observation on differences in drag and drop behavior is definitely an inherent difference in behavior of the platforms. Indeed generally there is no drag data available until the drop phase on Linux and Mac. EMF's implementation of LocalTransfer also has that behavior because it won't return the selected object until the transfer data returns the expected start time. You can use the platform's LocalSelectionTransfer to get different behavior, but keep in mind that all other transfers will similarly not have the drag data available early so if you're expecting that generally, it won't work generally. Only Windows provides this behavior.

In Oomph I worked on an improved (more flexible) implementation of drag and drop support for EMF (e.g., provide a textual transfer of the XMI serialization of the selection so that drag and drop works between separate processes, and using the system clipboard so that drag and drop generally works between editors, even in separate processes), but even here, the differences in platform behavior are super annoying. I.e., if I can't know the object being dragged, so I can't provide decent early feedback, and I can't even determine which is the best transfer to use based on the data that's available in the transfer. In this scenario, the behavior of checking the start time becomes more important, because the start time of the LocalTransfer will not match what's in the transfer data and hence the local selection that might be available shouldn't be used.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Customizing EMF context menu
Next Topic:[Xcore] specifying a setter for a many-valued derived feature
Goto Forum:
  


Current Time: Tue Apr 23 07:14:15 GMT 2024

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

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

Back to the top