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

The following examples show how to use org.eclipse.swt.dnd.Clipboard#dispose() . 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: CellEditorTextViewer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
 */
private void copy() {
	super.doOperation(ITextOperationTarget.COPY);
	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	HSTextTransfer hsTextTransfer = HSTextTransfer.getInstance();
	Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
	String plainText = (String) clipboard.getContents(plainTextTransfer);
	if (plainText == null || plainText.length() == 0) {
		return;
	}
	plainText = plainText.replaceAll(System.getProperty("line.separator"), "\n");
	plainText = plainText.replaceAll(TmxEditorConstanst.LINE_SEPARATOR_CHARACTER + "", "");
	plainText = plainText.replaceAll(TmxEditorConstanst.TAB_CHARACTER + "", "\t");
	plainText = plainText.replaceAll(TmxEditorConstanst.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);
	clipboard.dispose();
}
 
Example 2
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 3
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 4
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void doPasteWithImportsOperation() {
	ITextEditor editor= getTextEditor();
	IJavaElement inputElement= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());

	Clipboard clipboard= new Clipboard(getDisplay());
	try {
		ClipboardData importsData= (ClipboardData)clipboard.getContents(fgTransferInstance);
		if (importsData != null && inputElement instanceof ICompilationUnit && !importsData.isFromSame(inputElement)) {
			// combine operation and adding of imports
			IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
			if (target != null) {
				target.beginCompoundChange();
			}
			try {
				fOperationTarget.doOperation(fOperationCode);
				addImports((ICompilationUnit)inputElement, importsData);
			} catch (CoreException e) {
				JavaPlugin.log(e);
			} finally {
				if (target != null) {
					target.endCompoundChange();
				}
			}
		} else {
			fOperationTarget.doOperation(fOperationCode);
		}
	} finally {
		clipboard.dispose();
	}
}
 
Example 5
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(ITextSelection selection) {
	fClipboard= new Clipboard(getShell().getDisplay());
	try {
		copyToClipboard(selection, 0);
	} finally {
		fClipboard.dispose();
	}
}
 
Example 6
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void doRun(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarEntryResources) throws CoreException {
	ClipboardCopier copier= new ClipboardCopier(resources, javaElements, jarEntryResources, getShell(), fAutoRepeatOnFailure);

	if (fClipboard != null) {
		copier.copyToClipboard(fClipboard);
	} else {
		Clipboard clipboard= new Clipboard(getShell().getDisplay());
		try {
			copier.copyToClipboard(clipboard);
		} finally {
			clipboard.dispose();
		}
	}
}
 
Example 7
Source File: PasteRemoteResourceAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isEnabled() {
       if (getSelectedRemoteResources().length != 1)
           return false;
       
       boolean result;
       Clipboard clipboard = new Clipboard(getShell().getDisplay());
       result = clipboard.getContents(RemoteResourceTransfer.getInstance()) != null;
       clipboard.dispose();
	return result;
}
 
Example 8
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void paste(Table table, Consumer<String> fn) {
	if (table == null || fn == null)
		return;
	Clipboard clipboard = new Clipboard(UI.shell().getDisplay());
	try {
		TextTransfer transfer = TextTransfer.getInstance();
		Object content = clipboard.getContents(transfer);
		if (!(content instanceof String))
			return;
		fn.accept((String) content);
	} finally {
		clipboard.dispose();
	}
}
 
Example 9
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 10
Source File: KillRing.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the text from the system clipboard
 * 
 * @return the system clipboard content as a String
 */
public String getClipboardText() {
	Clipboard clipboard = new Clipboard(Display.getCurrent());
	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	String cliptxt = (String)clipboard.getContents(plainTextTransfer, DND.CLIPBOARD);
	clipboard.dispose();
	return cliptxt;
}
 
Example 11
Source File: Clipboards.java    From offspring with MIT License 5 votes vote down vote up
public static void copy(Display display, String contents) {
  Clipboard clipboard = new Clipboard(display);
  TextTransfer textTransfer = TextTransfer.getInstance();
  clipboard.setContents(new String[] {
      contents
  }, new Transfer[] {
    textTransfer
  });
  clipboard.dispose();
}
 
Example 12
Source File: VM99Clipboard.java    From ldparteditor with MIT License 5 votes vote down vote up
public String getClipboardText() {
    final String result;
    Display display = Display.getCurrent();
    Clipboard clipboard = new Clipboard(display);
    result = (String) clipboard.getContents(TextTransfer.getInstance());
    clipboard.dispose();
    return result == null ? "" : result; //$NON-NLS-1$
}
 
Example 13
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 14
Source File: RemoteProfilesPreferencePage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void setClipboardContents(IStructuredSelection data) {
    LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
    transfer.setSelection(data);
    Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
    clipboard.setContents(new Object[] { new Object() }, new Transfer[] { transfer });
    clipboard.dispose();
}
 
Example 15
Source File: ExportWizardPage.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void copyToClipboard(String toolTip) {
    Object[] data = new Object[] { toolTip };
    Transfer[] transfer = new Transfer[] { TextTransfer.getInstance() };
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    clipboard.setContents(data, transfer);
    clipboard.dispose();
}
 
Example 16
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 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: AbapGitDialogObjLog.java    From ADT_Frontend with MIT License 5 votes vote down vote up
/**
 * Copies the current selection to the clipboard.
 *
 * @param table
 *            the data source
 */
protected void copy() {
	Object firstElement = AbapGitDialogObjLog.this.tree.getViewer().getStructuredSelection().getFirstElement();
	final StringBuilder data = new StringBuilder();

	IAbapObject selectedAbapObj = (IAbapObject) firstElement;
	data.append(selectedAbapObj.getName() + " | " + selectedAbapObj.getType() + " | " + selectedAbapObj.getMsgType() + " | " //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
			+ selectedAbapObj.getMsgText());

	final Clipboard clipboard = new Clipboard(AbapGitDialogObjLog.this.tree.getViewer().getControl().getDisplay());
	clipboard.setContents(new String[] { data.toString() }, new TextTransfer[] { TextTransfer.getInstance() });
	clipboard.dispose();
}
 
Example 19
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 20
Source File: RemoteProfilesPreferencePage.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private static IStructuredSelection getClipboardContents() {
    Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
    IStructuredSelection data = (IStructuredSelection) clipboard.getContents(LocalSelectionTransfer.getTransfer());
    clipboard.dispose();
    return data;
}