Java Code Examples for org.eclipse.swt.dnd.Clipboard#setContents()

The following examples show how to use org.eclipse.swt.dnd.Clipboard#setContents() . 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: AbapGitView.java    From ADT_Frontend with MIT License 6 votes vote down vote up
/**
 * Copies the current selection to the clipboard.
 *
 * @param table
 *            the data source
 */
protected void copy() {
	Object selection = AbapGitView.this.viewer.getStructuredSelection().getFirstElement();
	if (selection != null && selection instanceof IRepository) {
		IRepository currRepository = ((IRepository) selection);

		String repoStatusString = currRepository.getStatusText() == null ? "" : currRepository.getStatusText(); //$NON-NLS-1$
		String repoUserString = currRepository.getCreatedEmail() == null ? currRepository.getCreatedBy()
				: currRepository.getCreatedEmail();

		String lastChangedAt = currRepository.getDeserializedAt();
		if (lastChangedAt == null || lastChangedAt.equals("0.0")) { //$NON-NLS-1$
			lastChangedAt = currRepository.getCreatedAt();
		}
		String repoLastChangedString = getFormattedDate(lastChangedAt);

		final StringBuilder data = new StringBuilder();
		data.append(currRepository.getPackage() + " " + currRepository.getUrl() + " " + currRepository.getBranchName() + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				+ repoUserString + " " + repoLastChangedString + " " + repoStatusString); //$NON-NLS-1$ //$NON-NLS-2$

		final Clipboard clipboard = new Clipboard(AbapGitView.this.viewer.getControl().getDisplay());
		clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
		clipboard.dispose();
	}
}
 
Example 2
Source File: CopyDataToClipboardSerializer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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});
}
 
Example 3
Source File: CopyDataToClipboardSerializer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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});
}
 
Example 4
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}
}
 
Example 5
Source File: ClipboardHandler.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void putIntoClipboard(int clipboardType, Display display, String plainText) throws SWTError {
    Clipboard clipboard = new Clipboard(display);
    try {
        TextTransfer plainTextTransfer = TextTransfer.getInstance();

        String[] data = new String[] { plainText };
        Transfer[] types = new Transfer[] { plainTextTransfer };

        try {
            clipboard.setContents(data, types, clipboardType);
        } catch (SWTError error) {
            // Copy to clipboard failed. This happens when another application
            // is accessing the clipboard while we copy. Ignore the error.
            // Fixes 1GDQAVN
            // Rethrow all other errors. Fixes bug 17578.
            if (error.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
                throw error;
            }
        }
    } finally {
        clipboard.dispose();
    }
}
 
Example 6
Source File: TreeToClipboardAdapter.java    From logbook with MIT License 6 votes vote down vote up
/**
 * ツリーの選択されている部分をヘッダー付きでクリップボードにコピーします
 * 
 * @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() });
}
 
Example 7
Source File: TLCErrorView.java    From tlaplus with MIT License 6 votes vote down vote up
@Override
public void runWithKey(final boolean excludeActionHeader) {
	// it seems impossible this could ever be null since we treat it as non-null in the constructor.
	if (errorTraceTreeViewer == null) {
		return;
	}
	final TLCError trace = errorTraceTreeViewer.getCurrentTrace();
	if (!trace.hasTrace()) {
		// safeguard in addition to isEnabled 
		return;
	}

	final Clipboard clipboard = new Clipboard(display);
	clipboard.setContents(new Object[] { trace.toSequenceOfRecords(!excludeActionHeader) },
			new Transfer[] { TextTransfer.getInstance() });
	clipboard.dispose();
}
 
Example 8
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void copy(Table table, Converter converter) {
	if (table == null)
		return;
	StringBuilder text = new StringBuilder();
	copyHeaders(table, text);
	copyItems(table, converter, text);
	Clipboard clipboard = new Clipboard(UI.shell().getDisplay());
	clipboard.setContents(new String[] { text.toString() },
			new Transfer[] { TextTransfer.getInstance() });
	clipboard.dispose();
}
 
Example 9
Source File: SwitchMedicationHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Uses first parts of an article name and copies it to the clipboard. <br>
 * Usually including everything from the start that is UPPER-CASE (including UPPER-CASE with
 * DASH or NUMBER mixtures). In case article name does not fulfill common structure at least the
 * first 2 parts (words) are included.
 * 
 */
private void copyShortArticleNameToClipboard(){
	IArticle article = originalPresc.getArticle();
	if (article == null)
		return;
		
	String fullName = article.getName();
	String[] nameParts = fullName.split(SPACE);
	StringBuilder sbFilterName = new StringBuilder();
	
	for (int i = 0; i < nameParts.length; i++) {
		String s = nameParts[i];
		if (i > 0) {
			sbFilterName.append(" ");
		}
		
		// matches upper cases, dash an probably number but not only numbers
		if (s.matches(UPCASES_DASH_NR_PATTERN) && !s.matches(NUMBERS)) {
			sbFilterName.append(s);
		} else {
			// at least first two parts of name are included
			if (i < 2) {
				sbFilterName.append(s);
			} else {
				break;
			}
		}
	}
	
	// copy text to clipboard
	Clipboard cb = new Clipboard(UiDesk.getDisplay());
	TextTransfer textTransfer = TextTransfer.getInstance();
	cb.setContents(new String[] {
		sbFilterName.toString()
	}, new Transfer[] {
		textTransfer
	});
}
 
