Open GoogleCodeExporter opened 9 years ago
And got the same thing with a ManyToOne field :
The code :
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
public abstract class ComboxBoxEditor<T> extends Composite implements
LeafValueEditor<T> {
private T value;
private List<T> liste = new ArrayList<T>();
private final ListBox listBox = new ListBox();
public ComboxBoxEditor() {
initWidget(listBox);
listBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
value = liste.get(listBox.getSelectedIndex());
}
});
}
@Override
protected void onAttach() {
super.onAttach();
retrieveData();
}
abstract protected String getTextValue(T obj);
abstract protected void retrieveData();
protected final void dataCallback(List<T> data) {
liste = data;
listBox.clear();
for (int i = 0; i < liste.size(); i++) {
listBox.addItem(getTextValue(liste.get(i)));
}
listBox.setSelectedIndex(liste.indexOf(value));
}
@Override
public void setValue(T value) {
this.value = value;
listBox.setSelectedIndex(liste.indexOf(value));
}
@Override
public T getValue() {
return value;
}
}
The implementation :
class MyEntityEditor implements Editor<MyEntity> {
ComboxBoxEditor<LitProxy> lit = new ComboxBoxEditor<LitProxy>() {
@Override
protected void retrieveData() {
ClientController.request().lit().findAll().fire(new Receiver<List<LitProxy>>() {
@Override
public void onSuccess(List<LitProxy> response) {
dataCallback(response);
}
});
}
@Override
protected String getTextValue(LitProxy obj) {
return obj.getNom();
}
};
}
Original comment by Creati...@gmail.com
on 15 Apr 2011 at 11:11
Original issue reported on code.google.com by
Creati...@gmail.com
on 15 Apr 2011 at 11:06