Wednesday, October 31, 2012

Re: I Help help implementing ClickableSafeHtmlCell

If you want your cell to handle events you need to set those events as consumed by defining a constructor like

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

But do not reinvent the wheel, http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/gwt/cell/client/ClickableTextCell.html is already there (that also is a safehtmlcell).
On Wednesday, October 31, 2012 2:31:58 AM UTC+1, Milan Cvejic wrote:
Hi,
I am trying to implement ClickableSafeHtmlCell but I can not make it to handle events. I am using Field

    class ClickableSafeHtmlCell extends SafeHtmlCell {

        public void onBrowserEvent(Cell.Context context, Element parent, SafeHtml value, NativeEvent event, ValueUpdater<SafeHtml> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if ("click".equals(event.getType())) {
                Window.alert("bla");
            }
        }
    }

and then creating CellTable column with following code:

        Column<Data, SafeHtml> objectNameColumn = new Column<Data, SafeHtml>(new ClickableSafeHtmlCell()) {
            @Override
            public SafeHtml getValue(ModuleEntry object) {
                String name = (object.getName() == null ? "" : object.getName());
                String description = (object.getDescription() == null ? "" : object.getDescription());

                String regex = "(<([^>]+)>)";
                return new SafeHtmlBuilder().appendHtmlConstant(
                        "<span>" + name + "</span></br />" + "<span title='" + new SafeHtmlBuilder().appendEscaped(description.replaceAll(regex, "")).toSafeHtml().asString() + "'>"
                                + description.replaceAll(regex, "") + "</span>").toSafeHtml();
            }
        };
and set FieldUpdater for that column:

        objectNameColumn.setFieldUpdater(new FieldUpdater<Data, SafeHtml>() {
            public void update(int index, Data object, SafeHtml value) {
                Window.alert(value.asString());
            }
        });

Is there anything that I am missing? Any suggestion is welcome.

Thanks,
Milan

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/JRYUu0zn4ygJ.
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