org.eclipse.swt.dnd.RTFTransfer Java Examples
The following examples show how to use
org.eclipse.swt.dnd.RTFTransfer.
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: TextEditor.java From birt with Eclipse Public License 1.0 | 5 votes |
private void pasteClipboard( ) { Clipboard cb = new Clipboard( Display.getCurrent( ) ); // TransferData[] types = cb.getAvailableTypes( ); RTFTransfer rtfTransfer = RTFTransfer.getInstance( ); Object contents = cb.getContents( rtfTransfer ); // textEditor.paste( ); if ( contents != null ) { RTFHTMLHandler handler = new RTFHTMLHandler( ); try { RTFParser.parse( contents.toString( ), handler ); textEditor.insert( handler.toHTML( ) ); return; } catch ( Exception e1 ) { } } else { HTMLTransfer htmlTransfer = HTMLTransfer.getInstance( ); contents = cb.getContents( htmlTransfer ); if ( contents != null ) { textEditor.insert( contents.toString( ) ); return; } } TextTransfer plainTextTransfer = TextTransfer.getInstance( ); String text = (String) cb.getContents( plainTextTransfer, DND.CLIPBOARD ); textEditor.insert( text ); }
Example #2
Source File: ImportsAwareClipboardAction.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
private void doCutCopyWithImportsOperation() { try { final XbaseClipboardData cbData = createClipboardData(); if (cbData != null ) { ClipboardUtil.clipboardOperation(new Function<Clipboard, Boolean>() { @Override public Boolean apply(Clipboard clipboard) { Map<Object,Transfer> payload = newLinkedHashMap(); payload.put(cbData, TRANSFER_INSTANCE); TextTransfer textTransfer = TextTransfer.getInstance(); String textData = (String) clipboard.getContents(textTransfer); if (textData == null || textData.isEmpty()) { // StyledText copied any data to ClipBoard return Boolean.FALSE; } payload.put(textData, textTransfer); RTFTransfer rtfTransfer = RTFTransfer.getInstance(); String rtfData = (String) clipboard.getContents(rtfTransfer); if (rtfData != null && !rtfData.isEmpty()) { payload.put(rtfData, rtfTransfer); } List<Object> datas = newArrayList(); List<Transfer> dataTypes = newArrayList(); for (Entry<Object, Transfer> entry : payload.entrySet()) { datas.add(entry.getKey()); dataTypes.add(entry.getValue()); } try { clipboard.setContents(datas.toArray(), dataTypes.toArray(new Transfer[] {})); return Boolean.TRUE; } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(getShell(), ActionMessages.CopyQualifiedNameAction_ErrorTitle, ActionMessages.CopyQualifiedNameAction_ErrorDescription)) { clipboard.setContents(datas.toArray(), dataTypes.toArray(new Transfer[] {})); return Boolean.TRUE; } return Boolean.FALSE; } } }); } } finally { textOperationTarget.doOperation(operationCode); } }
Example #3
Source File: ClipboardOperationAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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(); } } }