Java Code Examples for org.eclipse.swt.dnd.DND#ERROR_CANNOT_SET_CLIPBOARD

The following examples show how to use org.eclipse.swt.dnd.DND#ERROR_CANNOT_SET_CLIPBOARD . 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: SinkView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public void run() {
    StringBuffer buf = new StringBuffer();
    addCalls(viewer.getTable().getSelection(), buf);
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    try {
        fClipboard.setContents(new String[]{convertLineTerminators(buf.toString())},
            new Transfer[]{plainTextTransfer});
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) throw e;
        if (MessageDialog
            .openQuestion(fView.getViewSite().getShell(),
                ("CopyCallHierarchyAction.problem"),
                ("CopyCallHierarchyAction.clipboard_busy"))) {
            run();
        }
    }
}
 
Example 2
Source File: LapseView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public void run() {
    StringBuffer buf= new StringBuffer();
    
    addCalls(fViewer.getTree().getSelection()[0], 0, buf);//we get the node selected in the tree

    TextTransfer plainTextTransfer = TextTransfer.getInstance();//for converting plain text in a String into Platform specific representation
    
    try{
        fClipboard.setContents(
            new String[]{ convertLineTerminators(buf.toString()) }, 
            new Transfer[]{ plainTextTransfer });
    }  catch (SWTError e){
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) 
            throw e;
        if (MessageDialog.openQuestion(fView.getViewSite().getShell(), 
                ("CopyCallHierarchyAction.problem"), ("CopyCallHierarchyAction.clipboard_busy"))
        ) 
        {
            run();
        }
    }
}
 
Example 3
Source File: SourceView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public void run() {
       StringBuffer buf = new StringBuffer();
       addCalls(viewer.getTable().getSelection(), buf);

	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	try{
		fClipboard.setContents(
			new String[]{ convertLineTerminators(buf.toString()) }, 
			new Transfer[]{ plainTextTransfer });
	}  catch (SWTError e){
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) 
			throw e;
		if (MessageDialog.openQuestion(fView.getViewSite().getShell(), 
				("CopyCallHierarchyAction.problem"), ("CopyCallHierarchyAction.clipboard_busy"))
		) 
		{
			run();
		}
	}
}
 
Example 4
Source File: CopyAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the clipboard contents. Prompt to retry if clipboard is busy.
 *
 * @param resources
 *            the resources to copy to the clipboard
 * @param fileNames
 *            file names of the resources to copy to the clipboard
 * @param names
 *            string representation of all names
 */
private void setClipboard(final IResource[] resources, final String[] fileNames, final String names) {
	try {
		// set the clipboard contents
		if (fileNames.length > 0) {
			clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] {
					ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
		} else {
			clipboard.setContents(new Object[] { resources, names },
					new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() });
		}
	} catch (final SWTError e) {
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; }
		if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO //$NON-NLS-1$
																			// ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,
				"Problem with copy.")) { //$NON-NLS-1$
			setClipboard(resources, fileNames, names);
		}
	}
}
 
Example 5
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 6
Source File: CopyCallHierarchyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	StringBuffer buf= new StringBuffer();
	addCalls(fViewer.getTree().getSelection()[0], 0, buf);

	TextTransfer plainTextTransfer= TextTransfer.getInstance();
	try {
		fClipboard.setContents(
				new String[] { convertLineTerminators(buf.toString()) },
				new Transfer[] { plainTextTransfer });
	} catch (SWTError e) {
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
			throw e;
		if (MessageDialog.openQuestion(fView.getViewSite().getShell(), CallHierarchyMessages.CopyCallHierarchyAction_problem, CallHierarchyMessages.CopyCallHierarchyAction_clipboard_busy))
			run();
	}
}
 
Example 7
Source File: LocationCopyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	IStructuredSelection selection= (IStructuredSelection) fLocationViewer.getSelection();
	StringBuffer buf= new StringBuffer();
	for (Iterator<?> iterator= selection.iterator(); iterator.hasNext();) {
		CallLocation location= (CallLocation) iterator.next();
		buf.append(location.getLineNumber()).append('\t').append(location.getCallText());
		buf.append('\n');
	}
	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	try {
		fClipboard.setContents(
				new String[]{ CopyCallHierarchyAction.convertLineTerminators(buf.toString()) },
				new Transfer[]{ plainTextTransfer });
	} catch (SWTError e){
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
			throw e;
		if (MessageDialog.openQuestion(fViewSite.getShell(), CallHierarchyMessages.CopyCallHierarchyAction_problem, CallHierarchyMessages.CopyCallHierarchyAction_clipboard_busy))
			run();
	}
}
 
