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

The following examples show how to use org.eclipse.swt.dnd.Clipboard#getContents() . 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: SegmentViewer.java    From translationstudio8 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();
	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();
}
 
Example 3
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 4
Source File: StyledTextComp.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private boolean checkPaste() {
  try {
    Clipboard clipboard = new Clipboard( xParent.getDisplay() );
    TextTransfer transfer = TextTransfer.getInstance();
    String text = (String) clipboard.getContents( transfer );
    if ( text != null && text.length() > 0 ) {
      return true;
    } else {
      return false;
    }
  } catch ( Exception e ) {
    return false;
  }
}
 
Example 5
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 6
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 7
Source File: TextEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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 8
Source File: RenderClipboardAction.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
public void run(IAction action) {
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    String contents = (String) clipboard.getContents(TextTransfer.getInstance());
    if (contents != null) {
        view.setAutoSync(false);
        view.setContents(contents.getBytes(), new DOTGraphicalContentProvider());
    }
}
 
Example 9
Source File: DBrowser.java    From Rel with Apache License 2.0 5 votes vote down vote up
private static 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();	
	}
}
 
Example 10
Source File: StyledTextComp.java    From hop with Apache License 2.0 5 votes vote down vote up
private boolean checkPaste() {
  try {
    Clipboard clipboard = new Clipboard( xParent.getDisplay() );
    TextTransfer transfer = TextTransfer.getInstance();
    String text = (String) clipboard.getContents( transfer );
    if ( text != null && text.length() > 0 ) {
      return true;
    } else {
      return false;
    }
  } catch ( Exception e ) {
    return false;
  }
}
 
Example 11
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 12
Source File: PasteRemoteResourceAction.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(getShell().getDisplay());
       final ISVNRemoteResource resource = (ISVNRemoteResource)clipboard.getContents(RemoteResourceTransfer.getInstance());
       clipboard.dispose();

          RepositoryManager manager = SVNUIPlugin.getPlugin().getRepositoryManager();
          final String message = manager.promptForComment(getShell(), new IResource[]{});

          if (message == null)
              return; // canceled
          
          ISVNRemoteResource selectedResource = getSelectedRemoteResources()[0];
          final ISVNRemoteFolder destination = 
              (selectedResource.isFolder()?
                  (ISVNRemoteFolder)selectedResource:selectedResource.getParent());
          
          run(new IRunnableWithProgress() {
              public void run(IProgressMonitor monitor)throws  InvocationTargetException {
                  try {
                      SVNProviderPlugin.getPlugin().getRepositoryResourcesManager().
                          copyRemoteResource(resource,destination,message,monitor);
                  } catch (TeamException e) {
                      throw new InvocationTargetException(e);
                  }
              }
          }, true /* cancelable */, PROGRESS_BUSYCURSOR); //$NON-NLS-1$
  }
 
Example 13
Source File: ClipboardTester.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
	final Clipboard clipBoard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
	final FileTransfer transfer = FileTransfer.getInstance();
	final String[] selection = (String[]) clipBoard.getContents(transfer);
	return selection != null;
}
 
Example 14
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 15
Source File: Utils.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Gets a URL from the clipboard</p>
 * <p>The supported protocols currently are http, https and udp.</p>
 * @param display
 * @return first valid link from clipboard, else "http://"
 */
public static String getLinkFromClipboard(Display display ){
	final Clipboard cb = new Clipboard(display);
	final TextTransfer transfer = TextTransfer.getInstance();

	String data = (String) cb.getContents(transfer);

	String text = UrlUtils.parseTextForURL(data, false);
	if (text == null) {
		return( "http://" );
	}

	return text;
}
 
Example 16
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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();
		}
	}
}
 
Example 17
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;
}
 
Example 18
Source File: OpenTorrentWindow.java    From BiglyBT with GNU General Public License v2.0 3 votes vote down vote up
@Override
public void updateUI() {

	Clipboard clipboard = new Clipboard(Display.getDefault());

	String sClipText = (String) clipboard.getContents(TextTransfer.getInstance());
	
	if (sClipText != null){
		
		if ( lastCopiedFromClip != null && sClipText.equals( lastCopiedFromClip )){
			
			return;
		}
	
		boolean bTorrentInClipboard = addTorrentsFromTextList(sClipText, true) > 0;

		if ( btnPasteOrClear != null && !btnPasteOrClear.isDisposed()){
			
			btnPasteOrClear.setVisible(bTorrentInClipboard);
			
			if ( !btnPasteOrClearIsPaste ){
				
				Messages.setLanguageText(btnPasteOrClear, "OpenTorrentWindow.addFiles.Clipboard" );
				
				Utils.makeButtonsEqualWidth( Arrays.asList( btnBrowseTorrent, btnBrowseFolder, btnPasteOrClear ));
				
				btnPasteOrClear.getParent().layout( true );
				
				btnPasteOrClearIsPaste = true;
			}
		}
		
		if (bTorrentInClipboard) {
			Utils.setTT(btnPasteOrClear,sClipText);
		}
	}
	
	clipboard.dispose();
}