UIB click handlers, GWTQuery, and TD's ;)

54 views
Skip to first unread message

Roger Studner

unread,
May 25, 2012, 7:47:15 PM5/25/12
to Google Web Toolkit
I'm building an app that has a really good use case for me to have my own/raw HTML Tables   (I thought of flextable.. but the api pains me).

Anyway.. i'm trying to figure out something and am a bit stuck, thought "the crowd" might have some ideas.

piece of code:

GQuery td = $("<td colspan='x'/>");
ThingyBarUIB thingyBar = new ThingyBarUIB();
thingyBar.loadData(someObject);
td.append(thingyBar.getElement());                       
addClickHandlerToBar(someObject, thingyBar);

Now.. I easily add click handlers via the method/gwtquery all is well.

I'd really like, just to be.. I dunno.. "closer to GWT".. to be able to use @UiHandler on the UIBinder backed via class ThingyBarUIB.

I realize this 'fails' the second I do thingyBar.getElement().

Any known techniques to get around this i.e. use UiHandler?  reAttach()? 

Thanks!
Roger

Jens

unread,
May 25, 2012, 8:43:08 PM5/25/12
to google-we...@googlegroups.com
If you want to use @UiHandler and thus GWT's event handling I think you just have to call onAttach()/onDetach().

So your code would be:

GQuery td = $("<td colspan='x'/>");
ThingyBarUIB thingyBar = new ThingyBarUIB(); //UiBinder with @UiHandler
thingyBar.loadData(someObject);
thingyBar.attachTo(td); // implemented as: void attachTo(Element e) { e.append(getElement()); onAttach(); }

.... and later on when you dont need thingybar anymore:

thingyBar.detach(); //implemented as: void detach() { getElement().removeFromParent(); onDetach(); }

If you, for some reason, cant say when to detach() you could add your thingyBar to RootPanel.detachOnWindowClose(Widget w); in your attachTo() method. This would be similar to what Button.wrap(Element e) does. Take a look at the source code. But as you add a widget to a td cell you should know when to remove it, so calling a detach() method should be preferred.

-- J.
Reply all
Reply to author
Forward
0 new messages