SWT Browser Drag and Drop

Posted by scottalas on Stack Overflow See other posts from Stack Overflow or by scottalas
Published on 2010-05-05T04:01:59Z Indexed on 2010/05/05 4:08 UTC
Read the original article Hit count: 195

Filed under:
|
|

I'm trying to use drag-n-drop with an embedded SWT Browser, so that my application can drag hyperlinks from the Browser to another Control. I've been able to set up the destination to receive data from an external browser, but the internal does not seem to participate in the drag-n-drop. Any ideas?

I would guess that I need something like a selection listener to track when something is grabbed in the browser, or some way to ask the browser what is currently selected, perhaps using javascript.

My current setup of the Browser is simplistic, looking like this:

    browser = new Browser(top, SWT.NONE); // MOZILLA
    createDragSource(browser); // below

    // a selection listener never receives events:
    browser.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event)
        {
           System.out.println("Selection listener event");
        }
     });

 ...

private void createDragSource(final Browser browser) {

   Transfer[] types = new Transfer[] { 
         URLTransfer.getInstance(),
         HTMLTransfer.getInstance(),
         TextTransfer.getInstance(),
         ImageTransfer.getInstance(),
   };

       int mode =  DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE;
  DragSource dragSource = new DragSource(browser, mode);
  dragSource.setTransfer(types);
  dragSource.addDragListener(new DragSourceListener() {

    public void dragStart(DragSourceEvent event) {
       System.out.println("source.dragStart");
    }

    public void dragSetData(DragSourceEvent event) {
       System.out.println("source.dragSetData");
            // Is there a way to get the Browser's drag item here?
    }

    public void dragFinished(DragSourceEvent event) {
       System.out.println("source.dragFinished");
      //do nothing
    }
  });
}

Thanks for any help!

© Stack Overflow or respective owner

Related posts about swt

Related posts about browser