我有一个简单的单元格类:
public class MyCell implements AbstractCell<MyDto> {
...
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
MyDto value, SafeHtmlBuilder sb) {
}
}我怎么能听到这样一个单元格的MGWT TapEvent?
编辑:我不想使用MGWT提供的CellList,我需要使用来自GWT的CellList,因为这使我能够使用数据提供程序。
可能是触摸委托可以链接到单元格吗?
发布于 2014-06-15 11:32:45
您不能在GWT CellTable中轻松地使用mgwt触摸事件。
如果GWT-CellTable更开放,您可以扩展它,从Mgwt-CellTable获取与触摸事件相关的代码,并将扩展类的容器设置为具有触摸功能的小部件。但这是不可能的,因为您不能设置或更改的小部件。
因此,不必扩展GWT,您必须复制自己类中的所有代码,并从Mgwt-Cell添加触摸事件(请参阅UlTouchWidget和InternalTouchHandler代码)。但不方便的是,您必须对单元格表进行样式设计,以使其看起来具有移动性,这是一项艰巨的工作。
另一种选择是扩展Mgwt-CellTable,使其使用数据提供程序,但是由于它扩展了复合而不是AbstractHasData,所以您必须包装一个AbstractHasData并以某种方式填充它的所有API。
最简单的选择是复制Mgwt-CellTable的代码,并使其扩展AbstractHasData并实现一组方法。使用这种方式,您就有了一个移动查看小部件。这对我来说很管用:
// 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) {
}
}发布于 2014-06-11 18:54:34
举个例子,我如何在我的应用程序中使用它:
BarcodeCellSubType barcodeCellSubType = new BarcodeCellSubType();
celllist = new CellList<ScanDTO>(barcodeCellSubType);
celllist.addCellSelectedHandler(new CellSelectedHandler() {
@Override
public void onCellSelected(CellSelectedEvent event) {
//...
}
});那是我的路..。BarcodeCellSubType扩展了BarcodeCell,BarcodeCell实现了单元
还是要在MyCell对象中侦听?
https://stackoverflow.com/questions/24109640
复制相似问题