Example 8
Source File: CopyAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Set the clipboard contents. Prompt to retry if clipboard is busy.
 * 
 * @param resources the resources to copy to the clipboard
 * @param fileNames file names of the resources to copy to the clipboard
 * @param names string representation of all names
 */
private void setClipboard(IResource[] resources, String[] fileNames, String names) {
    try {
        // set the clipboard contents
        if (fileNames.length > 0) {
            clipboard.setContents(
                    new Object[] { resources, fileNames, names },
                    new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(),
                            TextTransfer.getInstance() });
        } else {
            clipboard.setContents(new Object[] { resources, names },
                    new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() });
        }
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
            throw e;
        }
        if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
                "Problem with copy.")) { //$NON-NLS-1$
            setClipboard(resources, fileNames, names);
        }
    }
}
 
Example 9
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 10
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void copyToClipboard(ITextSelection selection, int repeatCount) {
	try{
		fClipboard.setContents(new String[] { selection.getText() }, new Transfer[] { TextTransfer.getInstance() });
	} catch (SWTError e) {
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD || repeatCount >= MAX_REPEAT_COUNT)
			throw e;

		if (MessageDialog.openQuestion(getShell(), InfoViewMessages.CopyToClipboard_error_title, InfoViewMessages.CopyToClipboard_error_message))
			copyToClipboard(selection, repeatCount + 1);
	}
}
 
Example 11
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void setClipboardContents(Clipboard clipboard, Object[] datas, Transfer[] transfers) {
	try {
		clipboard.setContents(datas, transfers);
	} catch (SWTError e) {
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
			throw e;
		}
		// silently fail.  see e.g. https://bugs.eclipse.org/bugs/show_bug.cgi?id=65975
	}
}
 
Example 12
Source File: CopyAction.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Set the clipboard contents. Prompt to retry if clipboard is busy.
  * 
  * @param resources the resources to copy to the clipboard
  * @param fileNames file names of the resources to copy to the clipboard
  * @param names string representation of all names
  */
 private void setClipboard(IResource[] resources, String[] fileNames,
         String names) {
     try {
         // set the clipboard contents
         if (fileNames.length > 0) {
             clipboard.setContents(new Object[] { resources, fileNames,
                     names },
                     new Transfer[] { ResourceTransfer.getInstance(),
                             FileTransfer.getInstance(),
                             TextTransfer.getInstance() });
         } else {
             clipboard.setContents(new Object[] { resources, names },
                     new Transfer[] { ResourceTransfer.getInstance(),
                             TextTransfer.getInstance() });
         }
     } catch (SWTError e) {
         if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
	throw e;
}
         if (MessageDialog
                 .openQuestion(
                         shell,
                         WorkbenchNavigatorMessages.actions_CopyAction_msgTitle, // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
                         WorkbenchNavigatorMessages.actions_CopyAction_msg)) { //$NON-NLS-1$
	setClipboard(resources, fileNames, names);
}
     }
 }
 
Example 13
Source File: CopyAction.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Set the clipboard contents. Prompt to retry if clipboard is busy.
  * 
  * @param resources the resources to copy to the clipboard
  * @param fileNames file names of the resources to copy to the clipboard
  * @param names string representation of all names
  */
 private void setClipboard(IResource[] resources, String[] fileNames,
         String names) {
     try {
         // set the clipboard contents
         if (fileNames.length > 0) {
             clipboard.setContents(new Object[] { resources, fileNames,
                     names },
                     new Transfer[] { ResourceTransfer.getInstance(),
                             FileTransfer.getInstance(),
                             TextTransfer.getInstance() });
         } else {
             clipboard.setContents(new Object[] { resources, names },
                     new Transfer[] { ResourceTransfer.getInstance(),
                             TextTransfer.getInstance() });
         }
     } catch (SWTError e) {
         if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
	throw e;
}
         if (MessageDialog
                 .openQuestion(
                         shell,
                         WorkbenchNavigatorMessages.actions_CopyAction_msgTitle, // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
                         WorkbenchNavigatorMessages.actions_CopyAction_msg)) { //$NON-NLS-1$
	setClipboard(resources, fileNames, names);
}
     }
 }