• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree Drag'n Drop ignoring canImport

 
Ron Alby
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really stuck on this and desperately need help.

I am programming Drag and Drop on a JTree using TransferHandler. One of the things my canImport method checks for is trying to drop a parent on a child (clearly a no-no). The method correctly checks for this condition and returns FALSE. The cursor shows the appropriate circle with a line thru it indicating you can't drop here.

However, if I go ahead and release the mouse anyways, for some reason it goes ahead and tries to make the transfer. It calls my exportDone method first (since that method doesn't know any better, it goes ahead and unhooks the node from the tree), and then calls my importData method. Since the node us already unhooked from the tree, I am now screwed.

What am I doing wrong? Why does the transfer ignore my canImport returning false and go ahead and try to transfer anyways?

Any help is greatly appreciated ... I am really screwed here.
 
Ron Alby
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK - found it.

When exportDone is called there is an 'action' parameter passed in ... and if canImport has returned FALSE then the action is 0 - meaning do nothing. Unfortunately, none of the examples I found on the net demonstrated this.

IMHO, it is rather silly to go thru the bother of a callback just to say "don't do anything" - and it also seems silly to call the method exportDone when there is no export, but I guess there are complexities at work that I don't understand.
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron Alby wrote:When exportDone is called there is an 'action' parameter passed in ... and if canImport has returned FALSE then the action is 0 - meaning do nothing. Unfortunately, none of the examples I found on the net demonstrated this.

Actually, the value is TransferHandler.NONE. Its value happens to be 0, but you should really compare to the constant, and the other constants TransferHandler.COPY, TransferHandler.MOVE, TransferHandler.COPY_OR_MOVE and TransferHandler.LINK.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic