Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Why the drop method never been called?
Why the drop method never been called? [message #447855] Mon, 20 December 2004 06:10 Go to next message
Eclipse UserFriend
Originally posted by: wudong.At.sklse.org

HI, All:
I want to drap and drop inside a tableViewer. Drag one tableitem and drop to another. I use the tableViewer's addDragSourceListener() and addDropTargetListener() to add DnD listener to toe talbeViewer.
the DragSourceListener work well, but it's very stange that the DropTargetListener's drop method is never been called.
only the dropOver, and dropEnter are call when I performed a Drag and Drop operation.

What the problem will it be?


============== Code =============
/*
* Created on 2004-12-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.swt.snippets;


import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

/**
* @author Wudong
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class cd extends Composite {
final TableViewer tableViewer;
class ContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
return new Object[] { "item_0", "item_1", "item_2" };
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
public cd(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout());

tableViewer = new TableViewer(this, SWT.BORDER);
tableViewer.setContentProvider(new ContentProvider());
final Table table = tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);

final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(100);
tableColumn.setText("New column");

final TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
tableColumn_1.setWidth(100);
tableColumn_1.setText("New column");
tableViewer.setInput(new Object());
//
Transfer[] transferarray = new Transfer[]{TextTransfer.getInstance()};
tableViewer.addDragSupport(DND.DROP_COPY, transferarray, new DragLS());
tableViewer.addDropSupport(DND.DROP_COPY, transferarray, new DropLS());
}

public void dispose() {
super.dispose();
}

protected void checkSubclass() {
}

static Display display;
static Shell shell;
public static void main(String[] args) {
display = Display.getDefault();
shell = new Shell(display);
shell.setLayout(new FillLayout());
new cd(shell, SWT.NONE);

shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

class DropLS implements DropTargetListener{
TableItem olditem=null;
public void drop(DropTargetEvent event) {
TableItem item = (TableItem)event.item;

System.out.println("Droped");
}


public void dragOver(DropTargetEvent event) {
TableItem item = (TableItem)event.item;

if (item!=null && !item.equals(olditem)){
System.out.println("Drop Over: "+item.getText());
olditem = item;
event.feedback = DND.FEEDBACK_SELECT;
}

}


/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse .swt.dnd.DropTargetEvent)
*/
public void dragEnter(DropTargetEvent arg0) {
TableItem item = (TableItem)arg0.item;
if (item!=null)
System.out.println("Drop Enter:"+item.getText());

}


/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse .swt.dnd.DropTargetEvent)
*/
public void dragLeave(DropTargetEvent arg0) {
TableItem item = (TableItem)arg0.item;
if (item!=null)
System.out.println("Drop Leave: "+item.getText());
}


/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged( org.eclipse.swt.dnd.DropTargetEvent)
*/
public void dragOperationChanged(DropTargetEvent arg0) {

}


/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DropTargetListener#dropAccept(org.eclips e.swt.dnd.DropTargetEvent)
*/
public void dropAccept(DropTargetEvent arg0) {
TableItem item = (TableItem)arg0.item;
if (item!=null)
System.out.println("Drop Accept: "+item.getText());
}
}

