Drag and Drop handling multiple events


I am able to drag and drop items from table to tree. But, I hav requirement of drag and drop items inside tree also.

Scenario is , First I will drag few items from table and put it under a tree node. Similarly, I can have many tree nodes, having children as items dropped from table. Now, I might want to move the child items from one tree node to another tree node in Tree. Is is possible to handle, multiple drop events, one from another table and another with in tree table child items.

Hope I portrayed my requirements clear. Awaiting for suggestions and ideas.

I was recently looking for a solution for this exact scenario and was finally able to get this to work! I was able to figure this one out after taking a look at the constructors for
accept criteria.

If you look at And, for instance, you’ll see…

public And(ClientSideCriterion... criteria) {
    this.criteria = criteria;

While the constructor for Or looks like this…

public Or(ClientSideCriterion... criteria) {
    this.criteria = criteria;

Both constructors can take any number of ClientSideCriterion as formal parameters, so I realized, after playing with these two ClientSideCriterion for a bit, that really what I needed to do to be able to drop objects onto a tree from a table AND from itself, was a modification of the getAcceptCriterion() method override in the DropHandler implementation.

So the code I came up with looks like this…

@Override public AcceptCriterion getAcceptCriterion() { return new Or(new And(acceptCriterion1, AcceptItem.ALL), new And(acceptCriterion2, AcceptItem.ALL)); } where acceptCriterion1 is my table

new SourceIs(table);

and acceptCriterion2 is my tree

new SourceIs(tree);

The neat thing about the And and Or is that you can not only have 2 drop targets, but any number you want, depending on what combination of logic you implement with those two accept criterion.

~ Ray Hedgecock