Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » DragAndDrop Source problem
DragAndDrop Source problem [message #448611] Wed, 12 January 2005 00:44 Go to next message
Steve is currently offline SteveFriend
Messages: 29
Registered: July 2009
Junior Member
Hi there,

I am implementing DND on a set of Labels the drop tager
//--------------
new DropTargetListener() {
public void dragEnter(DropTargetEvent arg0) {
Label item = (Label) ((DropTarget) arg0.getSource())
.getControl();
if (((TableBean) item.getData()).getTableName().equals(
((TableBean) selItem.getData()).getTableName()))
arg0.detail = DND.DROP_NONE;
else {
arg0.detail = DND.DROP_LINK;
}

prevDropTargetBg = ((Label) arg0.getSource())
.getBackground();
((Label) arg0.getSource()).setBackground(display
.getSystemColor(SWT.COLOR_DARK_MAGENTA));

}

public void dragLeave(DropTargetEvent arg0) {
((Label) arg0.widget).setBackground(prevDropTargetBg);
}

public void dragOperationChanged(DropTargetEvent arg0) {
// TODO Auto-generated method stub

}

public void dragOver(DropTargetEvent arg0) {
}

public void drop(DropTargetEvent arg0) {
if (selItem == null)
return;
String dt = (String) arg0.data;
Label item = (Label) arg0.widget;
item.setBackground(prevDropTargetBg);
int ttlTop = SWTUtils.getOffsetTop(item, tableCanvas);
int ttlLeft = SWTUtils.getOffsetLeft(item, tableCanvas);
if (item == null)
return;
qBean.addJoin(selTable, selItem, (TableBean) item
.getParent().getData(), item);
}

public void dropAccept(DropTargetEvent arg0) {
// TODO Auto-generated method stub

}
}
//--------------

the line in dragEnter

Label item = (Label) ((DropTarget) arg0.getSource())
.getControl();

returns the Label that the drag originated from, not the label that the
mouse is currently hovering over.

Is this the normal behavour of DnD, or is there something I am doing wrong.

I have triend this two ways, one where every label shares the same
DropTargetListener, and one where every label has it's own instance of a
DropTargetListener, both times using the code as specified above.

Both times the same result has occured.

What I am trying to get returned is the Control over which the mouse is
hovering. I will try with a MouseTrackListener, but I think, when in DnD
mode, the MouseTrackListener isn't fired.

Regards

Steve
Re: DragAndDrop Source problem [message #448619 is a reply to message #448611] Wed, 12 January 2005 12:25 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Calling

Label item = (Label) ((DropTarget) arg0.getSource()).getControl();

in dragEnter DOES return the widget that you are hovering over. I have
verified this by printing out the handles of the widgets in a simple
example. There is something else wrong with your example. Perhaps the
"selItem" value is being set incorrectly.


"Steve" <steve@crmsoftware.com.au> wrote in message
news:cs1ski$kff$1@www.eclipse.org...
> Hi there,
>
> I am implementing DND on a set of Labels the drop tager
> //--------------
> new DropTargetListener() {
> public void dragEnter(DropTargetEvent arg0) {
> Label item = (Label) ((DropTarget) arg0.getSource())
> .getControl();
> if (((TableBean) item.getData()).getTableName().equals(
> ((TableBean) selItem.getData()).getTableName()))
> arg0.detail = DND.DROP_NONE;
> else {
> arg0.detail = DND.DROP_LINK;
> }
>
> prevDropTargetBg = ((Label) arg0.getSource())
> .getBackground();
> ((Label) arg0.getSource()).setBackground(display
> .getSystemColor(SWT.COLOR_DARK_MAGENTA));
>
> }
>
> public void dragLeave(DropTargetEvent arg0) {
> ((Label) arg0.widget).setBackground(prevDropTargetBg);
> }
>
> public void dragOperationChanged(DropTargetEvent arg0) {
> // TODO Auto-generated method stub
>
> }
>
> public void dragOver(DropTargetEvent arg0) {
> }
>
> public void drop(DropTargetEvent arg0) {
> if (selItem == null)
> return;
> String dt = (String) arg0.data;
> Label item = (Label) arg0.widget;
> item.setBackground(prevDropTargetBg);
> int ttlTop = SWTUtils.getOffsetTop(item, tableCanvas);
> int ttlLeft = SWTUtils.getOffsetLeft(item, tableCanvas);
> if (item == null)
> return;
> qBean.addJoin(selTable, selItem, (TableBean) item
> .getParent().getData(), item);
> }
>
> public void dropAccept(DropTargetEvent arg0) {
> // TODO Auto-generated method stub
>
> }
> }
> //--------------
>
> the line in dragEnter
>
> Label item = (Label) ((DropTarget) arg0.getSource())
> .getControl();
>
> returns the Label that the drag originated from, not the label that the
> mouse is currently hovering over.
>
> Is this the normal behavour of DnD, or is there something I am doing
> wrong.
>
> I have triend this two ways, one where every label shares the same
> DropTargetListener, and one where every label has it's own instance of a
> DropTargetListener, both times using the code as specified above.
>
> Both times the same result has occured.
>
> What I am trying to get returned is the Control over which the mouse is
> hovering. I will try with a MouseTrackListener, but I think, when in DnD
> mode, the MouseTrackListener isn't fired.
>
> Regards
>
> Steve
>
>
Previous Topic:ProgressBar SWT.INDETERMINATE
Next Topic:DnD - several transfer classes?
Goto Forum:
  


Current Time: Fri Apr 16 18:27:12 GMT 2021

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

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

Back to the top