class DragLS extends DragSourceAdapter{
Object dragSource = null;
public void dragStart(DragSourceEvent event) {
IStructuredSelection selection = (IStructuredSelection)tableViewer.getSelection();
if (selection!=null && !selection.isEmpty()) {
event.doit = true;
dragSource = selection.getFirstElement();
} else {
event.doit = false;
}
};

public void dragSetData(DragSourceEvent event) {
event.data = dragSource.toString();
}

public void dragFinished(DragSourceEvent event) {
System.out.println("Drag Object: "+dragSource.toString()+" Finished");
}
}
}
Re: Why the drop method never been called? [message #447863 is a reply to message #447855] Mon, 20 December 2004 13:35 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
You have only specified DND.DROP_COPY as the operation. In order to do a
copy, on Windows you must hold down the Ctrl key while dragging. You can
make also DND.DROP_COPY be the default operation (default, means no keys
need to be pressed) for the DropTarget by using DND.DROP_DEFAULT:

See:




"wudong" <wudong@At.sklse.org> wrote in message
news:cq5qc8$5le$1@www.eclipse.org...
> HI, All:
> I want to drap and drop inside a tableViewer. Drag one tableitem and drop
> to another. I use the tableViewer's addDragSourceListener() and
> addDropTargetListener() to add DnD listener to toe talbeViewer.
> the DragSourceListener work well, but it's very stange that the
> DropTargetListener's drop method is never been called.
> only the dropOver, and dropEnter are call when I performed a Drag and Drop
> operation.
>
> What the problem will it be?
>
>
> ============== Code =============
> /*
> * Created on 2004-12-20
> *
> * TODO To change the template for this generated file go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
> package org.eclipse.swt.snippets;
>
>
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.SWT;
> import org.eclipse.jface.viewers.TableViewer;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.TableColumn;
> import org.eclipse.swt.widgets.TreeItem;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.IStructuredSelection;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.swt.dnd.*;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableItem;
>
> /**
> * @author Wudong
> *
> * TODO To change the template for this generated type comment go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
> public class cd extends Composite {
> final TableViewer tableViewer;
> class ContentProvider implements IStructuredContentProvider {
> public Object[] getElements(Object inputElement) {
> return new Object[] { "item_0", "item_1", "item_2" };
> }
> public void dispose() {
> }
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
> }
> public cd(Composite parent, int style) {
> super(parent, style);
> setLayout(new FillLayout());
>
> tableViewer = new TableViewer(this, SWT.BORDER);
> tableViewer.setContentProvider(new ContentProvider());
> final Table table = tableViewer.getTable();
> table.setLinesVisible(true);
> table.setHeaderVisible(true);
>
> final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
> tableColumn.setWidth(100);
> tableColumn.setText("New column");
>
> final TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
> tableColumn_1.setWidth(100);
> tableColumn_1.setText("New column");
> tableViewer.setInput(new Object());
> //
> Transfer[] transferarray = new
> Transfer[]{TextTransfer.getInstance()};
> tableViewer.addDragSupport(DND.DROP_COPY, transferarray, new
> DragLS());
> tableViewer.addDropSupport(DND.DROP_COPY, transferarray, new
> DropLS());
> }
>
> public void dispose() {
> super.dispose();
> }
>
> protected void checkSubclass() {
> }
>
> static Display display;
> static Shell shell;
> public static void main(String[] args) {
> display = Display.getDefault();
> shell = new Shell(display);
> shell.setLayout(new FillLayout());
> new cd(shell, SWT.NONE);
>
> shell.setSize(400, 400);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> class DropLS implements DropTargetListener{
> TableItem olditem=null;
> public void drop(DropTargetEvent event) {
> TableItem item = (TableItem)event.item;
>
> System.out.println("Droped");
> }
>
>
> public void dragOver(DropTargetEvent event) {
> TableItem item = (TableItem)event.item;
>
> if (item!=null && !item.equals(olditem)){
> System.out.println("Drop Over: "+item.getText());
> olditem = item;
> event.feedback = DND.FEEDBACK_SELECT;
> }
>
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse .swt.dnd.DropTargetEvent)
> */
> public void dragEnter(DropTargetEvent arg0) {
> TableItem item = (TableItem)arg0.item;
> if (item!=null)
> System.out.println("Drop Enter:"+item.getText());
>
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse .swt.dnd.DropTargetEvent)
> */
> public void dragLeave(DropTargetEvent arg0) {
> TableItem item = (TableItem)arg0.item;
> if (item!=null)
> System.out.println("Drop Leave: "+item.getText());
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged( org.eclipse.swt.dnd.DropTargetEvent)
> */
> public void dragOperationChanged(DropTargetEvent arg0) {
>
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.swt.dnd.DropTargetListener#dropAccept(org.eclips e.swt.dnd.DropTargetEvent)
> */
> public void dropAccept(DropTargetEvent arg0) {
> TableItem item = (TableItem)arg0.item;
> if (item!=null)
> System.out.println("Drop Accept: "+item.getText());
> }
> }
>
> class DragLS extends DragSourceAdapter{
> Object dragSource = null;
> public void dragStart(DragSourceEvent event) {
> IStructuredSelection selection =
> (IStructuredSelection)tableViewer.getSelection();
> if (selection!=null && !selection.isEmpty()) {
> event.doit = true;
> dragSource = selection.getFirstElement();
> } else {
> event.doit = false;
> }
> };
>
> public void dragSetData(DragSourceEvent event) {
> event.data = dragSource.toString();
> }
>
> public void dragFinished(DragSourceEvent event) {
> System.out.println("Drag Object: "+dragSource.toString()+"
> Finished");
> }
> }
> }
>
Re: Why the drop method never been called? [message #447864 is a reply to message #447863] Mon, 20 December 2004 13:36 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Sorry, for an example of using DND.DROP_DEFAULT, see:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet84.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup


"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:cq6kf9$qv0$1@www.eclipse.org...
> You have only specified DND.DROP_COPY as the operation. In order to do a
> copy, on Windows you must hold down the Ctrl key while dragging. You can
> make also DND.DROP_COPY be the default operation (default, means no keys
> need to be pressed) for the DropTarget by using DND.DROP_DEFAULT:
>
> See:
>
>
>
>
> "wudong" <wudong@At.sklse.org> wrote in message
> news:cq5qc8$5le$1@www.eclipse.org...
>> HI, All:
>> I want to drap and drop inside a tableViewer. Drag one tableitem and drop
>> to another. I use the tableViewer's addDragSourceListener() and
>> addDropTargetListener() to add DnD listener to toe talbeViewer.
>> the DragSourceListener work well, but it's very stange that the
>> DropTargetListener's drop method is never been called.
>> only the dropOver, and dropEnter are call when I performed a Drag and
>> Drop operation.
>>
>> What the problem will it be?
>>
>>
>> ============== Code =============
>> /*
>> * Created on 2004-12-20
>> *
>> * TODO To change the template for this generated file go to
>> * Window - Preferences - Java - Code Style - Code Templates
>> */
>> package org.eclipse.swt.snippets;
>>
>>
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.jface.viewers.TableViewer;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>> import org.eclipse.swt.widgets.TableColumn;
>> import org.eclipse.swt.widgets.TreeItem;
>> import org.eclipse.swt.layout.FillLayout;
>> import org.eclipse.jface.viewers.ISelection;
>> import org.eclipse.jface.viewers.IStructuredSelection;
>> import org.eclipse.jface.viewers.Viewer;
>> import org.eclipse.jface.viewers.IStructuredContentProvider;
>> import org.eclipse.swt.dnd.*;
>> import org.eclipse.swt.graphics.Point;
>> import org.eclipse.swt.graphics.Rectangle;
>> import org.eclipse.swt.widgets.Table;
>> import org.eclipse.swt.widgets.TableItem;
>>
>> /**
>> * @author Wudong
>> *
>> * TODO To change the template for this generated type comment go to
>> * Window - Preferences - Java - Code Style - Code Templates
>> */
>> public class cd extends Composite {
>> final TableViewer tableViewer;
>> class ContentProvider implements IStructuredContentProvider {
>> public Object[] getElements(Object inputElement) {
>> return new Object[] { "item_0", "item_1", "item_2" };
>> }
>> public void dispose() {
>> }
>> public void inputChanged(Viewer viewer, Object oldInput, Object
>> newInput) {
>> }
>> }
>> public cd(Composite parent, int style) {
>> super(parent, style);
>> setLayout(new FillLayout());
>>
>> tableViewer = new TableViewer(this, SWT.BORDER);
>> tableViewer.setContentProvider(new ContentProvider());
>> final Table table = tableViewer.getTable();
>> table.setLinesVisible(true);
>> table.setHeaderVisible(true);
>>
>> final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
>> tableColumn.setWidth(100);
>> tableColumn.setText("New column");
>>
>> final TableColumn tableColumn_1 = new TableColumn(table,
>> SWT.NONE);
>> tableColumn_1.setWidth(100);
>> tableColumn_1.setText("New column");
>> tableViewer.setInput(new Object());
>> //
>> Transfer[] transferarray = new
>> Transfer[]{TextTransfer.getInstance()};
>> tableViewer.addDragSupport(DND.DROP_COPY, transferarray, new
>> DragLS());
>> tableViewer.addDropSupport(DND.DROP_COPY, transferarray, new
>> DropLS());
>> }
>>
>> public void dispose() {
>> super.dispose();
>> }
>>
>> protected void checkSubclass() {
>> }
>>
>> static Display display;
>> static Shell shell;
>> public static void main(String[] args) {
>> display = Display.getDefault();
>> shell = new Shell(display);
>> shell.setLayout(new FillLayout());
>> new cd(shell, SWT.NONE);
>>
>> shell.setSize(400, 400);
>> shell.open();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> display.dispose();
>> }
>>
>> class DropLS implements DropTargetListener{
>> TableItem olditem=null;
>> public void drop(DropTargetEvent event) {
>> TableItem item = (TableItem)event.item;
>>
>> System.out.println("Droped");
>> }
>>
>>
>> public void dragOver(DropTargetEvent event) {
>> TableItem item = (TableItem)event.item;
>>
>> if (item!=null && !item.equals(olditem)){
>> System.out.println("Drop Over: "+item.getText());
>> olditem = item;
>> event.feedback = DND.FEEDBACK_SELECT;
>> }
>>
>> }
>>
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse .swt.dnd.DropTargetEvent)
>> */
>> public void dragEnter(DropTargetEvent arg0) {
>> TableItem item = (TableItem)arg0.item;
>> if (item!=null)
>> System.out.println("Drop Enter:"+item.getText());
>>
>> }
>>
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse .swt.dnd.DropTargetEvent)
>> */
>> public void dragLeave(DropTargetEvent arg0) {
>> TableItem item = (TableItem)arg0.item;
>> if (item!=null)
>> System.out.println("Drop Leave: "+item.getText());
>> }
>>
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged( org.eclipse.swt.dnd.DropTargetEvent)
>> */
>> public void dragOperationChanged(DropTargetEvent arg0) {
>>
>> }
>>
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.swt.dnd.DropTargetListener#dropAccept(org.eclips e.swt.dnd.DropTargetEvent)
>> */
>> public void dropAccept(DropTargetEvent arg0) {
>> TableItem item = (TableItem)arg0.item;
>> if (item!=null)
>> System.out.println("Drop Accept: "+item.getText());
>> }
>> }
>>
>> class DragLS extends DragSourceAdapter{
>> Object dragSource = null;
>> public void dragStart(DragSourceEvent event) {
>> IStructuredSelection selection =
>> (IStructuredSelection)tableViewer.getSelection();
>> if (selection!=null && !selection.isEmpty()) {
>> event.doit = true;
>> dragSource = selection.getFirstElement();
>> } else {
>> event.doit = false;
>> }
>> };
>>
>> public void dragSetData(DragSourceEvent event) {
>> event.data = dragSource.toString();
>> }
>>
>> public void dragFinished(DragSourceEvent event) {
>> System.out.println("Drag Object: "+dragSource.toString()+"
>> Finished");
>> }
>> }
>> }
>>
>
>
Previous Topic:Plz somebody help me with SWT Table
Next Topic:Loading jpgs into a table?
Goto Forum:
  


Current Time: Thu Nov 26 01:45:55 GMT 2020

Powered by FUDForum. Page generated in 0.02219 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top