[英]Drag and drop gwt
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.
我查看了这些教程和示例http://code.google.com/p/gwt-dnd/wiki/GettingStarted,但我无法弄清楚如何设置放置控制器以将其放在我的面板之外。
Can you please give a hint or an idea? 你能给出一个暗示或想法吗?
If you instantiate a PickupDragController
as 如果你将
PickupDragController
实例PickupDragController
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). 然后将小部件放在拾取容器之外,然后自动抛出
VetoDragException
(由于构造VetoDragException
中的false
)。 See the JavaDoc or even the code in BoundaryDropController
if interested). 如果感兴趣,请参阅JavaDoc甚至是
BoundaryDropController
的代码。
You can then register a DragHandler
and in its onDragEnd
check if the exception occurred. 然后,您可以注册一个
DragHandler
并在其onDragEnd
检查是否发生了异常。 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());
In the DropController (AbstractDropController) you have to define in the constructor, a element, where you can drop the elements. 在DropController(AbstractDropController)中,您必须在构造函数中定义一个元素,您可以在其中删除元素。 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. PS:我已经用你提到的这个库建立了一些D&D,在我看来,它是错误的并且不容易入手。 But I didn't found a better native D&D lib for GWT, we tried to wrap the jquery D&D.
但我没有为GWT找到更好的原生D&D库,我们试图包装jquery D&D。 It is very fast and smooth, but hard to wrap.
它非常快速和光滑,但很难包裹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.