|
Re: Drag and drop not working [message #447712 is a reply to message #447710] |
Thu, 16 December 2004 15:25 |
hortiz Mising name Messages: 96 Registered: July 2009 |
Member |
|
|
I have found the problem, in the dragSetData method, I put an Integer in
the event.data instead of a String.
The right code is :
event.data = new Integer(composite.getBounds().y).toString();
hortiz wrote:
> Hi,
> Could you tell me why the code below does not work ? (I was very inspired
> by Snippet78...)
> In fact, event.data is always null in the drop method...
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.dnd.DND;
> import org.eclipse.swt.dnd.DragSource;
> import org.eclipse.swt.dnd.DragSourceEvent;
> import org.eclipse.swt.dnd.DragSourceListener;
> import org.eclipse.swt.dnd.DropTarget;
> import org.eclipse.swt.dnd.DropTargetAdapter;
> import org.eclipse.swt.dnd.DropTargetEvent;
> import org.eclipse.swt.dnd.TextTransfer;
> import org.eclipse.swt.dnd.Transfer;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> public class DNDTest {
> static Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
> static int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
> public static void main (String [] args) {
> Display display = Display.getDefault ();
> final Shell shell = new Shell (display);
> shell.setLayout(new GridLayout());
> Composite composite1 = new Composite(shell, SWT.BORDER);
> composite1.setLayoutData(new GridData());
> Composite composite2 = new Composite(shell, SWT.BORDER);
> composite2.setLayoutData(new GridData());
> setDragDrop(composite1);
> setDragDrop(composite2);
> DropTarget target = new DropTarget(shell, operations);
> target.setTransfer(types);
> target.addDropListener (new DropTargetAdapter() {
> public void drop(DropTargetEvent event) {
> System.out.println("DROP !!! " + event.data);
> }
> });
> shell.setSize (200, 200);
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> public static void setDragDrop (final Composite composite) {
> final DragSource source = new DragSource(composite, operations);
> source.setTransfer(types);
> source.addDragListener (new DragSourceListener () {
> public void dragStart(DragSourceEvent event) {
> event.doit = (composite.getBounds().y > 0);
> }
> public void dragSetData (DragSourceEvent event) {
> event.data = new Integer(composite.getBounds().y);
> System.out.println("DragSetData " + event.data);
> }
> public void dragFinished(DragSourceEvent event) {
> /* if (event.detail == DND.DROP_MOVE)
> label.setText ("");
> */
> }
> });
> }
> }
|
|
|
Powered by
FUDForum. Page generated in 0.02911 seconds