Sai
Sai

Reputation: 461

How to get the source component during dragEnter in Java SWT

I would like to create the following workflow:

  1. There are two types of boxes (A and B) and two types of baskets (C and D).
  2. Both types of boxes can be dragged and dropped into based C.
  3. But only boxes of type A can be dragged and dropped in D.

I would like to detect the type of box (A or B) during the dragEnter event in the DropTargetListener, so that I can change the cursor to DROP_NONE.

But right now all I can do is detect it during the actual drop event and then throw it away if it is incompatible with the basket.

Please guide me on how to solve this issue.

NOTE: I am using SWT org.eclipse.swt.dnd framework.

SNIPPET:

I would like to do something like this:

public void dragEnter (DropTargetEvent e)
{
    Box b = e.getSource // this is the part I need help with

    if(b.type == 'B')
       e.detail = DROP_NONE;
}

Upvotes: 0

Views: 313

Answers (1)

Loris Securo
Loris Securo

Reputation: 7638

You could create a static variable to keep the current drag source. You set it in dragStart and null it in dragFinished. Then you use it in dragEnter and other events to make your evaluations.

Upvotes: 1

Related Questions