问题
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