本文介绍了在Eclipse RCP中拖放视图之间传输项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有2个视图。在其中一个视图中,我可以看到包含自定义元素(如MDocument,MVersion ...)的TreeStructure。



我希望能够拖动从我的视图类型MVersion到另一个,但我不知道如何声明传输类型或检查选择的项目是否是支持的类型。



任何想法?

解决方案

最简单的方法是使用 LocalSelectionTransfer 。一旦你向观众添加了拖放支持...



你设置了被拖入的 ISelection DragSourceListener.dragStart()方法:

  LocalSelectionTransfer.getTransfer()。为setSelection(选择); 

DropTargetListener.drop()检查类型是否支持,并检索选择:

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


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?

解决方案

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();
    ...

这篇关于在Eclipse RCP中拖放视图之间传输项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:41