Reputation: 163
I am having an issue implementing a double click handler for my Datagrid. I have found a solution posted on Stack overflow that should fix my problem i believe, however, I can not figure out:
1. How exactly do I implement it?
2. What is <T>?
I am getting various errors I do not understand. The issue is almost certainly with the way I add the CellPreviewHandler (Line 6)
Errors (line 6 & 8)
-the Type new CellPreviewEvent.Handler(){} must implement the inherited abstract method CellPreviewEvent.Handler.onCellPreview(CellPreviewEvent)
-The method onCellPreview(CellPreviewEvent) of type new AsynCallBack(String[][]>(){} must override or implement a supertype method
MyCode:
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");
}
Link to original solution: adding Double click event in CellTable cell - GWT
Upvotes: 0
Views: 562
Reputation: 41089
This is not a very good code (a better option would be to extend DataGrid class), but if you don't want to change much, simply replace <T>
with <String[]>
.
Upvotes: 1