Transfer elements between views using drag-and-drop in Eclipse RCP?

I have 2 views in my application. In one view, I see a TreeStructure containing user defined elements (such as MDocument, MVersion ...).

I would like to be able to drag elements of type MVersion from my view to another, but I don’t know how to declare transfer types or check if the selected type is selected.

Any ideas?

+4
source share
1 answer

The easiest way is to use LocalSelectionTransfer . Once you have added drag and drop support to your viewers ...

You set the ISelection , which is dragged into the DragSourceListener.dragStart() method:

 LocalSelectionTransfer.getTransfer().setSelection(selection); 

In DropTargetListener.drop() you check if the type is supported and if the selection is retrieved:

 if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) ISelection sel = LocalSelectionTransfer.getTransfer().getSelection(); ... 
+7
source

Source: https://habr.com/ru/post/1385530/


All Articles