gpt4 book ai didi

java - GWT 编辑器和获取/设置值

转载 作者:行者123 更新时间:2023-12-01 15:46:02 26 4
gpt4 key购买 nike

我有以下编辑器类,我很好奇它出了什么问题。运行时,它确实正确地将右侧单选按钮设置为选定的。但是,当刷新顶级编辑器时,永远不会调用 getValue,并且我的对象的属性永远不会更新。这是代码(提示 - 修改过的 ValueListBox):

    public class ValueRadioList<T> extends FlowPanel implements
HasConstrainedValue<T>, LeafValueEditor<T>, ValueChangeHandler<Boolean> {

private final List<T> values = new ArrayList<T>();
private final Map<Object, Integer> valueKeyToIndex =
new HashMap<Object, Integer>();

private final String name;
private final Renderer<T> renderer;
private final ProvidesKey<T> keyProvider;

private T value;

public ValueRadioList(Renderer<T> renderer) {
this(renderer, new SimpleKeyProvider<T>());
}

public ValueRadioList(Renderer<T> renderer, ProvidesKey<T> keyProvider) {
super();
this.name = DOM.createUniqueId();
this.keyProvider = keyProvider;
this.renderer = renderer;
}

private void addValue(T value) {
Object key = keyProvider.getKey(value);
if (valueKeyToIndex.containsKey(key)) {
throw new IllegalArgumentException("Duplicate value: " + value);
}

valueKeyToIndex.put(key, values.size());
values.add(value);
RadioButton radio = new RadioButton(name, renderer.render(value));
radio.addValueChangeHandler(this);
add(radio);
assert values.size() == getWidgetCount();
}

@Override public HandlerRegistration addValueChangeHandler(
ValueChangeHandler<T> handler) {
return addHandler(handler, ValueChangeEvent.getType());
}

@Override public T getValue() {
return value;
}

@Override public void onValueChange(ValueChangeEvent<Boolean> event) {
int selectedIndex = -1;
for (int i = 0, l = getWidgetCount(); i < l; i++) {
if (((RadioButton) getWidget(i)).getValue()) {
selectedIndex = i;
break;
}
}

if (selectedIndex < 0) {
return; // Not sure why this happens during addValue
}
T newValue = values.get(selectedIndex);
setValue(newValue, true);
}

@Override public void setAcceptableValues(Collection<T> newValues) {
values.clear();
valueKeyToIndex.clear();
clear();

for (T nextNewValue : newValues) {
addValue(nextNewValue);
}

updateRadioList();
}

@Override public void setValue(T value) {
setValue(value, false);
}

@Override public void setValue(T value, boolean fireEvents) {
if (value == this.value
|| (this.value != null && this.value.equals(value))) {
return;
}

T before = this.value;
this.value = value;
updateRadioList();

if (fireEvents) {
ValueChangeEvent.fireIfNotEqual(this, before, value);
}
}

private void updateRadioList() {
Object key = keyProvider.getKey(value);
Integer index = valueKeyToIndex.get(key);
if (index == null) {
addValue(value);
}

index = valueKeyToIndex.get(key);
((RadioButton) getWidget(index)).setValue(true);
}
}

最佳答案

解决了,我的 POJO 错过了该领域的二传手。

关于java - GWT 编辑器和获取/设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com