Transfer getTransferType(String mime) { if (mime.equals("text/plain")) { return TextTransfer.getInstance(); } if (mime.equals("text/rtf")) { return RTFTransfer.getInstance(); } if (mime.equals("text/html")) { return HTMLTransfer.getInstance(); } if (mime.equals("text/uri-list")) { return URLTransfer.getInstance(); } if (mime.equals("application/x-java-rawimage")) { return ImageTransfer.getInstance(); } if (mime.equals("application/x-java-file-list") || mime.equals("java.file-list")) { return FileTransfer.getInstance(); } return getCustomTransfer(mime); }
String getMime(Transfer transfer) { if (transfer.equals(TextTransfer.getInstance())) { return "text/plain"; } if (transfer.equals(RTFTransfer.getInstance())) { return "text/rtf"; } ; if (transfer.equals( HTMLTransfer.getInstance())) { return "text/html"; } if (transfer.equals(URLTransfer.getInstance())) { return "text/uri-list"; } if (transfer.equals( ImageTransfer.getInstance())) { return "application/x-java-rawimage"; } if (transfer.equals(FileTransfer.getInstance())) { return "application/x-java-file-list"; } if (transfer instanceof CustomTransfer) { return ((CustomTransfer)transfer).getMime(); } return null; }
public void copyTaskAsHTML(ITask task) { StringBuilder sb = new StringBuilder(); String taskKey = task.getTaskId(); if (taskKey != null) { sb.append("<a href=\"" + task.getUrl() + "\">"); sb.append(taskKey); sb.append("</a>"); sb.append(": "); } sb.append(task.getSummary()); HTMLTransfer textTransfer = HTMLTransfer.getInstance(); TextTransfer tt = TextTransfer.getInstance(); Clipboard clipboard = new Clipboard(Display.getCurrent()); clipboard.setContents(new String[] { sb.toString(), sb.toString() }, new Transfer[] { textTransfer, tt }); clipboard.dispose(); }
/** * Get transferTypes, if null, create them * * @return */ private Transfer[] getTransferTypes() { if (transferTypes == null) { transferTypes = new Transfer[] { TextTransfer.getInstance(), HTMLTransfer.getInstance() }; } return transferTypes; }
public static void copyToClipboard(String html) { if (html == null || html.length() == 0) return; html = html.replace("<table", "<table border=\"1\""); Clipboard clipboard = new Clipboard(Display.getCurrent()); TextTransfer textTransfer = TextTransfer.getInstance(); HTMLTransfer htmlTransfer = HTMLTransfer.getInstance(); Transfer[] transfers = new Transfer[] {textTransfer, htmlTransfer}; Object[] data = new Object[] {html, html}; clipboard.setContents(data, transfers); clipboard.dispose(); }
private boolean isThereSomethingToPaste() { Clipboard clipboard = new Clipboard(Display.getCurrent()); try { TextTransfer textTransfer = TextTransfer.getInstance(); HTMLTransfer htmlTransfer = HTMLTransfer.getInstance(); String textData = (String)clipboard.getContents(textTransfer); String htmlData = (String)clipboard.getContents(htmlTransfer); return (textData != null && textData.length() > 0) || (htmlData != null && htmlData.length() > 0); } finally { clipboard.dispose(); } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart instanceof WorkWeekView) { LocalDate firstDayOfWeek = ((WorkWeekView) activePart).getFirstDayOfWeek(); HTMLExporter export = new HTMLExporter(); String result = export.getData(firstDayOfWeek); HTMLTransfer textTransfer = HTMLTransfer.getInstance(); TextTransfer tt = TextTransfer.getInstance(); Clipboard clipboard = new Clipboard(Display.getCurrent()); clipboard.setContents(new String[] { result, result }, new Transfer[] { textTransfer, tt }); clipboard.dispose(); } return null; }
Transfer getTransferType(String mime) { if (mime.equals("text/plain")) return TextTransfer.getInstance(); if (mime.equals("text/rtf")) return RTFTransfer.getInstance(); if (mime.equals("text/html")) return HTMLTransfer.getInstance(); if (mime.equals("text/uri-list")) return URLTransfer.getInstance(); if (mime.equals("application/x-java-rawimage")) return ImageTransfer.getInstance(); if (mime.equals("application/x-java-file-list") || mime.equals("java.file-list")) { return FileTransfer.getInstance(); } return getCustomTransfer(mime); }
String getMime(Transfer transfer) { if (transfer.equals(TextTransfer.getInstance())) return "text/plain"; if (transfer.equals(RTFTransfer.getInstance())) return "text/rtf"; ; if (transfer.equals( HTMLTransfer.getInstance())) return "text/html"; if (transfer.equals(URLTransfer.getInstance())) return "text/uri-list"; if (transfer.equals( ImageTransfer.getInstance())) return "application/x-java-rawimage"; if (transfer.equals(FileTransfer.getInstance())) return "application/x-java-file-list"; if (transfer instanceof CustomTransfer) return ((CustomTransfer)transfer).getMime(); return null; }
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 ); }
@Override public Transfer getTransfer() { return HTMLTransfer.getInstance(); }