I have a simple Cell class:
public class MyCell implements AbstractCell<MyDto> {
...
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
MyDto value, SafeHtmlBuilder sb) {
}
}
How can I listen to an MGWT TapEvent to such a cell?
Edit: I do not want to use the CellList provided by MGWT I need to use the CellList from GWT because this enables me to use a data provider.
May be a touch delegate can be linked to the Cell?
You cannot use mgwt touch events with GWT CellTable easily.
If GWT-CellTable were more open, you could extend it, take the code related with touch events from Mgwt-CellTable and set the container of your extended class a touch capable widget. But that is impossible because you can not set nor change the widget of the GWT-CellTable.
So instead of extending GWT-CellTable you have to duplicate all the code in your own class and add the touch events stuff from Mgwt-Cell (see UlTouchWidget and InternalTouchHandler code). But the inconvenient is that you have to style the cell table to look mobile which is a hard work.
Another option would be to extend Mgwt-CellTable to make it use data providers, but since it extends Composite instead of AbstractHasData, you have to wrap an AbstractHasData and populate all its API someway.
The simplest option, is to duplicate the code of Mgwt-CellTable and make it extend AbstractHasData and implement a bunch of methods. Using this way you have a mobile looking widget. This works for me:
// Copy mgwt CellList and change package and classname
package com.example;
// Make it extend AbstractHasData instead of Composite
public class MyCellList<T> extends AbstractHasData<T> {
/* Copy here all mgwt CellList code */
....
// Change the constructor to call the AbstractHasData one
public MyCellList(Cell<T> cell, ListCss css) {
super(new UlTouchWidget(),25, null);
main = (UlTouchWidget) getWidget();
css.ensureInjected();
this.cell = cell;
this.css = css;
internalTouchHandler = new InternalTouchHandler();
setStylePrimaryName(css.listCss());
}
// implement AbstractHasData methods
protected boolean dependsOnSelection() {
return false;
}
private Element fakeDiv = Document.get().createDivElement();
protected Element getChildContainer() {
return fakeDiv;
}
protected Element getKeyboardSelectedElement() {
return fakeDiv;
}
protected boolean isKeyboardNavigationSuppressed() {
return true;
}
protected void renderRowValues(SafeHtmlBuilder sb, List<T> values, int start,
SelectionModel<? super T> selectionModel)
throws UnsupportedOperationException {
render(values);
}
protected boolean resetFocusOnCell() {
return false;
}
protected void setKeyboardSelected(int index, boolean selected,
boolean stealFocus) {
}
}