ActionCells within a CompositeCell not receiving onBrowserEvent()

373 views
Skip to first unread message

Daniel Johnston

unread,
Jun 28, 2011, 1:16:59 PM6/28/11
to google-we...@googlegroups.com
The ActionCell's onBrowserEvent() methods are not called.  Is there something I need to override in the CompositeCell or ConsumedEvents to make this work?

Below my example code, based on the Sample http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTree  ....


// Construct a composite cell for actions

List<HasCell<Item, ?>> hasCells = new ArrayList<HasCell<Item, ?>>();

hasCells.add(new HasCell<Item, Item>() {


private ActionCell<Item> cell = new ActionCell<Item>(

SafeHtmlUtils

.fromTrustedString(Utils.makeImage(deleteIcon)),

new ActionCell.Delegate<Item>() {


@Override

public void execute(Item item) {

listener.onDeleteClicked(item);


}

});


public Cell<Item> getCell() {

return cell;

}


public FieldUpdater<Item, Item> getFieldUpdater() {

return null;

}


public Item getValue(Item item) {

return item;

}

});


hasCells.add(new HasCell<Item, Item>() {


private ActionCell<Item> cell = new ActionCell<Item>(

SafeHtmlUtils.fromTrustedString(Utils.makeImage(editIcon)),

new ActionCell.Delegate<Item>() {


@Override

public void execute(Item item) {

listener.onEditClicked(item);


}

});


public Cell<Item> getCell() {

return cell;

}


public FieldUpdater<Item, Item> getFieldUpdater() {

return null;

}


public Item getValue(Item item) {

return item;

}

});


CompositeCell<Item> actionsCell = new CompositeCell<Item>(

hasCells) {

@Override

public void render(Context context, Item value,

SafeHtmlBuilder sb) {

sb.appendHtmlConstant("<table><tbody><tr>");

super.render(context, value, sb);

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

}


@Override

protected Element getContainerElement(Element parent) {

// Return the first TR element in the table.

return parent.getFirstChildElement().getFirstChildElement()

.getFirstChildElement();

}


@Override

protected <X> void render(Context context, Item value,

SafeHtmlBuilder sb, HasCell<Item, X> hasCell) {

Cell<X> cell = hasCell.getCell();

sb.appendHtmlConstant("<td>");

cell.render(context, hasCell.getValue(value), sb);

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

}

};



Thanks in advance

---
-Daniel Johnston

Ashwin Desikan

unread,
Jun 28, 2011, 9:58:41 PM6/28/11
to google-we...@googlegroups.com
Daniel,

Check your import statement for the Element class. Thus should be using the .dom.Element package and not .client

Most probably that would be the issue for onbrowserEvent not getting invoked

Thanks
Ashwin

Sent from my iPhone
--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Daniel Johnston

unread,
Jun 29, 2011, 12:12:31 AM6/29/11
to google-we...@googlegroups.com
Thanks for the help Ashwin, but I checked the import, com.google.gwt.dom.client.Element, and its correct, however the ActionCells within the CompositeCell are still not receiving the onBrowserEvent()  .

--
-Daniel Johnston

ashwin....@gmail.com

unread,
Jun 29, 2011, 12:24:33 AM6/29/11
to google-we...@googlegroups.com
Are you following the exact sample? or are you using the CompositeCell in your own project?

Can you paste the code where you are associating your CompositeCell with a table or CellList

~Ashwin

Daniel Johnston

unread,
Jun 29, 2011, 1:30:06 PM6/29/11
to google-we...@googlegroups.com
Here's the link to the example code, http://pastebin.com/GbCRiZzu

If anyone has a working example of how to get ActionCells to work within a CompositeCell posting it would be much appreciated.

Thanks

Jeff Larsen

unread,
Jun 29, 2011, 1:46:19 PM6/29/11
to google-we...@googlegroups.com
You're not sinking any events in your constructor.

If you look at ActionCell you'll see 

 public ActionCell(SafeHtml message, Delegate<C> delegate) {
    super("click", "keydown");
....

}

You will at the very least need to call 
super("click", "keydown")
inside 
public ItemCellTableComposite()

Daniel Johnston

unread,
Jun 29, 2011, 8:18:42 PM6/29/11
to google-we...@googlegroups.com
I found a solution.  If you remove the table from the example and return the parent element from CompositeCell.getContainerElement() it seems to delegate the onBrowserEvents to the correct Element.


CompositeCell<ODataEntity<Item>> actionsCell = new CompositeCell<ODataEntity<Item>>(

hasCells) {

@Override

public void render(Context context, ODataEntity<Item> value,

SafeHtmlBuilder sb) {

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

super.render(context, value, sb);

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

}


@Override

protected Element getContainerElement(Element parent) {

// Return the first TR element in the table.

//return parent.getFirstChildElement().getFirstChildElement()

// .getFirstChildElement();

return parent;

}


@Override

protected <X> void render(Context context, ODataEntity<Item> value,

SafeHtmlBuilder sb, HasCell<ODataEntity<Item>, X> hasCell) {

Cell<X> cell = hasCell.getCell();

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

cell.render(context, hasCell.getValue(value), sb);

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

}

};


--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
-Daniel Johnston
Reply all
Reply to author
Forward
0 new messages