GWT 网格的 DoubleClick 事件处理程序
我正在使用 gwt 网格,并且尝试获取具有 onDoubleClick 事件的单元格。因此,如果我正在执行 onClickEvent,我会使用 getCellForEvent(ClickEvent) 并返回一个单元格。但该方法不接受 DoubleClickEvent。如何获取具有 onDoubleClick... 的单元格?
I am using a gwt grid and Im trying to get the cell that had the onDoubleClick event on it. So if I was doing onClickEvent I would use getCellForEvent(ClickEvent) and that returns a cell. But that method doesnt accept a DoublClickEvent. How do I get the cell that had the onDoubleClick...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
扩展
Grid
并使用受保护的getEventTargetCell
从NativeEvent
而不是GwtEvent
获取单元格。Extend
Grid
and use the protectedgetEventTargetCell
to obtain the cell from aNativeEvent
instead of aGwtEvent
.我没有想到 NativeEvent 的事情。我希望它可以跨浏览器移植。我的 DataGrid 有 ClickableTextCells 的扩展。 DClickableTextCell(“D”代表双击)对双击做出反应,Microsoft 将其定义为 500 毫秒内的双击。
如果 DoubleClick 计时器当前正在运行,则此点击必须是双击的第二次点击。如果 DoubleClick 计时器当前未运行,则这可能是 DoubleClick 的第一次点击。启动计时器。以下是 DoubleClickTimer 的代码:
它可以工作,但现在我要考虑扩展 DataGrid。问题是 DataGrid 引用 AbstractCellTable 中受保护的方法,一旦将 DataGrid 子类放入不同的包中,这些方法就无法访问。您也可以将 AbstractCellTable 引入,但它会进行类似的引用,最终您会复制更多内容。
对 event.preventDefault 的调用会抑制双击的正常行为,即突出显示正在单击的小部件。由于整个 DataGrid 是一个小部件(单元格和列不是小部件),因此 DataGrid 中的每一位文本都会被选中,除非您阻止该默认行为。
我不是专家,我想从人们那里得到关于我是否可以做得更好的建议。但它确实有效,所以我将其作为可能的答案提供。
I didn't think of that NativeEvent thing. I hope it's portable across browsers. My DataGrid has an extension of ClickableTextCells. The DClickableTextCell ("D" for double-click) reacts to a double-click, which Microsoft defines as two-clicks within 500 milliseconds.
If the DoubleClick timer is currently running, then this click must the second click of a double-click. If the DoubleClick timer is not currently running, then this is potentially the first click of a DoubleClick. Start the timer. Here's the code for DoubleClickTimer:
It works, but now I'm going to look at extending DataGrid. The problem is that DataGrid refers to protected methods in AbstractCellTable that aren't accessible as soon as you put your DataGrid subclass in a different package. You can bring AbstractCellTable over as well, but then it makes similar references, and you end up copying more stuff.
The call to event.preventDefault suppresses the normal behaviour of a double-click, and that is to highlight the widget being clicked on. Since the whole DataGrid is a single widget (cells and columns are not widgets), every bit of text in the DataGrid gets selected unless you prevent that default behaviour.
I'm not an expert and I'd like to get advice from people on whether I could be doing this better. But it works, so I'm offering it as a possible answer.
您需要扩展原始单元格。在构造函数中将:
super("click", "keyup", "keydown", "blur");
更改为super("dblclick", "keyup", "keydown", " Blur");
并在 onBrowserEvent 方法中将:
if ("click".equals(type) || EnterPressed)
更改为if ("dblclick".equals(type) || 已按下)
You'll need to extend the original cell. In the constructor change:
super("click", "keyup", "keydown", "blur");
tosuper("dblclick", "keyup", "keydown", "blur");
and in the onBrowserEvent method change:
if ("click".equals(type) || enterPressed)
toif ("dblclick".equals(type) || enterPressed)