[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Dropping Java objects as text

Thanks for the reply.  The reason I'm confused is that I don't know how to
reliably distinguish between the two cases in dragSetData.  I don't want to
create my own TransferData implementation (since that would require
learning native drag-and-drop implementation details on every target
platform) so my ByteArrayTransfer subclass acts just like ByteArrayTransfer
with respect to TransferData instances.  

I have no idea (and the documentation gives no hint) whether
TextTransfer.isSupportedType will reliably return false for the
TransferData offered by a ByteArrayTransfer -- and the code here is
platform-dependent.  Do native drag-and-drop implementations consider byte
arrays and strings to be completely incompatible?  I don't even know the
answer to that on my *own* preferred platform.  So I'd like to set the same
data regardless and let Eclipse pick the Transfer instance using whatever
native voodoo it uses for that....

I guess I should create my own TransferData class so I could rely on
isSupportedType to distinguish between the two cases, but writing
platform-specific code seems pretty onerous for a simple drag-and-drop
task.

-David

Duong Nguyen wrote:

> 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