File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTree Drag'n Drop ignoring canImport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree Drag Watch "JTree Drag New topic
Author

JTree Drag'n Drop ignoring canImport

Ron Alby
Greenhorn

Joined: May 31, 2011
Posts: 24
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

Joined: May 31, 2011
Posts: 24
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree Drag'n Drop ignoring canImport
 
Similar Threads
JTree reload question, AGAIN
JTree problem
JTree, adding and removing nodes contained in a master tree
JTree
Need help on JTree