如何在AbstractHasData的实现中添加onclick事件。我想我必须添加CellPreviewEvent,但我有困难这样做。如果我的方法正确以及如何添加CellPreviewEvent,请告诉我。
public class TLayout extends AbstractHasData<Summary> {
private LayoutPanel main;
private ScrollPanel scroller;
private FlowPanel contents;
private ListDataProvider<Summary> dataProvider = new ListDataProvider<Summary>();
public TLayout(int pageSize,
ListDataProvider<Summary> dataProvider) {
super(new LayoutPanel(), pageSize, dataProvider.getKeyProvider());
this.dataProvider = dataProvider;
main = (LayoutPanel) getWidget();
main.addStyleName("TLayout");
contents = new FlowPanel();
scroller = new ScrollPanel(contents);
main.add( scroller );
scroller.addStyleName("scroller" );
contents.addStyleName("contents");
main.setSize("100%", "100%");
main.setWidgetLeftRight(scroller, 0, Unit.PCT, 0, Unit.PCT);
main.setWidgetTopBottom(scroller, 0, Unit.PCT, 0, Unit.PCT);
}
@Override
protected void renderRowValues(SafeHtmlBuilder sb,
List<Summary > values, int start,
SelectionModel<? super Summary > selectionModel)
throws UnsupportedOperationException {
// TODO Auto-generated method stub
Log.debug( "TLayout.renderRowValues() ENTER" );
for (Summary summary : values) {
sb.appendHtmlConstant(createCard( summary ));
}
}
private String createCard(Summary summary ) {
StringBuilder builder= new StringBuilder();
builder.append("<div class='summary'>");
....
.....
return builder.toString();
}
答案 0 :(得分:0)
最简单的方法是使用SelectionModel。您可以将SelectionModel添加到抽象数据库中,该数据将处理您的摘要类的选择。
private final SingleSelectionModel<Summary> summarySelectionModel = new SingleSelectionModel<Summary>() {
{
addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
Summary summary = getSelectedObject();
if (summary != null) {
// do something
}
}
});
}
};
tlLayout.addSelectionModel(summarySelectionModel);