Clipboard issue in RAP environment [message #1857748] |
Thu, 23 February 2023 18:43  |
Eclipse User |
|
|
|
We are implementing a feature that copies text data to the clipboard using the setContents() method of the org.eclipse.swt.dnd.Clipboard class.
When connecting from a localhost PC, it works normally, but when connecting from a remote PC, the following error occurs and it does not work normally.
I want to know the reason.
org.eclipse.swt.SWTError: Cannot set data in clipboard
at org.eclipse.swt.dnd.DND.error(DND.java:263)
at org.eclipse.swt.dnd.DND.error(DND.java:219)
at org.eclipse.swt.dnd.Clipboard.setContents(Clipboard.java:272)
at kr.dazzle.ui.common.EnClipboard.setContents(EnClipboard.java:138)
at kr.dazzle.ui.common.EnClipboard.setContents(EnClipboard.java:124)
at kr.dazzle.ui.tree.actions.CopyCellAction$1.run(CopyCellAction.java:51)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:66)
at kr.dazzle.ui.tree.actions.CopyCellAction.run(CopyCellAction.java:46)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:493)
...
|
|
|
|
|
|
|
Re: Clipboard issue in RAP environment [message #1857947 is a reply to message #1857940] |
Tue, 07 March 2023 19:58   |
Eclipse User |
|
|
|
I wrote a sample program to reproduce this problem.
The mail template plugin of the RAP sample has been slightly modified and works as follows.

This is a simple sample that saves the entered sentence to the clipboard when you enter a sentence in the text field and click the "Copy" button.
If you test with the URL below on the device where the server is running, it works perfectly.
http://localhost:Port/mail
but,
If you test by accessing the URL below from another device, an error occurs.
http://IP:Port/mail
Am I just not sure how to use it properly?
I hope so. ^^
Here's the code that implements clipboard handling:
public class ViewComposite extends Composite {
private Text text;
/**
* Create the composite.
*
* @param parent
* @param style
*/
public ViewComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(3, false));
Label lblText = new Label(this, SWT.NONE);
lblText.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblText.setText("Text: ");
text = new Text(this, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Button btnCopy = new Button(this, SWT.NONE);
btnCopy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String str = text.getText();
System.out.println("Text:" + str);
Clipboard clipboard = new Clipboard(getDisplay());
clipboard.setContents(new Object[] { str }, new Transfer[] { TextTransfer.getInstance() });
}
});
btnCopy.setText("Copy");
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
Attachment: ClipboardTest.zip
(Size: 30.81KB, Downloaded 78 times)
Attachment: OK.png
(Size: 26.79KB, Downloaded 310 times)
[Updated on: Tue, 07 March 2023 20:03] by Moderator
|
|
|
|
Re: Clipboard issue in RAP environment [message #1857975 is a reply to message #1857970] |
Thu, 09 March 2023 01:13   |
Eclipse User |
|
|
|
Unfortunately, even though I corrected it as instructed, the problem remains.
public ViewComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(3, false));
Label lblText = new Label(this, SWT.NONE);
lblText.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblText.setText("Text: ");
text = new Text(this, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Button btnCopy = new Button(this, SWT.NONE);
btnCopy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String str = text.getText();
System.out.println("Text:" + str);
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { str }, new Transfer[] { TextTransfer.getInstance() });
clipboard.dispose();
}
});
btnCopy.setText("Copy");
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04408 seconds