处理来自 CellTable 的点击事件,如何将它们处理回默认调度程序?

发布于 2024-12-12 15:00:04 字数 2922 浏览 0 评论 0原文

我有一个带有一个自定义列的 CellTable,我在其中手动渲染它,并放置一个带有一堆 HTMLPanel/Anchor/FlowPanel 小部件的 FlowPanel,其中有 DecoratorPanel。

当然,DecoratorPanel 呈现为表格。

渲染是这样发生的:

public class MyExpandableCell extends AbstractCell<String> {
    ...
    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
        if (value != null) {
            FlowPanel fp = createDetailsFlowPanel(value);
            sb.appendHtmlConstant(fp.getElement().getString());
        }
    }

现在,我已将单击事件的处理程序添加到我的主 CellTable 中。在我的处理程序中,我遍历树以查找属于我的 CellTable 的第一个 TR,方法是检查它是否包含“偶数行”或“奇数行”CSS 类。

但是,当单击发生在 DecoratorPanel 内部(位于我的单元格表的 TD 内部)时,我的处理程序也会被触发,因为单击属于单元格表区域。

我可以通过看到父 TR 没有 CellTable CSS 类来检测到这一点。

问题:如何将此类单击事件的处理返回到 DecoratorPanel - 它真正属于哪里?现在,我的 DecoratorPanel 不会展开,我想是因为我的单击处理程序拦截并抑制了 CellTable 级别上的所有单击。

table = setupMyCellTable(PAGE_SIZE, CLIENT_BUNDLE, myCellTableResources);
mydataprovider.addDataDisplay(table);
table.sinkEvents(Event.ONCLICK);
table.addDomHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent e) {
        boolean isClick = "click".equals(e.getNativeEvent().getType());
        if (isClick) {
            Element originalElement = e.getNativeEvent().getEventTarget().cast();
            Element element = originalElement;
            String ctTrClassEven = CLIENT_BUNDLE.mainCss().cellTableEvenRow();
            String ctTrClassEven = CLIENT_BUNDLE.mainCss().cellTableOddRow();

            // Looking for closest parent TR which has one
            // of the two row class names (for this cellTable):
            while (element != null
                    && !"tr".equalsIgnoreCase(element.getTagName())
                    && !(element.getClassName().contains(ctTrClassEven) ||
                         element.getClassName().contains(ctTrClassEven))) {
                element = element.getParentElement();
            }
            if (element != null) {
                if (element.getClassName().contains(ctTrClassEven)
                        || element.getClassName().contains(ctTrClassEven)) {
                    // Found cell table's TR. Set new TR height.
                } else {
                    // Found TR from DecoratorPanel inside of the celltable's cell.
                    // Do nothing. But how do I make sure
                    // that decorator panel processes this click and expands?
                    return;
                    // Did not work: NS_ERROR_ILLEGAL_VALUE javascript exception.
                    // if (originalElement != null) {
                    //     originalElement.dispatchEvent(e.getNativeEvent());
                    // }
                }
            } else {
                debugStr.setText("(did not find tr)");
            }
        }
    }
}, ClickEvent.getType());

I have a CellTable with one custom column where I render it manually and put a FlowPanel with a bunch of HTMLPanel/Anchor/FlowPanel widgets, and among them is DecoratorPanel.

DecoratorPanel renders as a table, of course.

Rendering happens like this:

public class MyExpandableCell extends AbstractCell<String> {
    ...
    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
        if (value != null) {
            FlowPanel fp = createDetailsFlowPanel(value);
            sb.appendHtmlConstant(fp.getElement().getString());
        }
    }

Now, I have added a handler for click events to my main CellTable. In my handler I traverse the tree to find a first TR belonging to my CellTable, by checking if it contains "even row" or "odd row" CSS classes.

However, when click happens inside of the DecoratorPanel (which is inside of my cell table's TD), my handler also gets triggered, since the click belongs to the cell table area.

I can detect this my seeing that parent TR does not have CellTable CSS classes.

QUESTION: how can I return processing of such click events to the DecoratorPanel - where it really belongs to? As it is now, my DecoratorPanel does not expand and I think because my click handler intercepts and suppresses all clicks on the CellTable level.

table = setupMyCellTable(PAGE_SIZE, CLIENT_BUNDLE, myCellTableResources);
mydataprovider.addDataDisplay(table);
table.sinkEvents(Event.ONCLICK);
table.addDomHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent e) {
        boolean isClick = "click".equals(e.getNativeEvent().getType());
        if (isClick) {
            Element originalElement = e.getNativeEvent().getEventTarget().cast();
            Element element = originalElement;
            String ctTrClassEven = CLIENT_BUNDLE.mainCss().cellTableEvenRow();
            String ctTrClassEven = CLIENT_BUNDLE.mainCss().cellTableOddRow();

            // Looking for closest parent TR which has one
            // of the two row class names (for this cellTable):
            while (element != null
                    && !"tr".equalsIgnoreCase(element.getTagName())
                    && !(element.getClassName().contains(ctTrClassEven) ||
                         element.getClassName().contains(ctTrClassEven))) {
                element = element.getParentElement();
            }
            if (element != null) {
                if (element.getClassName().contains(ctTrClassEven)
                        || element.getClassName().contains(ctTrClassEven)) {
                    // Found cell table's TR. Set new TR height.
                } else {
                    // Found TR from DecoratorPanel inside of the celltable's cell.
                    // Do nothing. But how do I make sure
                    // that decorator panel processes this click and expands?
                    return;
                    // Did not work: NS_ERROR_ILLEGAL_VALUE javascript exception.
                    // if (originalElement != null) {
                    //     originalElement.dispatchEvent(e.getNativeEvent());
                    // }
                }
            } else {
                debugStr.setText("(did not find tr)");
            }
        }
    }
}, ClickEvent.getType());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-12-19 15:00:04

看起来像是 GWT 中的一个错误,由于装饰器面板使用表格来渲染自身而触发:
http://code.google.com/p/google -web-toolkit/issues/detail?id=5714
(另一个示例 http://code.google.com/ p/google-web-toolkit/issues/detail?id=6750

修复预计将随 GWT 2.5 一起提供。

Looks like a bug in GWT, triggered because decorator panel uses table to render itself:
http://code.google.com/p/google-web-toolkit/issues/detail?id=5714
(another example http://code.google.com/p/google-web-toolkit/issues/detail?id=6750)

Fix is expected to be shipped with GWT 2.5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文