Reputation: 21
I'm trying to delete a widget from a panel when I drop that widget outside the panel. I looked up these tutorials and examples http://code.google.com/p/gwt-dnd/wiki/GettingStarted but I can't figure out how to set up the drop controller to drop it outside my panel.
Can you please give a hint or an idea?
Upvotes: 0
Views: 908
Reputation: 3048
If you instantiate a PickupDragController
as
PickupDragController controller =
new PickupDragController(pickupContainer, false);
and you drop your widgets outside the pickup container, then a VetoDragException
is automatically thrown (as a result of that false
in the contructor). See the JavaDoc or even the code in BoundaryDropController
if interested).
You can then register a DragHandler
and in its onDragEnd
check if the exception occurred. If so, remove the widget. Something like:
class MyHandler implements DragHandler {
// onPreviewDragStart, onDragStart, onPreviewDragEnd omitted.
public void onDragEnd(DragEndEvent event) {
if (event.getContext().vetoException != null) {
// Not sure it works, but you get the idea.
event.getContext().draggable.removeFromParent();
}
}
}
controller.addDragHandler(new MyHandler());
Upvotes: 2
Reputation: 53
In the DropController (AbstractDropController) you have to define in the constructor, a element, where you can drop the elements. Do you have some code snippets to help you concrete?
PS: I have build some D&D with this library you mentioned, in my opinion, it is buggy and not so easy to start with. But I didn't found a better native D&D lib for GWT, we tried to wrap the jquery D&D. It is very fast and smooth, but hard to wrap.
Upvotes: 0