private static void addDefaultInternalCommands(InternalCommandContextProvider provider, KaviPickListDialog kaviPickList) { provider.addCommand("list: toggle view selected", (currentProvider) -> { currentProvider.toggleViewOnlySelected(); kaviPickList.togglePreviousProvider().refreshFromContentProvider(); }); provider.addCommand("list: selected to clipboard", (currentProvider) -> { Clipboard clipboard = new Clipboard(kaviPickList.getShell().getDisplay()); final List<BiFunction<Object, Integer, String>> fieldResolvers = currentProvider.getKaviListColumns().getColumnOptions().stream() .filter(column -> column.isSearchable()) .map(column -> column.getColumnContentFn()) .collect(Collectors.toList()); FieldCollectorTransform transform = new FieldCollectorTransform(fieldResolvers, currentProvider.getSelectedEntriesImplied().stream().map(rankedItem -> rankedItem.dataItem).collect(Collectors.toList())); clipboard.setContents(new Object[] { transform.asAlignedColumns() }, new Transfer[] { TextTransfer.getInstance() }); kaviPickList.togglePreviousProvider().refreshFromContentProvider(); clipboard.dispose(); }); provider.addCommand("working", "list: toggle sort name", (currentProvider) -> { kaviPickList.togglePreviousProvider().sortDefault().refreshFromContentProvider(); }); }
private void copySelectedAsTabDelimited() { StringBuffer stringBuffer = new StringBuffer(); int totalRowCount = debugDataViewer.getTableViewer().getTable().getItemCount(); int totalColumnCount = debugDataViewer.getTableViewer().getTable().getColumnCount(); boolean hasRow=false; for (int rowCount = 0; rowCount < totalRowCount; rowCount++) { for (int columnCount = 0; columnCount < totalColumnCount; columnCount++) { Point cell = new Point(rowCount, columnCount); if(debugDataViewer.getSelectedCell().contains(cell)){ stringBuffer.append(debugDataViewer.getTableViewer().getTable().getItem(rowCount).getText(columnCount) + "\t"); hasRow=true; } cell=null; } if(hasRow){ stringBuffer.append("\n"); hasRow=false; } } Clipboard cb = new Clipboard(Display.getCurrent()); TextTransfer textTransfer = TextTransfer.getInstance(); String textData = stringBuffer.toString(); cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer }); cb.dispose(); }
@Override public void updateUI() { boolean bTorrentInClipboard = false; Clipboard clipboard = new Clipboard(Display.getDefault()); String sClipText = (String) clipboard.getContents(TextTransfer.getInstance()); if (sClipText != null) bTorrentInClipboard = addTorrentsFromTextList(sClipText, true) > 0; if (btnPasteOpen != null && !btnPasteOpen.isDisposed() && btnPasteOpen.isVisible() != bTorrentInClipboard) { btnPasteOpen.setVisible(bTorrentInClipboard); if (bTorrentInClipboard) { btnPasteOpen.setToolTipText(sClipText); } } clipboard.dispose(); }
public static void copyToClipBoard( final String data ) { Runnable do_it = new Runnable() { @Override public void run() { new Clipboard(Utils.getDisplay()).setContents( new Object[] {data.replaceAll("\\x00", " " ) }, new Transfer[] {TextTransfer.getInstance()}); } }; if ( Utils.isSWTThread()){ do_it.run(); }else{ Utils.execSWTThread( do_it ); } }
public static void addCopyToClipMenu( final Menu menu, final String text ) { MenuItem item = new MenuItem( menu,SWT.NONE ); String msg_text_id= "label.copy.to.clipboard"; item.setText( MessageText.getString( msg_text_id )); item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent arg0) { new Clipboard(menu.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()}); } }); }
/** * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { PasswordSafeJFace app = PasswordSafeJFace.getApp(); PwsEntryBean selected = app.getSelectedRecord(); if (selected == null) return; // retrieve filled Entry, always needed for passwords PwsEntryBean theEntry = app.getPwsDataStore().getEntry(selected.getStoreIndex()); Clipboard cb = new Clipboard(app.getShell().getDisplay()); app.copyToClipboard(cb, theEntry.getPassword().toString()); final IPreferenceStore thePrefs = JFacePreferences.getPreferenceStore(); final boolean recordAccessTime = thePrefs .getBoolean(JpwPreferenceConstants.RECORD_LAST_ACCESS_TIME); if (recordAccessTime) { // this could/should be sent to a background // thread app.updateAccessTime(theEntry); } cb.dispose(); }
/** * Initialize copy paste by getting the clipboard and hooking * the actions to global edit menu. * * @param viewer */ private void initCopyPaste(TreeViewer viewer) { this.clipboard = new Clipboard(getSite().getShell().getDisplay()); IActionBars bars = getSite().getActionBars(); bars.setGlobalActionHandler( ActionFactory.CUT.getId(), (Action)outlineActions.get(ACTION_CUT)); bars.setGlobalActionHandler( ActionFactory.COPY.getId(), (Action)outlineActions.get(ACTION_COPY)); bars.setGlobalActionHandler( ActionFactory.PASTE.getId(), (Action)outlineActions.get(ACTION_PASTE)); bars.setGlobalActionHandler( ActionFactory.DELETE.getId(), (Action)outlineActions.get(ACTION_DELETE)); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); String url = getBookmarkUrl(selection); if (url == null) { return null; } Clipboard clipboard = new Clipboard(null); try { TextTransfer textTransfer = TextTransfer.getInstance(); Transfer[] transfers = new Transfer[] { textTransfer }; Object[] data = new Object[] { url }; clipboard.setContents(data, transfers); } finally { clipboard.dispose(); } return null; }
private IStructuredSelection getStructuredSelectionFromClipboard(Display display) { Clipboard clipboard = new Clipboard(display); try { String text = (String) clipboard.getContents(URLTransfer.getInstance()); if (text == null) { text = (String) clipboard.getContents(TextTransfer.getInstance()); } if (text != null) { try { URL url = new URL(text); return new StructuredSelection(url); } catch (MalformedURLException e) { } } String[] paths = (String[]) clipboard.getContents(FileTransfer.getInstance()); if (paths != null) { return new StructuredSelection(Arrays.stream(paths).map(Path::new).collect(Collectors.toList())); } return new StructuredSelection(); } finally { clipboard.dispose(); } }
/** * テーブルの選択されている部分をヘッダー付きでクリップボードにコピーします * * @param header ヘッダー * @param table テーブル */ public static void copyTable(String[] header, Table table) { TableItem[] tableItems = table.getSelection(); StringBuilder sb = new StringBuilder(); sb.append(StringUtils.join(header, "\t")); sb.append("\r\n"); for (TableItem column : tableItems) { String[] columns = new String[header.length]; for (int i = 0; i < header.length; i++) { columns[i] = column.getText(i); } sb.append(StringUtils.join(columns, "\t")); sb.append("\r\n"); } Clipboard clipboard = new Clipboard(Display.getDefault()); clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() }); }
/** * ツリーの選択されている部分をヘッダー付きでクリップボードにコピーします * * @param header ヘッダー * @param tree ツリー */ public static void copyTree(String[] header, Tree tree) { TreeItem[] treeItems = tree.getSelection(); StringBuilder sb = new StringBuilder(); sb.append(StringUtils.join(header, "\t")); sb.append("\r\n"); for (TreeItem column : treeItems) { String[] columns = new String[header.length]; for (int i = 0; i < header.length; i++) { columns[i] = column.getText(i); } sb.append(StringUtils.join(columns, "\t")); sb.append("\r\n"); } Clipboard clipboard = new Clipboard(Display.getDefault()); clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() }); }
protected String fromClipboard(IEditorPart editor) { Shell shell = editor.getSite().getShell(); Display display = shell.getDisplay(); Clipboard clip = new Clipboard(display); try { TextTransfer transfer = TextTransfer.getInstance(); return (String)clip.getContents(transfer); } catch(Exception e) { ElementHelper.panic(log, "from clipboard", e); throw new RuntimeException(e); } finally { clip.dispose(); } }
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if("hasTextContent".equals(property)) { IWorkbenchPart part = Helper.getActivePart(); if(part == null) { return false; } Display display = part.getSite().getShell().getDisplay(); Clipboard clip = new Clipboard(display); Object content = clip.getContents(TextTransfer.getInstance()); clip.dispose(); return expectedValue.equals(content != null); } return false; }
private void copyToClipboard(TreeItem[] items, Clipboard clipboard) { StringBuilder sb = new StringBuilder(); for (TreeItem item : items) { Object data = item.getData(); if (data != null) { sb.append(data.toString()); sb.append('\n'); } } String content = sb.toString(); if (content.length() > 0) { clipboard.setContents( new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()} ); } }
/** * Copies the current selection of a Table into the provided Clipboard, as * multi-line text. * * @param clipboard The clipboard to place the copied content. * @param table The table to copy from. */ private static void copyTable(Clipboard clipboard, Table table) { int[] selection = table.getSelectionIndices(); // we need to sort the items to be sure. Arrays.sort(selection); // all lines must be concatenated. StringBuilder sb = new StringBuilder(); // loop on the selection and output the file. for (int i : selection) { TableItem item = table.getItem(i); LogMessage msg = (LogMessage)item.getData(); String line = msg.toString(); sb.append(line); sb.append('\n'); } // now add that to the clipboard clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() }); }
/** Copy all selected messages to clipboard. */ public void copySelectionToClipboard(Clipboard clipboard) { StringBuilder sb = new StringBuilder(); for (LogCatMessage m : getSelectedLogCatMessages()) { sb.append(m.toString()); sb.append('\n'); } if (sb.length() > 0) { clipboard.setContents( new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()} ); } }
public void run() { ISelection sel = viewer.getSelection(); if (sel instanceof StructuredSelection) { StringBuilder sb = new StringBuilder(); @SuppressWarnings("unchecked") Iterator<File> i = ((StructuredSelection)sel).iterator(); while (i.hasNext()) { File file = i.next(); sb.append(file.getAbsolutePath().replace("\\", "/")); if (i.hasNext()) { sb.append(sep); } } Clipboard clipboard = new Clipboard(Display.getDefault()); clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() }); clipboard.dispose(); } }
public void run() { ISelection sel = viewer.getSelection(); if (sel instanceof StructuredSelection) { if (sel.isEmpty()) return; List<String> paths = new ArrayList<String>(); @SuppressWarnings("unchecked") Iterator<File> i = ((StructuredSelection)sel).iterator(); while (i.hasNext()) { File file = i.next(); if (file.isDirectory()) continue; paths.add(file.getAbsolutePath()); } Clipboard clipboard = new Clipboard(Display.getDefault()); clipboard.setContents(new Object[] { (String[])paths.toArray(new String[paths.size()]) }, new Transfer[] { FileTransfer.getInstance() }); clipboard.dispose(); } }
/*************************************************************************** * Copy selected source rows **************************************************************************/ public void copySelected() { GridItem[] selection = getGrid().getSelection(); Clipboard clipboard = new Clipboard(Display.getCurrent()); String data = ""; for (GridItem item : selection) { if (!data.isEmpty()) data += "\n"; String line = item.getText(CodeViewerColumn.CODE.ordinal()); if (line != null) { line = line.trim(); } else { line = ""; } data += line; } clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() }); clipboard.dispose(); }
@Override public void createPartControl(Composite parent) { FeatureModelManager featureModelManager = FeatureSupport.getManager(); ProductModelManager productModelManager = ProductSupport.getManager(); FeatureAndProductInput input = new FeatureAndProductInput(featureModelManager, productModelManager); this.featureIndex = new FeatureIndex(featureModelManager, productModelManager); FilteredTree filteredTree = createFilteredTree(parent); this.viewer = filteredTree.getViewer(); this.patternFilter = filteredTree.getPatternFilter(); this.viewerFilters.add(patternFilter); this.clipboard = new Clipboard(parent.getDisplay()); this.copyAction = new FeatureAndPluginCopyAction(viewer, clipboard); this.pasteAction = new FeatureAndPluginPasteAction(viewer, clipboard); registerGlobalActions(); contributeToActionBar(featureModelManager, productModelManager); hookContextMenu(); initialiseViewer(input); }
protected void makeActions() { clipboard = new Clipboard(shell.getDisplay()); pasteAction = new PasteAction(shell, clipboard); pasteAction.setImageDescriptor(GamaIcons.create("menu.paste2").descriptor()); pasteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE); copyAction = new CopyAction(shell, clipboard, pasteAction); copyAction.setImageDescriptor(GamaIcons.create("menu.copy2").descriptor()); copyAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY); final IShellProvider sp = () -> shell; deleteAction = new DeleteResourceAction(sp); deleteAction.setImageDescriptor(GamaIcons.create("menu.delete2").descriptor()); deleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE); }
/** * Copies the current selection to the clipboard. * * @param table the data source */ protected void copy(final Table table) { if (canCopy(table)) { final StringBuilder data = new StringBuilder(); for (int row = 0; row < table.getSelectionCount(); row++) { for (int col = 0; col < table.getColumnCount(); col++) { data.append(table.getSelection()[row].getText(col)); if (col == 0) { data.append('='); } else if (row != table.getSelectionCount() - 1) { data.append(NewLine.SYSTEM_LINE_SEPARATOR); } } } final Clipboard clipboard = new Clipboard(table.getDisplay()); clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() }); clipboard.dispose(); } }
/** * Copies the current selection to the clipboard. * * @param list the data source */ protected void copy(final List list) { if (canCopy(list)) { final StringBuilder data = new StringBuilder(); for (int row = 0; row < list.getSelectionCount(); row++) { data.append(list.getSelection()[row]); if (row != list.getSelectionCount() - 1) { data.append(NewLine.SYSTEM_LINE_SEPARATOR); } } final Clipboard clipboard = new Clipboard(list.getDisplay()); clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() }); clipboard.dispose(); } }
private ITransferableSpi getContents(final Clipboard clipboard) { final Map<TransferTypeSpi, Object> transferMap = new LinkedHashMap<TransferTypeSpi, Object>(); for (final TransferData transferData : clipboard.getAvailableTypes()) { if (TEXT_TRANSFER.isSupportedType(transferData)) { transferMap.put(new TransferTypeSpi(String.class), clipboard.getContents(TEXT_TRANSFER)); } else if (OBJECT_TRANSFER.isSupportedType(transferData)) { final Object data = clipboard.getContents(OBJECT_TRANSFER); if (data instanceof TransferContainer) { for (final TransferObject transferObject : ((TransferContainer) data).getTransferObjetcs()) { transferMap.put(transferObject.getTransferType(), transferObject.getData()); } } } } if (!transferMap.isEmpty()) { return new TransferableSpiAdapter(transferMap); } else { return null; } }
protected void copyToClipboard(IStructuredSelection selection) { StringBuilder sb = new StringBuilder(); for (Object object : (List<?>) selection.toList()) { if(object instanceof TreeParent){ TreeParent tp = (TreeParent) object; object = tp.getNamedElement(); if(object != null){ NamedElement elt = (NamedElement) object; sb.append(elt.getNameAndVersion()).append("\n"); } else if(tp instanceof TreeProblem) { sb.append(((TreeProblem) tp).getProblem()).append("\n"); } } } TextTransfer textTransfer = TextTransfer.getInstance(); final Clipboard cb = new Clipboard(getSite().getShell().getDisplay()); try { cb.setContents(new Object[]{sb.toString()}, new Transfer[]{textTransfer}); } finally { cb.dispose(); } }
public synchronized void disposeClipboards() { trace.debug("disposing " + displayToClipboard.size() + " clipboards"); for (Map.Entry<Display, Clipboard> entry : displayToClipboard.entrySet()) { Display display = entry.getKey(); if (!display.isDisposed()) { final Clipboard clipboard = entry.getValue(); display.syncExec(new Runnable() { @Override public void run() { clipboard.dispose(); } }); } } displayToClipboard.clear(); }
/** * Return the clipboard contents from our local cache, if the contents are present and support the acceptableType * * @param acceptableTypes * @param clipboard * @return ClipboardContents */ private ClipboardContents getCachedContents(List<TransferData> acceptableTypes, Clipboard clipboard) { TransferData type = getMatchingType(acceptableTypes); if (type != null) { Transfer markerTransfer = markerTransferProvider.getTransfer(); Object markerTransferObject = clipboard.getContents(markerTransfer); if (markerTransferObject instanceof byte[]) { ITransferable transferable = markerTransferProvider.unpackTransferObject((byte[]) markerTransferObject); if (transferable instanceof MarkerTransferable) { MarkerTransferable markerTransferable = (MarkerTransferable) transferable; if (markerTransferable.getMarker() == cachedClipboardMarker.getMarker()) { return new ClipboardContents(type, cachedClipboardTransferable); } } } } return null; }
/** * Clear out the clipboard contents */ public static void clearClipboardContents() { final Display display = WidgetUtils.getDisplay(); display.syncExec(new Runnable() { @Override public void run() { Clipboard clipboard = ClipboardServer.instance.getClipboard(display); try { clipboard.clearContents(); } catch (ThreadDeath td) { throw td; } catch (Throwable t2) { LogUtil.warn("failed to clear the clipboard"); } } }); }
protected boolean somethingAvailable() { final Display display = WidgetUtils.getDisplay(); final TransferData[][] typesArray = new TransferData[1][]; display.syncExec(new Runnable() { @Override public void run() { Clipboard clipboard = ClipboardServer.instance.getClipboard(display); typesArray[0] = clipboard.getAvailableTypes(); } }); TransferData[] types = typesArray[0]; if ((types == null) || (types.length == 0)) { return false; } List<TransferData> acceptableTypes = new ArrayList<TransferData>(); for (TransferData type : types) { if (modifier.canInsert(type, targetSelection, InsertionSemantics.ON)) { acceptableTypes.add(type); } } if (acceptableTypes.isEmpty()) { return false; } this.acceptableTypes = Collections.unmodifiableList(acceptableTypes); return true; }
/** * Get the clipboard contents. Plan clipboard contents should consist * of an array which is a string and then one or more plan elements. * @param modifier * @param expectedElements */ public static PlanTransferable getClipboardContents() { Clipboard clipboard = ClipboardServer.instance.getClipboard(null); TransferData[] types = clipboard.getAvailableTypes(); Assert.assertNotNull(types); Assert.assertTrue(types.length != 0); List<TransferData> acceptableTypes = new ArrayList<TransferData>(); for (TransferData type : types) { for (Transfer transfer : planTransfers) { if (transfer.isSupportedType(type)) { acceptableTypes.add(type); break; } } } Assert.assertFalse(acceptableTypes.isEmpty()); ClipboardContents contents = TransferRegistry.getInstance().getFromClipboard(acceptableTypes); Assert.assertNotNull(contents); Assert.assertTrue(contents.transferable instanceof PlanTransferable); return (PlanTransferable)contents.transferable; }
private void copyToClipboard(IResource[] resources, String[] fileNames, String names, IJavaElement[] javaElements, TypedSource[] typedSources, int repeat, Clipboard clipboard) { final int repeat_max_count= 10; try{ clipboard.setContents(createDataArray(resources, javaElements, fileNames, names, typedSources), createDataTypeArray(resources, javaElements, fileNames, typedSources)); } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD || repeat >= repeat_max_count) throw e; if (fAutoRepeatOnFailure) { try { Thread.sleep(500); } catch (InterruptedException e1) { // do nothing. } } if (fAutoRepeatOnFailure || MessageDialog.openQuestion(fShell, ReorgMessages.CopyToClipboardAction_4, ReorgMessages.CopyToClipboardAction_5)) copyToClipboard(resources, fileNames, names, javaElements, typedSources, repeat + 1, clipboard); } }
/** * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ; */ private void copy() { super.doOperation(ITextOperationTarget.COPY); TextTransfer plainTextTransfer = TextTransfer.getInstance(); XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance(); Clipboard clipboard = new Clipboard(getTextWidget().getDisplay()); String plainText = (String) clipboard.getContents(plainTextTransfer); if (plainText == null || plainText.length() == 0) { return; } plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n"); plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", ""); plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t"); plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " "); plainText = plainText.replaceAll("\u200B", ""); clipboard.clearContents(); Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText }; Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer }; clipboard.setContents(data, types, DND.CLIPBOARD); clipboard.dispose(); }
public void serialize() { final Clipboard clipboard = command.getClipboard(); final String cellDelimeter = command.getCellDelimeter(); final String rowDelimeter = command.getRowDelimeter(); final TextTransfer textTransfer = TextTransfer.getInstance(); final StringBuilder textData = new StringBuilder(); int currentRow = 0; for (LayerCell[] cells : copiedCells) { int currentCell = 0; for (LayerCell cell : cells) { final String delimeter = ++currentCell < cells.length ? cellDelimeter : ""; if (cell != null) { textData.append(cell.getDataValue() + delimeter); } else { textData.append(delimeter); } } if (++currentRow < copiedCells.length) { textData.append(rowDelimeter); } } clipboard.setContents(new Object[]{textData.toString()}, new Transfer[]{textTransfer}); }
public void updateUI() { boolean bTorrentInClipboard = false; Clipboard clipboard = new Clipboard(Display.getDefault()); String sClipText = (String) clipboard.getContents(TextTransfer.getInstance()); if (sClipText != null) bTorrentInClipboard = addTorrentsFromTextList(sClipText, true) > 0; if (btnPasteOpen != null && !btnPasteOpen.isDisposed() && btnPasteOpen.isVisible() != bTorrentInClipboard) { btnPasteOpen.setVisible(bTorrentInClipboard); if (bTorrentInClipboard) { btnPasteOpen.setToolTipText(sClipText); } } clipboard.dispose(); }