是否可以将多个对象(代表TreeViewer
个选项)放入剪贴板?这是我的Cut代码。
static public void Cut(EssentialData dataInst)
{
IStructuredSelection selection = (IStructuredSelection)dataInst.getTreeViewer().getSelection();
if(selection == null)
{
System.err.println("selection received was null");
return;
}
Object[] objects = selection.toArray();
//because setContents requires a Transfer object for every object sent
List<Transfer> typesList = new ArrayList<>();
for(int i = 0; i < objects.length; i++)
typesList.add(FileEntryTransfer.getInstance());
final Clipboard cb = new Clipboard(Display.getCurrent());
cb.setContents(objects, typesList.toArray(new Transfer[]{}));
cb.dispose();
for(int i = 0; i < objects.length; i++)
dataInst.getFileManager().removeEntry((FileEntry)objects[i]);
dataInst.getTreeViewer().refresh(false);
}
我要做的是将多个选项(FileEntry
的实例)放入剪贴板。
FileEntryTransfer
是我的自定义ByteArrayTransfer
课程,我也用于DND。它运行良好,但我注意到setContents()
实际上只发送了一个FileEntry
对象,而不是一个对象数组(这就是我想要的)。
有什么想法吗?
[编辑]感谢vanaprogeja,我用
解决了这个问题cb.setContents(new Object[]{ objects }, new Transfer[] { FileEntryTransfer.getInstance() });
答案 0 :(得分:2)
怎么样:
cb.setContents(new Object[]{ objects },
new Transfer[] { FileEntryTransfer.getInstance() });