Thursday, June 30, 2011

CellTable doesn't update the value from ClickableTextCell

Hi,
I've extended the ClickableTextCell to allow user to pick up a value
from a dialog box. The problem is that when user pick the value and
commit the choice the value is not displayed in CellTable, although
the bean that is used under the Cell has new value. The cell's update
method is albo invoked. What can be the problem? How to handle it?


Here's the code of the extended class:

public class ModifiedClickableTextCell extends
AbstractSafeHtmlCell<String> {

private AdminConstants ac = AdminConstants.AC.constants();

public ModifiedClickableTextCell() {
this(SimpleSafeHtmlRenderer.getInstance());
}

public ModifiedClickableTextCell(SafeHtmlRenderer<String> renderer) {
super(renderer, "click", "keydown");
}

@Override
public void onBrowserEvent(final Context context, final Element
parent, final String value, final NativeEvent event, final
ValueUpdater<String> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
Integer key = (Integer) context.getKey();
if (key == -1) {
if ("click".equals(event.getType())) {

final DialogBox db = new DialogBox();
db.setAutoHideEnabled(false);

Label searchLbl = new Label(ac.search());
Label producerLbl = new Label(ac.producer());

final ListBox lb = new ListBox();
getProducers(lb);

final TextBox tb = new TextBox();
tb.setWidth("150px");
tb.addKeyUpHandler(new KeyUpHandler() {

@Override
public void onKeyUp(KeyUpEvent kue) {
String p =
TextUtils.replaceAsteriskWithPercentToUpperCaseOrNull(tb.getText());
AsyncCallback<List<DictDTO>> cb = new
AdminAsyncCallback<List<DictDTO>>() {
@Override
public void onSuccess(List<DictDTO> result) {
if (result != null && !result.isEmpty()) {
lb.clear();
lb.addItem("");
for (DictDTO d : result) {
lb.addItem(d.getValue());
}
}
}
};
AdminService.Async.service().searchProducers(p, cb);
}
});

lb.setWidth("100%");

FlexTable ft = new FlexTable();
ft.setWidth("300px");
ft.setWidget(0, 0, searchLbl);
ft.setWidget(1, 0, producerLbl);
ft.setWidget(0, 1, tb);
ft.setWidget(1, 1, lb);
ft.getColumnFormatter().setWidth(0, "50%");
ft.getColumnFormatter().setWidth(1, "50%");
DOM.setStyleAttribute(ft.getFlexCellFormatter().getElement(0, 0),
"textAlign", "center");
DOM.setStyleAttribute(ft.getFlexCellFormatter().getElement(1, 0),
"textAlign", "center");
Button closeBtn = new Button(ac.close());
closeBtn.setStyleName("");
closeBtn.setWidth("60px");
DOM.setStyleAttribute(closeBtn.getElement(), "display", "block");
DOM.setStyleAttribute(closeBtn.getElement(), "margin", "auto");
closeBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent ce) {
db.hide();
}
});
Button okBtn = new Button(ac.ok());
okBtn.setStyleName("");
okBtn.setWidth("60px");
DOM.setStyleAttribute(okBtn.getElement(), "display", "block");
DOM.setStyleAttribute(okBtn.getElement(), "margin", "auto");
okBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent ce) {
String producer = lb.getItemText(lb.getSelectedIndex());
onEnterKeyDown(context, parent, producer, event, valueUpdater);
db.hide();
}
});
ft.setWidget(2, 0, okBtn);
ft.setWidget(2, 1, closeBtn);
db.add(ft);
db.center();
}
}
}

@Override
protected void onEnterKeyDown(Context context, Element parent, String
value, NativeEvent event, ValueUpdater<String> valueUpdater) {
if (valueUpdater != null) {
valueUpdater.update(value);
}
}

@Override
protected void render(Context context, SafeHtml value,
SafeHtmlBuilder sb) {
if (value != null) {
sb.append(value);
}
}

private void getProducers(final ListBox lb) {
Dict.getProducers(new AdminAsyncCallback<List<String>>() {

@Override
public void onSuccess(List<String> result) {
if (result != null) {
for (String s : result) {
lb.addItem(s);
}
}
}
});
}
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment