[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: SWT vs SWING/AWT Drag and drop

This is a great example!  Thank you Duong.

Now, I would like to extend this question: 

Let's say that I have a custom Transferable being dragged from a
Swing component.  The Transferable looks like:

================================================================

public class CustomTransferable implements Transferable {

    protected static DataFlavor customFlavor = new DataFlavor
(CustomClass.class,
        "A Custom Object");

    protected static DataFlavor[] _supportedFlavors = { customFlavor };
    private CustomObject _node;

    public ProjectNodeTransferable(CustomObject node) {
        this._node = node;
    }

    public synchronized Object getTransferData(DataFlavor flavor)
            throws UnsupportedFlavorException, IOException {
        if (flavor.equals(customFlavor))  //How can SWT thread ask?
            return _node;
        else
            throw new UnsupportedFlavorException(flavor);
    }

    public synchronized DataFlavor[] getTransferDataFlavors() {
        return _supportedFlavors;
    }

    public boolean isDataFlavorSupported(DataFlavor flavor) {
        if (flavor.equals(nodeFlavor))
            return true;
        return false;
    }
================================================================

Now, my DragGestureListener starts starts a drag via s DragGestureEvent 
and includes an instance of my above Transferable.

My question is... how can my SWT DropTarget be aware of this Transfer 
type?  I am not even sure what I need to create for my Transfer Types in 
my drop target :

================================================================
        final DropTarget dropTarget = new DropTarget(chartComposite, 
DND.DROP_COPY | DND.DROP_DEFAULT);
        Transfer[] types = new Transfer[] { /* What Transfer is 
compatible with CustomTransferable.getTransferData() ?? */ };
        dropTarget.setTransfer(types);
================================================================

 SWT is running in a different thread than my Swing component, but all 
in the same JVM.  Does that mean I need to serialize the transfer, and 
include a subclass of ByteArrayTransfer to do this?

This seems like a reasonable thing to do, since I can declaritively 
exchange objects between SWT and AWT controls with SWT_AWT.  However, 
when I involve the Drag and Drop framework; the complication grows.  

I am not concerned with sharing this information external to my 
application.  It is simply to move around specific entities between 
Swing and SWT containers.

Thanks,
Sheldon W


duongn@xxxxxxxxxx (Duong Nguyen) wrote in
news:150d2f1a386db2503b63da1b87abc1d1$1@xxxxxxxxxxxxxxx: 

> You would write DND for your treeViewer using the SWT API and write
> the Swing DND API for your Swing component. You just have to make sure
> that your transfer types between the two are compatible.
> 
> Here's a simple text DND between Swing and SWT:
> package swt.examples.dnd;
>  
> /*
>  * example snippet: DND between Swing/AWT and SWT
>  */
> import javax.swing.*;
> ...
> }
> 
> 
> Chandra wrote:
> 
>> Hi All,
> 
>>   I have a swing based component in editor and I need to implement a 
>> Drag-Drop (DND) feature between SWT based treeviewer and Swing based 
>> component. Please guide me for the above. At least send me the sample
>> for these kind of scenario.
> 
>> Thanks,
>> Chandra M
> 
>