java 如何向 GWT ButtonCell 添加点击处理程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4556313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:56:59  来源:igfitidea点击:

How do I add a click handler to the GWT ButtonCell?

javagwtevent-handlingclickgwt2

提问by Noor

I created a ButtonCelland a Columnfor it:

我为它创建了一个ButtonCell和一个

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

How do I now add a click handler (e.g. ClickHandler) for this ButtonCell?

我现在如何为这个ButtonCell添加一个点击处理程序(例如ClickHandler)?

采纳答案by Jason Terk

The Cell Samplerexample includes use of clickable ButtonCells. Clicks on ButtonCells are handled by setting the FieldUpdaterfor the Column:

细胞取样例子包括使用可点击ButtonCells的。通过为列设置FieldUpdater来处理对 ButtonCells 的点击:

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.
  }
});

回答by MihaiS

 //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 
    }
}