[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: Thu, 16 Oct 2008 19:56:45 +0000 (UTC)
- Newsgroups: eclipse.platform.swt
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
isSupportedType is the only way (in platform-neutral code, don't know about
native stuff) of figuring out what kind of transfer the target is
Yes.
requesting. ByteArrayTransfer is abstract, but my ByteArrayTransfer
subclass doesn't override isSupportedType, and there's no point in doing so
unless I create my own TransferData subclass. So, for distinguishing
requested drop types, I'm stuck with ByteArrayTransfer's default behavior
unless I subclass TransferData. Am I right so far?
- You should subclass ByteArrayTransfer for your own custom (internal)
transfer type and call it something else -- let's call it MyCustomTransfer.
- You should not subclass TransferData.
- You should not implement your own isSupportedType. The default behaviour
is will work if you registered your custom transfer correctly. When you
register your transfer type (MyCustomTransfer), it will be given a unique
ID. This ID will be used to identify if the types are compatible. See
Snippet79 on how to create your own transfer type.
Having now written enough to clarify my thinking, I think my question is,
will TextTransfer.isSupportedType and ByteArrayTransfer.isSupportedType
ever return true for the same TransferData instance, or are they guaranteed
to be mutually exclusive on every platform? If they're mutually exclusive,
then I can use them to distinguish between the two cases (an internal drop
and an external drop.)
If you register your transfer type (MyCustomTransfer), it will have a
unique ID -- only your application will know it so it can be used safely
for an internal drop. This unique ID will be used by isSupportedType to
determine if the type and data are compatible during a drag and drop.
Otherwise I have to come up with some other
solution involving platform-specific code, such as implementing my own
TransferData subclass.
You will need to implement javaToNative and nativeToJava for your transfer
type (MyCustomTransfer) but they don't have to platform-specific if you
are only doing internal drop. They can as simple as:
Object myTransferObject;
protected void javaToNative (Object object, TransferData transferData) {
myTransferObject = object;
}
protected Object nativeToJava(TransferData transferData) {
return myTransferObject;
}
Again, thanks for the replies; this conversation is helping clarify my
thinking.
See Snippet79 and Snippet171 for examples on how to create your own
transfer type. See Snippet185 for an example on how to provide more than
one transfer type. See
http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html for
general DND questions. This article also mentions how you should use
isSupportedType.
Duong