Community
Participate
Working Groups
We all know what the copy action for a list viewer is, it's to accumulate the text in the selected item(s) and put it on the clipboard. So, why not provide it once and for all. (Yes, of course, someone might want a more complex version that uses more of the interior structure for more data). The following is nearly the generic implementation, except that I didn't just use the label provider to get the text. ISelection viewerSelection = tmListViewer.getSelection(); IStructuredSelection iss = (IStructuredSelection)viewerSelection; Clipboard clipboard = new Clipboard(getControl().getDisplay()); String textData = ""; StringBuffer tb = new StringBuffer(); Iterator it = iss.iterator(); while(it.hasNext()) { TMMatchSet.Match element = (TMMatchSet.Match)it.next(); tb.append(element.text); tb.append("\n"); } textData = tb.toString(); TextTransfer textTransfer = TextTransfer.getInstance(); Transfer[] transfers = new Transfer[] { textTransfer }; Object[] data = new Object[] { textData }; clipboard.setContents(data, transfers); clipboard.dispose();
*** This bug has been marked as a duplicate of bug 121782 ***