我在为Datagrid实施双击处理程序时遇到问题。我已经找到了在堆栈溢出上发布的解决方案,该解决方案应该可以解决我的问题,但是我无法确定:

1. How exactly do I implement it?
2. What is <T>?


我收到各种我不明白的错误。问题几乎可以肯定是我添加CellPreviewHandler的方式(第6行)

错误(第6和8行)

-类型new CellPreviewEvent.Handler(){}必须实现继承的抽象方法CellPreviewEvent.Handler.onCellPreview(CellPreviewEvent)

-类型为新AsynCallBack(String [] []>(){}类型的onCellPreview(CellPreviewEvent)方法必须重写或实现超类型方法

我的代码:

Public Class DataGrid extends Widget{
    Timer singleClickTimer;
    int clickCount = 0;
    int clickDelay = 300;
myDataTable = new DataGrid<String[]>(result.length, resources, KEY_PROVIDER);
myDataTable.addCellPreviewHandler(new Handler<T>(){
@Override
public void onCellPreview(final CellPreviewEvent<T> event) {
    if (Event.getTypeInt(event.getNativeEvent().getType()) == Event.ONMOUSEOVER) {
        handleOnMouseOver(event);
    } else if (Event.getTypeInt(event.getNativeEvent().getType()) == Event.ONCLICK) {
        clickCount++;
        if (clickCount == 1) {
            singleClickTimer = new Timer() {

                @Override
                public void run() {
                    clickCount = 0;
                    handleOnClick(event);
                }
            };
            singleClickTimer.schedule(clickDelay);
        } else if (clickCount == 2) {
            singleClickTimer.cancel();
            clickCount = 0;
            handleOnDblClick(event);
        }
    }
}
});
private void handleOnMouseOver(CellPreviewEvent<T> event) {
    Element cell = event.getNativeEvent().getEventTarget().cast();
    GWT.log("mouse over event");
}

private void handleOnClick(CellPreviewEvent<T> event) {
    Element cell = event.getNativeEvent().getEventTarget().cast();
    GWT.log("click event");
}

private void handleOnDblClick(CellPreviewEvent<T> event) {
    Element cell = event.getNativeEvent().getEventTarget().cast();
    GWT.log("double click event");
}


链接到原始解决方案:
adding Double click event in CellTable cell - GWT

最佳答案

这不是一个很好的代码(更好的选择是扩展DataGrid类),但是如果您不想做太多更改,只需将<T>替换为<String[]>

09-18 00:04