Drag and Drop, Copy and Paste

View: New views
1 Messages — Rating Filter:   Alert me  

Drag and Drop, Copy and Paste

by Carsten Schmalhorst :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all!

I am currently working on the palette tutorials from the "RCP-Plugging..." book and experience some problems. Drag and drop from the palette using a TopCompontent as drop target works well. But I want to drag a DataNode from the palette to a DataNode in an ExplorerView. This works well with copy & paste, the documentation tells me it should work with drag and drop as well. But it does not. My DataNode source contains little more than the clipboardCopy() implementation:

[...]
  @Override
  public Transferable clipboardCopy() throws IOException
  {
    Transferable defaultT = super.clipboardCopy();
    ExTransferable added = ExTransferable.create(defaultT);
    added.put(new TransferableImpl(this));
    return added;
  }
 
  private static class TransferableImpl extends ExTransferable.Single
  {
    BladeManipDataNode _node;
    TransferableImpl(BladeManipDataNode node)
    {
      super(BladesurfaceManipulator.DATAFLAVOR);
      _node = node;
    }

    @Override
    protected Object getData() throws IOException, UnsupportedFlavorException
    {
      return _node.getLookup().lookup(BladesurfaceManipulator.class);
    }
  }
[...]

My drop target implements both createPasteTypes and getDropType

[...]
  @Override
  public PasteType getDropType(final Transferable transferable, int dropAction, final int dropIndex)
  {
    return new PasteType()
    {

      public Transferable paste() throws IOException
      {
        System.out.println("drop");
        return null;
      }
    };
  }
   
  @Override
  protected void createPasteTypes(Transferable t, List s)
  {
    final Transferable tt = t;
    if(t.isDataFlavorSupported(BladesurfaceManipulator.DATAFLAVOR)) {
      PasteType ptyp = new PasteType()
      {
        public Transferable paste() throws IOException
        {
          try {
            BladesurfaceManipulator bsmanip = (BladesurfaceManipulator) tt.getTransferData(
                    BladesurfaceManipulator.DATAFLAVOR);
            _blade.addBladesurfaceManipulator(bsmanip);
          }
          catch(UnsupportedFlavorException ex) {
            Exceptions.printStackTrace(ex);
          }
          return null;
        }
      };
      s.add(ptyp);
    }
    super.createPasteTypes(t, s);
  }
[...]

Even with the dummy implementation of getDropType() nothing happens when I drag a node from the palette over the target node. The cursor just says dropping is forbidden. And yes, I explicitly tell my BeanTreeView to accept drop events. I can drop any other node - even from my desktop - on the target node and the output is printed correctly. Providing a DragAndDropHandler for the Palette didn't help either. Drag action is called.

What am I missing?

Cheers,

Carsten