Using widgets in CellTable

45 views
Skip to first unread message

Ryan McFall

unread,
Aug 8, 2011, 9:40:17 AM8/8/11
to Google Web Toolkit
I have an existing widget (Composite) that I would like to display in
a column of a Cell Table.

My approach is to create an extension of AbstractCell with the
following render method:

public void render(Cell.Context context, Widget value, SafeHtmlBuilder
sb) {
String html = value.getElement().getInnerHTML()
SafeHtml safeValue = SafeHtmlUtils.fromTrustedString(html);
sb.append(safeValue);
}

I am confused as to what I would use for the Column to add to the
CellTable, however.

Any help on how this might work, either with the approach I'm trying,
or a completely different approach, would be appreciated. Thanks!

Ryan

Jeff Larsen

unread,
Aug 8, 2011, 9:57:58 AM8/8/11
to google-we...@googlegroups.com
I'm not sure that what you're trying to do will work. I suspect it won't with one big reason being Columns don't implemenet the same onBrowserEvent that Widgets do. 

What you probably need to do is redesign your widget as a Cell. Then when you need to use it as a widget, push that cell into CellWidget. 

I'm fully aware of how complicated this could become, but I think this will be your best option. 

For more details on what is probably your best solution, check out this:

Ryan McFall

unread,
Aug 8, 2011, 12:14:58 PM8/8/11
to Google Web Toolkit
Thanks for the reply Jeff. I'm just getting started using Cells and
the corresponding CellWidgets, so hopefully my questions aren't too
uninformed.

The widget in question basically wraps a panel of PushButtons that
perform an action based on which row of a table they are contained
in.

So to make my Widget into a cell, would it extend CompositeCell, and
then in its constructor pass an appropriate List of other Cells?
Right now the PushButtons have only an icon; what is the best option
to emulate this using the Cell framework?

Thanks,
Ryan
> https://groups.google.com/forum/#!topic/google-web-toolkit-contributo...

Ashwin Desikan

unread,
Aug 8, 2011, 12:38:04 PM8/8/11
to google-we...@googlegroups.com
Ryan,

Check out the ImageCell and ActionCell. You can use either of those to
implement the functionality you are looking for.

~Ashwin

Ryan McFall

unread,
Aug 8, 2011, 3:26:25 PM8/8/11
to Google Web Toolkit

So I would extend ImageCell and pass "click" to AbstractCell's
constructor, overriding onBrowserEvent to handle the click event?

Seems strange to me that there are no constants defined for the
different events that can be passed to the AbstractCell constructor.

Thanks again,
Ryan

Jeff Larsen

unread,
Aug 8, 2011, 3:42:39 PM8/8/11
to google-we...@googlegroups.com
One thing I've found that has been working really well for me is the following (And this way you don't have to do a lot of extending of classes).

I had a need for all my Columns to have Rightclick ability, so I wrote a ContextMenuCellDelegate, which takes a Cell and delegates all methods except consumesEvents() which I override to use my one Set<String> which has all the Strings of the column + contextmenu.

Then I extended column to do the same basic thing, delegating all methods to Column in my constructor with the exception of getCell() and onBrowserEvent

My ContextColumnDelegate delegates the onbrowser to the column then it checks to see if the event is of type "contextmenu" and if it is, it fires off the ColumnBrowserEventDelegate method that is also is passed in through the constructor. This allows me to use all the current functionality of existing columns without having to extend every one to add right click event. 
Reply all
Reply to author
Forward
0 new messages