Transfer Items between Views with Drag-and-Drop in Eclipse RCP?

心已入冬 提交于 2019-12-21 17:47:00

问题


I have 2 views in my application. In one of the views I can see a TreeStructure containing custom defined elements (such as MDocument, MVersion...).

I would like to be able to drag items of type MVersion from my view to the other one but I don't know how to declare the transfer types or to check if the item selected is a supported type.

Any ideas?


回答1:


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

You set the ISelection that is dragged in DragSourceListener.dragStart() method:

LocalSelectionTransfer.getTransfer().setSelection(selection);

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

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


来源:https://stackoverflow.com/questions/8445899/transfer-items-between-views-with-drag-and-drop-in-eclipse-rcp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!