我的编辑器由几个TextBox,CheckBoxes等组成。对于由其小部件触发的ValueChangeEvents,在编辑器本身上监听的正确方法是什么?
我试图理解Developer's Guide - Editors,但无济于事。
答案 0 :(得分:2)
(G +帖子扩大讨论)
您可能会考虑一些想法:
查找HasValueChangeHandlers
的示例编辑器访问者:
driver.accept(new EditorVisitor(){
@Override
public <T> void endVisit(EditorContext<T> ctx) {
Editor<T> ed = ctx.getEditor();
if (ed instanceof HasValueChangeHandlers) {
@SuppressWarnings("unchecked")
HasValueChangeHandlers<T> hasHandlers = (HasValueChangeHandlers<T>) ed;
hasHandlers.addValueChangeHandler(new ValueChangeHandler<T>() {
@Override
public void onValueChange(ValueChangeEvent<T> event) {
// TODO update button
// consider comparing event.getValue() with ctx.getFromModel()
// though that requires seeing which editors have changes...
}
});
}
}
});
更改示例轮询:
Timer t = new Timer(){
@Override
public void run() {
boolean hasChanges = driver.isDirty();
// TODO update button with the hasChanges value
}
};
t.schedule(500);
// Don't forget to cancel() this when done, both on save and cancel!