JDK-4378091 : Please add DropTargetDragEvent.getTransferable() method
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0,1.4.1,1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_xp
  • CPU: x86
  • Submitted: 2000-10-10
  • Updated: 2017-05-16
  • Resolved: 2003-08-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description

Name: rmT116609			Date: 10/10/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

I've written a JTree that supports drag&drop. I implemented the
DropTargetListener.dragOver(DropTargetDragEvent) that it selects the current
node that the dragging node moves over. Now, I want to check if this
current/selected node is a valid drop target (node). For this reason, I need to
get the current transferable to check wether source and target nodes
are "compatible". For this reason I did a DropTargetDragEvent.getTransferable()
(just like DropTargetDropEvent.getTransferable()) but this method is not
available in DropTargetDragEvent! Playing with different DataFlavors is not
enough, there are objects of the same flavour but with different properties.
And the dropping sequence is dependend on this properties, so I need to have
the transferable to check for additional values.

Can we expect to have DropTargetDragEvent.getTransferable() in the next SDK or
is there another solution for this problem?

when I implemented the DropTargetListener, I came to dragOver(). In this
method I want to check if the dragged node is allowed to be dropped on the
current "under" node. SO, just like I did in with a DropTargetDropEvent, I
called "getTransferable()" to inspect the nodes and do further checking. But
the compiler said that getTransferable() is not availabe in
DropTargetDragEvent!

But I need this to check whether the node is "compatible" with the to be
dropped on node. (Application logic: only specific nodes (with specific
properties) are allowed to be dropped - even of the same falvour!).

Here's the code with the not working (but needed) part in comments:

--------------------------------------
    /**
     * Implements DropTargetListener.
     * Called when a drag operation is ongoing on the DropTarget.
     */
    public void dragOver(DropTargetDragEvent event) {
//System.out.println("DropTargetListener.dragOver() ...");
        Point mouseLoc = event.getLocation();
        TreePath path = this.getPathForLocation(mouseLoc.x, mouseLoc.y);
        if (path != null) {
            VegasNode selectedTarget = (VegasNode)
path.getLastPathComponent();
            selectNode(selectedTarget);

//unfortunately, the following method does not exist: !!!
//            Transferable tr = event.getTransferable();
//            if (tr.isDataFlavorSupported(VegasNode.NODE_FLAVOR)) { //is
this a VegasNode?
//                VegasNode dragNode = (VegasNode)
tr.getTransferData(VegasNode.NODE_FLAVOR);
//                Utils.debug("check here for valid drop sequence:
dragNode="+dragNode+", dropNode="+selectedTarget);
//                //todo: check type of both VegasNodes if they are
compatibe ...
//            }
        }
    }//dragOver()
(Review ID: 107743) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b15
2004-06-14

WORK AROUND Name: rmT116609 Date: 10/10/2000 Save the transferable node/object in a global field so that it is accessible in all other drag&drop interface methods. :-( ======================================================================
2004-06-11

EVALUATION Will consider for tiger. david.mendenhall@east 2001-03-19 Name: dsR10078 Date: 12/03/2003 A new method java.awt.dnd.DropTargetDragEvent.getTransferable() added in 1.5: /** * This method returns the Transferable object that represents * the data associated with the current drag operation. * * @return the Transferable associated with the drag operation * @throws InvalidDnDOperationException if the data associated with the drag * operation is not available * * @since 1.5 */ public Transferable getTransferable(); ###@###.### 2003-12-03 ======================================================================
2003-12-03