Example 10
Source File: PlatzhalterView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Copy selected key to clipboard
 */
private void copyToClipboard(){
	String key = getSelectedKey();
	if (key != null) {
		Clipboard clipboard = new Clipboard(getViewSite().getShell().getDisplay());
		clipboard.setContents(new Object[] {
			key
		}, new Transfer[] {
			TextTransfer.getInstance()
		});
		clipboard.dispose();
	}
}
 
Example 11
Source File: ProcidDialog.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
protected void copyProcidToClipboard() {
	Display display = Display.getCurrent();
       Clipboard clipboard = new Clipboard(display);
       clipboard.setContents(new Object[] { processId },
               new Transfer[] { TextTransfer.getInstance() });
       clipboard.dispose();
}
 
Example 12
Source File: file_to_clipboard.java    From ldparteditor with MIT License 5 votes vote down vote up
/**
 * Copy a file into the clipboard
 * Assumes the file exists -> no additional check
 * @param fileName - includes the path
 */

public static void copytoClipboard(String fileName) {
    Display display = Display.getCurrent();
    Clipboard clipboard = new Clipboard(display);
    String[] data = { fileName };
    clipboard.setContents(new Object[] { data },
            new Transfer[] { FileTransfer.getInstance() });
    clipboard.dispose();
}
 
Example 13
Source File: Utils.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
public static void copyToClipboard(String cmdAll) {
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    TextTransfer textTransfer = TextTransfer.getInstance();
    Transfer[] transfers = new Transfer[]{textTransfer};
    Object[] data = new Object[]{cmdAll};
    clipboard.setContents(data, transfers);
    clipboard.dispose();
}
 
Example 14
Source File: CopyRemoteResourceAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(IAction action) {
	ISVNRemoteResource remoteResources[] = getSelectedRemoteResources();
	Clipboard clipboard = new Clipboard(getShell().getDisplay());
	clipboard.setContents(new Object[]{remoteResources[0]},
			new Transfer[]{RemoteResourceTransfer.getInstance()});
	clipboard.dispose();
}
 
Example 15
Source File: CopyUrlToClipboardAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
	Clipboard clipboard = new Clipboard(Display.getCurrent());
	Transfer transfer = TextTransfer.getInstance();
	ISVNRemoteResource[] selectedResources = getSelectedRemoteResources();
	clipboard.setContents(
			new String[]{selectedResources[0].getUrl().toString()}, 
			new Transfer[]{transfer});	
	clipboard.dispose();
}
 
Example 16
Source File: ReferenceSearchViewPageActions.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	TreeViewer viewer = page.getViewer();
	Clipboard clipboard = new Clipboard(viewer.getControl().getDisplay());
	
	ITreeSelection selection = page.getViewer().getStructuredSelection();
	@SuppressWarnings("unchecked")
	Object data = selection.toList().stream()
		.map(sel -> page.getLabelProvider().getText(sel))
		.collect(joining(System.lineSeparator()));
	clipboard.setContents(new Object[] {data}, new Transfer[]{TextTransfer.getInstance()});
	clipboard.dispose();
}
 
Example 17
Source File: TreeClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void copy(Tree tree, ClipboardLabelProvider label) {
	if (tree == null)
		return;
	StringBuilder text = new StringBuilder();
	copyHeaders(tree, label, text);
	copyItems(tree, label, text);
	Clipboard clipboard = new Clipboard(UI.shell().getDisplay());
	clipboard.setContents(new String[] { text.toString() }, new Transfer[] { TextTransfer.getInstance() });
	clipboard.dispose();
}
 
Example 18
Source File: CopyNameAction.java    From ADT_Frontend with MIT License 5 votes vote down vote up
protected void copyTextToClipboard(Object object) {
	final StringBuilder data = new StringBuilder();

	if (object instanceof IAbapGitObject) {
		data.append(((IAbapGitObject) object).getName());
	} else if (object instanceof IAbapGitFile) {
		data.append(((IAbapGitFile) object).getName());
	}

	final Clipboard clipboard = new Clipboard(Display.getDefault());
	clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
	clipboard.dispose();
}
 
Example 19
Source File: TreeClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void copy(Tree tree) {
	if (tree == null)
		return;
	StringBuilder text = new StringBuilder();
	int levels = getLevelCount(tree);
	copyHeaders(tree, levels, text);
	copyItems(tree, levels, text);
	Clipboard clipboard = new Clipboard(UI.shell().getDisplay());
	clipboard.setContents(new String[] { text.toString() },
			new Transfer[] { TextTransfer.getInstance() });
	clipboard.dispose();
}
 
Example 20
Source File: KillRing.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
public void setClipboardText(String text){
	Clipboard clipboard = new Clipboard(Display.getCurrent());
	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	clipboard.setContents(new Object[] {text},new Transfer[]{plainTextTransfer});
	clipboard.dispose();
}