Tuesday, February 1, 2011

Re: Can CellWidgets contain custom composite widgets ?

We have extended the AbstractCell and did the following.

Have a widget created using UiBinder XML for the content of a cell. In the render method,  instantiate the widget, set the data and getHTML. Once you get HTML, it is business as usual. You can also respond to the events inside the widget by overriding onBrowserEvent. We only had anchors inside the widget, so we listened to "click" events and responded it to it by delegating the event to presenters. This approach eliminated having to write HTML mark up in Java code. 

Not sure if this is the answer you are looking for.

Prashant

On Wed, Feb 2, 2011 at 4:10 AM, zixzigma <zixzigma@gmail.com> wrote:
after investigating CompositeCell or directly extending AbstractCell,
it is my understanding that to create custom cell,
the only option at the moment is to embed HTML markup in the render method as below.

in other words, we cannot create a custom composite widget with UiBinder,
and add it to the cell.

am I correct on this ?



    @Override
    public void render(Context context, Contact value, SafeHtmlBuilder sb) {
      /*
       * Always do a null check on the value. Cell widgets can pass null to
       * cells if the underlying data contains a null, or if the data arrives
       * out of order.
       */
      if (value == null) {
        return;
      }

      // Add a checkbox. If the contact is a favorite, the box will be checked.
      sb.appendHtmlConstant("<table><tr><td valign=\"top\">");
      if (favorites.contains(value)) {
        sb.appendHtmlConstant("<input type=\"checkbox\" checked=checked/>");
      } else {
        sb.appendHtmlConstant("<input type=\"checkbox\" />");
      }
      sb.appendHtmlConstant("</td><td>");

      // Display the name in big letters.
      sb.appendHtmlConstant("<div style=\"size:200%;font-weight:bold;\">");
      sb.appendEscaped(value.name);
      sb.appendHtmlConstant("</div>");

      // Display the address in normal text.
      sb.appendHtmlConstant("<div style=\"padding-left:10px;\">");
      sb.appendEscaped(value.address);
      sb.appendHtmlConstant("</div>");

      sb.appendHtmlConstant("</td></tr></table>");

    }

--
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.

--
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