HandlerManager for Cells

60 views
Skip to first unread message

Mohit

unread,
Jun 28, 2012, 1:35:04 AM6/28/12
to google-we...@googlegroups.com
Hello everybody,

I have a requirement in my project to have event handlers to cells. For example, there is a TextInputCell to which I want to attach a handler to focus event. But AbstractCell doesn't provide any HandlerManager functionality to which I can add a handler.

Does anybody has suggestions on how to implement this? Shall I extend TextInputCell and add HandlerManager to it?

Thanks
Mohit

Jens

unread,
Jun 28, 2012, 3:30:37 AM6/28/12
to google-we...@googlegroups.com
In your Cell constructor you have to call super("focus") to let the cell sink focus events and then overwrite onBrowserEvent() to catch them.

Alternatively you could use GWT 2.5 which introduces UiBinder for Cells along with event handler support (see: http://googlewebtoolkit.blogspot.de/2012/06/gwt-2.html).

-- J.

Mohit

unread,
Jun 28, 2012, 5:36:51 AM6/28/12
to google-we...@googlegroups.com
What I want to do is fire an event from a cell so that some other widget can listen to it? For example, I have a text input cell in a table to which I want to attach a focus handler.

Like:

column.getCell().addFocusHandler(new SomeFocusHandler(){
  public void onFocus(SomeFocusEvent sfe){
    Window.alert(sfe.getValue()); //Alert the cell value
  }
});


Jens

unread,
Jun 28, 2012, 6:29:49 AM6/28/12
to google-we...@googlegroups.com
You could try table.addCellPreviewHandler(). Basically the handler is called before a cell receives the event in its Cell.onBrowserEvent() method. The PreviewEvent gives you access to the event type, column index and the row value. So you could check for the focus event and the column and then do your stuff with the row value from outside the table.

Cells just render strings so event handling is more low level than in widgets. 

-- J.

Mohit

unread,
Jun 29, 2012, 3:04:20 AM6/29/12
to google-we...@googlegroups.com
Thanks guys. The fix worked for me.

Cheers,
Mohit
Reply all
Reply to author
Forward
0 new messages