Custom Transfer type for drag and drop? (SWT)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JHuman
    New Member
    • Feb 2009
    • 5

    Custom Transfer type for drag and drop? (SWT)

    Hi there,
    At the moment I'm making an application where I drag an item in a List to a Canvas (all in SWT). However, I don't wish to use TextTransfer or ByteArrayTransf er for the drag and drop data transfer. I want to transfer a class defined by me (lets just call it myCustomObj). I've tried subclassing Transfer but I don't have a clue what to put inside Transfer's methods, particularly isSupportedType () and nativeToJava(). Can anyone help me out (perhaps there's a better way than subclassing Transfer)?

    PS: I found an article that kind of looks at what I'm asking here, but that example subclasses ByteArrayTransf er, which I don't think is what I need. I want to transfer an object, not bytes.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    The sender can serialize(look in wikipedia about serialisation) the object (= convert your object into a ByteArray). Then the receiver can convert the ByteArray back into an object.

    You can't send an object (pointer to its memory location) directly over, because that cut-and-paste must work between all different types of programs (basic, c++, java, ...). So what do you think how could a basic-program handle a java object? The internal structure is completely different! So the best way is not to serialize it to a ByteArray, but to XML.

    Comment

    Working...