TreeViewer selections and the Clipboard

≡放荡痞女 提交于 2019-12-14 03:54:42

问题


Is it possible to place more than one object (which represent TreeViewer selections) into the clipboard? Here's my Cut code.

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);
}

What I'm trying to do is place multiple selections, which are instances of FileEntry, into the clipboard.

FileEntryTransfer is my custom ByteArrayTransfer class that I also use for DND. It works well, but I noticed that setContents() actually sends it only one FileEntry object as opposed to an array of objects (which is what I want).

Any ideas?

[edit]Thanks to vanaprogeja, I sovled it with

cb.setContents(new Object[]{ objects }, new Transfer[] { FileEntryTransfer.getInstance() });

回答1:


How about:

cb.setContents(new Object[]{ objects },
    new Transfer[] { FileEntryTransfer.getInstance() });


来源:https://stackoverflow.com/questions/8498537/treeviewer-selections-and-the-clipboard

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