[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Dropping Java objects as text
|
- From: duongn@xxxxxxxxxx (Duong Nguyen)
- Date: Wed, 15 Oct 2008 19:21:31 +0000 (UTC)
- Newsgroups: eclipse.platform.swt
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
I'm a bit confused by your description but I'll try to answer this as best
I can. In your first paragraph you indicated that you're serializing your
object but in your second paragraph, you said that you reference the
object directly for internal drops.
I don't think your proposed solution is right. You don't need to subclass
TextTransfer to modify its behaviour. Doing so will prevent it from
working with applications that expect a normal TextTransfer.
You can specify multiple transfer types from the drag source. One of the
transfer type can be your internal transfer type as you have it now, and
the second transfer type can be a TextTransfer type. The TextTransfer type
may not have the complete data to reconstruct your actual object - it can
simply be the "toString" equivalent of your object.
Depending on whether the drop target wants the actual object or the string
description of the object, you will give him the right one in your
dragSetData method.
To see an example of providing multiple transfer types, see Snippet185:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet185.java?view=co
In your case, you would provide both the internal transfer type and the
TextTransfer from your DragSource but you would only accept the internal
transfer type from your DropTarget. The TextTransfer value would be for
external applications such as NotePad.
I hope that helps.
Duong
David Huebel wrote:
My application uses a TreeViewer to let users edit "bookmarks" and organize
them in folders. When users drag bookmarks and folders within the viewer,
they are transferred as serialized objects using a subclass of
ByteArrayTransfer. This has been implemented and is working fine. I want
to be able to drag these same items *out* of the application so an external
text representation can be dropped into other applications.
I'm a bit stuck at this point. The drop data can't be the external text
representation because it wouldn't be appropriate for internal drops.
Currently the drop data is a reference to the object itself, which works
fine for internal drops and seems like the right thing to do. However,
since the drop data isn't the external text representation, I can't use
TextTransfer directly.
The natural thing to do seems to be to subclass TextTransfer and override
javaToNative, but TextTransfer is designed to prevent subclassing -- it has
no public or protected constructors.
I think I need to subclass ByteArrayTransfer (or Transfer) and implement
getTypeNames() and getTypeIds() to return the same values as
TextTransfer.getTypeNames() and TextTransfer.getTypeIds(). Where do I get
these values? I would like to delegate to the TextTransfer
implementations, but they're protected. I don't see any API in the dnd
package that lets me retrieve the platform-specific names and IDs for
dropping text.
Am I going about this the right way? What am I missing? Any tips would be
much appreciated.
Thanks,
David