如何使用复选框选择模型在单击某一行时调用方法?
我将复选框选择模型设置如下:
table.setSelectionModel(selectionModel,
DefaultSelectionEventManager.<T> createCheckboxManager(0));发布于 2011-04-14 00:54:44
我找到了一个解决方案!不使用createCheckboxManager(),而是使用createCustomManager(),通过参数传递一个扩展CheckboxEventTranslator的EventTranslator,并委托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;
}
}
)
);发布于 2011-04-12 23:34:21
创建一个您调用的函数,
table.setSelectionModel(selectionModel, ClassName.myMethod(0));
static <T> DefaultSelectionEventManager<T> myMethod(int column) {
//call whatever functions you want
return DefaultSelectionEventManager.<T> createCheckboxManager(column);
}https://stackoverflow.com/questions/5637598
复制相似问题