Custom UIBinder container - HOWTO??

65 views
Skip to first unread message

Transplant

unread,
Jan 11, 2012, 10:29:08 PM1/11/12
to Google Web Toolkit
What is the preferred method for creating a custom UIBinder container?

I would like to implement a container class SuperSnazzyContainer, and
then be able use it in a UIBinder template like so:

<mylib:SuperSnazzyContainer>
<g:Label text="woo-hoo"/>
<g:Button text="click-me"/>
</mylib:SuperSnazzyContainer>

What is the most straightforward way to implement such a beast??

Thanks in advance,

Kanagaraj M

unread,
Jan 11, 2012, 10:58:21 PM1/11/12
to google-we...@googlegroups.com
Its simple.
Make your SuperSnazzyContainer implements HasWidgets.

Clint Checketts

unread,
Jan 16, 2012, 11:06:40 AM1/16/12
to google-we...@googlegroups.com
I learned from this example: http://stackoverflow.com/a/4176867/970308

1) Implement HasWidgets
2) Forward the calls onto a FlowPanel


public class MyComponent extends Composite implements HasWidgets {

   
private static MyComponentUiBinder uiBinder = GWT.create(MyComponentUiBinder.class);

    interface
MyComponentUiBinder extends UiBinder<Widget, MyComponent> {}

   
@UiField
   
FlowPanel main;

   
public MyComponent() {
        initWidget
(uiBinder.createAndBindUi(this));
   
}

   
@Override
   
public void add(Widget w) {
        main
.add(w);
   
}

   
@Override
   
public void clear() {
        main
.clear();
   
}

   
@Override
   
public Iterator<Widget> iterator() {
       
return main.iterator();
   
}

   
@Override
   
public boolean remove(Widget w) {
       
return main.remove(w);
   
}
}

And just have this in your XML:
<g:FlowPanel ui:field="main" />

On Wed, Jan 11, 2012 at 8:58 PM, Kanagaraj M <kanaga...@gmail.com> wrote:
Its simple.
Make your SuperSnazzyContainer implements HasWidgets.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/Z7Yde581TdwJ.

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.

Reply all
Reply to author
Forward
0 new messages