0
votes

I want to drag & drop nodes in a TreeViewer to reorder them. The nodes in my tree wrap an IJavaElement or an IFile. My problem is that none of my attempts to place these node-values in the drag-event are accessible once the drop event is executed (=null). Apparently, I got something wrong with this TransferHandles you have to use or create.

   @Override
    public void dragSetData(DragSourceEvent event) {     
        IStructuredSelection selections = treeViewer.getSelections();
        IBookmark dragNode = (IBookmark) selections.getFirstElement();

        //There is only 1 transfer handle as return
        event.dataType = FileTransfer.getInstance().getSupportedTypes()[0];
        event.data = dragNode.getValue();//<-- Returns my IFile

It should work this way, but nothing reaches my drop listener. Does anyone know what I am doing wrong?

Edit:

Is there a way to place the current instance of the object that is dragged into the drag-event? I am only working within Eclipse in my own view for this operation. And I am actually more interested in the instance of the object that is dropped than just the value of the node.

1

1 Answers

0
votes

It's not clear from your code why you get null in your drop event (in case of incompatible transfer types, you wouldn't get to drop at all). However, setting dataType in dragSetData() has no effect. Transfer types should be configured using addDragSupport and addDropSupport of StructuredViewer.

Is there a way to place the current instance of the object that is dragged into the drag-event?

You can use LocalSelectionTransfer as explained here.