【问题标题】:GWT CellTable with checkbox selection and on row click event具有复选框选择和行单击事件的 GWT CellTable
【发布时间】:2011-04-12 15:19:48
【问题描述】:

使用复选框选择模型单击某行时如何调用方法?

我正在像这样设置复选框选择模型:

table.setSelectionModel(selectionModel, 
      DefaultSelectionEventManager.<T> createCheckboxManager(0));

【问题讨论】:

    标签: java gwt gwt-2.2-celltable


    【解决方案1】:

    我找到了解决办法!不要使用createCheckboxManager(),而是使用createCustomManager(),通过参数传递一个扩展CheckboxEventTranslatorEventTranslator 并执行translateSelectionEvent 方法的委托,只拦截超级(CheckboxEventTranslator)忽略的事件。

    源代码:

    table.setSelectionModel(selectionModel, 
        DefaultSelectionEventManager.createCustomManager(
            new DefaultSelectionEventManager.CheckboxEventTranslator<T>() {
                @Override
                public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) {
                    SelectAction action = super.translateSelectionEvent(event);
                    if (action.equals(SelectAction.IGNORE)) {
                        GWT.log("DO WHAT YOU WANT!!!");
                        return SelectAction.IGNORE;
                    }
                    return action;
                }
            }
        )
    );
    

    【讨论】:

      【解决方案2】:

      创建一个你调用的函数,

      table.setSelectionModel(selectionModel, ClassName.myMethod(0));
      
      static <T> DefaultSelectionEventManager<T> myMethod(int column) {
         //call whatever functions you want
         return DefaultSelectionEventManager.<T> createCheckboxManager(column);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-21
        • 2017-10-29
        • 2011-10-25
        • 2011-06-16
        • 1970-01-01
        相关资源
        最近更新 更多