tags:

views:

161

answers:

0

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!