Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4378091

Please add DropTargetDragEvent.getTransferable() method

XMLWordPrintable

    • tiger
    • x86
    • windows_nt, windows_xp



      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)
      ======================================================================

            dassunw Das Das (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: