如何将单击处理程序添加到GWT ButtonCell?

时间:2010-12-29 17:35:20

标签: java gwt event-handling click gwt2

我为它创建了ButtonCellColumn

ButtonCell previewButton = new ButtonCell();
Column<Auction,String> preview = new Column<Auction,String>(previewButton) {
  public String getValue(Auction object) {
    return "Preview";
  }
};

如何为此ClickHandler添加点击处理程序(例如ButtonCell)?

2 个答案:

答案 0 :(得分:16)

Cell Sampler示例包括使用可点击的ButtonCell。点击ButtonCells是通过设置列的FieldUpdater来处理的:

preview.setFieldUpdater(new FieldUpdater<Auction, String>() {
  @Override
  public void update(int index, Auction object, String value) {
    // The user clicked on the button for the passed auction.
  }
});

答案 1 :(得分:0)

 //Prevent mouse events  for table cell
 CellPreviewEvent.Handler<Auction > manager = DefaultSelectionEventManager.createBlacklistManager(4);//column number
 cellTable.setSelectionModel(selectionModel, manager);

 new Column<Auction , String>(new ButtonCell()){

    @Override
    public String getValue(Auction object) {
        return "Preview";
    }

    @Override
    public void onBrowserEvent(Cell.Context context, Element elem, Auction object, NativeEvent event) {
        event.preventDefault();

       //TODO implement event handling 
    }
}