I have a JTree and my own custom TreeModel implementation. I now want to add both Drag&Drop, as well as Copy, Cut & Paste support to my JTree.
I've read, that I need to implement my own TransferHandler because the JTree does not have its own TransferHandler implementation.

The problem is now, that my TreeModel is also a Set. No item in the model may be at 2 positions at the same time. So if I want to Move an item from one position to another I need to remove the item first and then insert it. I thought that would not be a problem, but apparently for Swing it is.

As far as I see it the TransferHandler will first call importData (for inserting the moved nodes) and only later call exportDone (for removing the moved nodes). This is, by definition of my model, illegal.
So I thought maybe I can hack it a little bit and remove the nodes in the importData method if the action is a move action. This works great for Drag&Drop, but does not work at all for Cut operations.

The problem is, when an object is Pasted (importData is called) I can not find out whether the object was cut or copied. On the other hand, in the exportDone method (called after importData) I can not find out whether the action is a Drag&Drop action or not.

I am really frustrated by this Design by now. I just can not see a good way to implement this without it looking like the ugliest hack.

Here is what I currently have for the TransferHandler: (I know, its huge)