I just uploaded the latest version of SimpleComposite in the issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=2508
On Sep 14, 9:47 am, dflorey <daniel.flo...@gmail.com> wrote: > I remember there once has been a LazyPanel in the incubator especially > for use within TabPanels. > Can you by chance provide your SimpleComposite src? > > Thanks, > Daniel > > On Sep 12, 5:04 pm, Ed <post2edb...@gmail.com> wrote: > > > > I've never used lazy-loading within my > > > composites and never felt the need for it; > > > Lucky bastard ;) > > > Of course you should always create your widgets as late/lazily as > > possible, but still.. it's not always that clear in complex app's with > > many nested widgets. > > As such, by embedding this behavior by default, you overcome this > > always, also for the times you forget it, or you don't even know about > > it. > > And it's a small change in the current Composite and a better > > programming style (= not creating it all in the constructor). > > I think you win a "lot" with little change. > > > I use it now for a few years in production and have good experience > > with it. > > And there is one important point I forgot in the above list that I > > like to add: > > 3) The Composite class is hard to reuse in subclasses. It's inherent > > to point 1). > > That's what gave my headaches when I start to use it years ago.. ... : > > ( > > Example: > > Suppose you have a Composite that shows a textbox. > > No suppose you want to subclass this to add a checkbox in front of the > > textbox. > > This is hard (because it's all created in the constructor), possible > > but ugly. > > > Of course it's possible by creating the correct protected methods that > > create the text box that you can then override. But don't forget that > > this method is called from within the constructor such that it becomes > > ugly. > > It's not for nothing that tools like PMD and Checkstyle complain when > > you call a not-private method (or not final protected/public method) > > within your constructor. > > > On Sep 12, 4:00 pm, Thomas Broyer <t.bro...@gmail.com> wrote: > > > > On Sep 12, 1:57 pm, Ed <post2edb...@gmail.com> wrote: > > > > > I long time ago I opened an issue about the Composite > > > > widget:http://code.google.com/p/google-web-toolkit/issues/detail?id=2508 > > > > > I think the Composite widget should be improved because: > > > > 1) Creating all widgets in the constructor is an anti-pattern (evil) > > > > like discussed in for example the book effective programming. > > > > 2) It's not lazy loading any widget. > > > > > To not get any problems using the Composite widget you should use call > > > > the initWidget() method in the constructor, meaning that you have to > > > > create your widget in the constructor > > > > Something like this: > > > > public MyWidget() { > > > > > initWidget(createMyWidget()); > > > > > } > > > > > In case the method createMyWidget() call several other Composite > > > > widgets, this can be "slow" operation without that you realize it as > > > > you don't really know that the called composite widgets do. I think > > > > you only want to create all these widgets when it's needed (the lazy > > > > loading idea). > > > > > I remember that GWT Designer of Instantiations is also creating all > > > > the widgets directly in the constructor (at least it was about a year > > > > ago).. > > > > I often see this at clients that use gwt designer, that all widgets > > > > are created too early instead of lazily which has an performance > > > > impact. > > > > > More advanced gwt developers probably recognize this and have a simple > > > > answer: "use the onAttach/onCreated" method to create all your widgets > > > > and simple call initWidget in the constructor with only the outer > > > > panel, which can be a simple div... > > > > I started like this as well, and then end up creating my own > > > > SimpleComposite that extends Composite and only asks the subclasses to > > > > create the widget when it's needed, as such getting real lazy creation > > > > of the widgets, which I think should be an important goal. > > > > > However the gwt beginners, will not start like that and will create > > > > their widgets to early and all in the constructor. > > > > > Why not make this kind of lazy-behavior more standard in the current > > > > Composite implementation such that all gwt developers are using it > > > > without even knowing it and no need to think extra about it? > > > > > I like to hear your feedback about this and maybe the gwt dev team can > > > > have a look at it (maybe after 2.1 is out). > > > > Well, if you instantiate a composite to only attach it later, then > > > maybe you should just instantiate the composite a a later time? > > > > I mean, I understand what you're saying, but I think in many cases > > > it's actually a non-issue. I've never used lazy-loading within my > > > composites and never felt the need for it; I instead lazy-load the > > > composite itself (using Gin Provider<>s or other factory pattern). > > -- http://groups.google.com/group/Google-Web-Toolkit-Contributors