private static Transfer[] createDataTypeArray(IResource[] resources, IJavaElement[] javaElements, String[] fileNames, TypedSource[] typedSources) { List<ByteArrayTransfer> result= new ArrayList<ByteArrayTransfer>(4); if (resources.length != 0) result.add(ResourceTransfer.getInstance()); if (javaElements.length != 0) result.add(JavaElementTransfer.getInstance()); if (fileNames.length != 0) result.add(FileTransfer.getInstance()); if (typedSources.length != 0) result.add(TypedSourceTransfer.getInstance()); result.add(TextTransfer.getInstance()); return result.toArray(new Transfer[result.size()]); }
private void doCutCopyWithImportsOperation() { ITextEditor editor= getTextEditor(); ITypeRoot inputElement= JavaUI.getEditorInputTypeRoot(editor.getEditorInput()); ISelection selection= editor.getSelectionProvider().getSelection(); Object clipboardData= null; if (inputElement != null && selection instanceof ITextSelection && !selection.isEmpty()) { ITextSelection textSelection= (ITextSelection) selection; if (isNonTrivialSelection(textSelection)) { clipboardData= getClipboardData(inputElement, textSelection.getOffset(), textSelection.getLength()); } } fOperationTarget.doOperation(fOperationCode); if (clipboardData != null) { /* * We currently make assumptions about what the styled text widget sets, * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=61876 */ Clipboard clipboard= new Clipboard(getDisplay()); try { Object textData= clipboard.getContents(TextTransfer.getInstance()); /* * Don't add if we didn't get any text data from the clipboard, see: * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=70077 * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=200743 */ if (textData == null) return; ArrayList<Object> datas= new ArrayList<Object>(3); ArrayList<ByteArrayTransfer> transfers= new ArrayList<ByteArrayTransfer>(3); datas.add(textData); transfers.add(TextTransfer.getInstance()); Object rtfData= clipboard.getContents(RTFTransfer.getInstance()); if (rtfData != null) { datas.add(rtfData); transfers.add(RTFTransfer.getInstance()); } datas.add(clipboardData); transfers.add(fgTransferInstance); Transfer[] dataTypes= transfers.toArray(new Transfer[transfers.size()]); Object[] data= datas.toArray(); setClipboardContents(clipboard, data, dataTypes); } finally { clipboard.dispose(); } } }