[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.rcp] Re: LocalSelectionTransfer and clipboard
|
Hi,
Francis Upton schrieb:
Try this instead:
clipboard.setContents(new Object[] {new
StructuredSelection(selectedObject)},
new Transfer[] {LocalSelectionTransfer.getTransfer()});
The LocalSelectionTransfer expects to deal with an ISelection.
Then to get the contents, I use:
ISelection selection = LocalSelectionTransfer.getTransfer()
.getSelection();
I assume, that will not work this way. The point is that is, as I can
see, irrelevant what will be stored as Object in
clipboard.setContents(Object[], Transfer[]), because the implementation
of LocalSelectionTransfer.nativeToJava() Method, just returns the stored
selection. In my understanding the Transfer type is an identifier for
the implemation which transforms a byte[] from java to native and back.
Each Transfer implementation have a
- javaToNative(Object, TransferData data)
- nativeToJava(TransferData data)
method. The implementation of LocalSelectionTransfer.nativeToJava just
checks whether the transferData was created by an
LocalSelectionTransfer, but doesn't use any native bytes from the
clipboard. It returns the prior stored selection.
A little bit confusing, isn't it? :) I have the following code working:
in the copy Action:
copy() {
LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
// very important, store your selection
transfer.setSelection(new StructureSelection(getYourSelection())
// the object[] doesn't really matters
getClipboard().setContents(new Object[] {getYourSelection()}, new
Transfer[] {transfer});
}
in the paste Action():
paste() {
LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
// that returns the selection stored in copy()
IStructuredSelection selection =
(IStructuredSelection)getClipboard().getContents(transfer)
}
Hope this helps. Just have a look at the implementation of
LocalSelectionTransfer.
bye
Thomas
Kerri wrote:
Is it ok to use LocalSelectionTransfer with the
org.eclipse.swt.dnd.Clipboard? I'm having a problem getting contents
back from the clipboard so I wrote these 2 lines of code. In the
debugger I can see that the data is stored in the clipboard from the
first line but I can't get it back out.
I have these 2 lines of code and the second one returns null.
clipboard.setContents(new Object[] {selectedObject}, new
Transfer[] {LocalSelectionTransfer.getTransfer()});
Object lsObject = clipboard.getContents(
LocalSelectionTransfer.getTransfer());
Thanks for any advice!
Kerri