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 中添加了一个单击事件处理程序。在我的处理程序中,通过检查它是否包含“偶数行”或“奇数行”CSS 类,我遍历树以找到属于我的 CellTable 的第一个 TR。

但是,当点击发生在 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());
4

1 回答 1

0

看起来像 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 一起提供。

于 2011-10-31T23:36:39.350 回答