org.eclipse.swt.dnd.ByteArrayTransfer Java Examples

The following examples show how to use org.eclipse.swt.dnd.ByteArrayTransfer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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()]);
}
 
Example #2
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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();
		}
	}
}