Re: Sub-classing UiBinder based Widgets
Alex, DefaultUI.ui.xml and SomeSubClass.ui.xml are not needed for anything in that example. You should provide dp.verp.planer.client.ExampleUiBinderWidget.ui.xml and dp.verp.planer.client.SomeSubClass.ui.xml instead, where dp.verp.planer.client. is the JNDI path to your templates (e.g. they should be in dp/verp/planer/client/ directory on your classpath - I pointed custom path to template with @UiTemplate annotation not to rely on default as it could tedious with UiBinder template bound to inner static class). -- 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-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Sub-classing UiBinder based Widgets
... and the advantage over the thomas' pattern is that you can incject any UI implementation form outside withouth defining subclass of the widget. and it can be implemented WITH or WITHOUT uibinder or even attached to existing DOM Nodes. - read comments in the example above. -- 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-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Sub-classing UiBinder based Widgets
Hi, I used to apply similar pattern as Thomas described. But with some differences that are worth to be mentioned. class SomeUiBinderWidget extends Widget { public static interface UI { } -- 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-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Sub-classing UiBinder based Widgets
Hi, I used to apply similar pattern as Thomas bt with some remarkable difference. here is the example to illustrate the differences and the concept itself - it's quite simple and not show all possible combinations but i think it's just enough for getting started communication - if you were interested in it and need some hepl feel free to ask import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.ButtonElement; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.FormElement; import com.google.gwt.user.client.Element; import com.google.gwt.dom.client.SpanElement; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiTemplate; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.ui.Widget; public class ExampleUiBinderWidget extends Widget { public static interface UI { Element root(); Element someButton(); Element someLabel(); } public static class DefaultUI implements UI { //different from thomas - I used to inject UiBinder interface definition //inside the layout inner class - why look below @UiTemplate(com.tomaszgawel.example.client.ExampleUiBinderWidget.ui.xml) static interface DefaultUIBinder extends UiBinderDivElement, DefaultUI {} final static DefaultUIBinder uiBinder = GWT.create(DefaultUIBinder.class); //i could have declared this fields the same as return types from //coresponding UI methods - so avoid necessity to cast later - //but it is to show the flexibility of this approach DivElement _root; @UiField ButtonElement _someButton; @UiField SpanElement _someLabel; public DefaultUI(){ _root = uiBinder.createAndBindUi(this); } @Override public Element root() { return _root.cast(); } @Override public Element someButton() { return _someButton.cast(); } @Override public Element someLabel() { return _someLabel.cast(); } } UI ui; int counter; public ExampleUiBinderWidget(){ this(new DefaultUI()); } public ExampleUiBinderWidget(UI ui){ assert ui != null : Provide ui - widgets do not like to show naked :P; //move initailisation from constructor //in case you want call setElement on something else than ui.root() this.ui = ui; init(); } protected void init() { setElement(ui.root()); someInitActions(); } protected void someInitActions() { DOM.sinkEvents(ui.someButton(), Event.ONCLICK); DOM.setEventListener(ui.someButton(), new EventListener() { @Override public void onBrowserEvent(Event event) { counter++; ui.someLabel().setInnerText(Button has been clicked + counter + times.); } }); } } class SomeSubClass extends ExampleUiBinderWidget { public static interface UI extends ExampleUiBinderWidget.UI { //wrappingFormElement FormElement form(); } //could just implenet the UI - but we also inherit superclass DefaultUI //to save some lines of duplicate code static class DefaultUI extends ExampleUiBinderWidget.DefaultUI implements UI { @UiTemplate(com.tomaszgawel.example.client.SomeSubClass.ui.xml) static interface DefaultUIBinder extends UiBinderDivElement, DefaultUI {} final static DefaultUIBinder uiBinder = GWT.create(DefaultUIBinder.class); @UiField FormElement _form; public DefaultUI(){ _root = uiBinder.createAndBindUi(this); } @Override public FormElement form() { return _form; } } public SomeSubClass(){ super(new DefaultUI()); } public SomeSubClass(UI ui){ super(ui); } @Override protected void init() { //you must cast to subclasses UI to get to additional fields //as member field ui is of type ExampleUiBinderWidget.UI ((UI) ui).form().setAction(http://someserver.com;); //and you could do this