So here is draft code for suggestion. If it sounds reasonable I will
prepare and submit patch and tests.
public Composite()
{
widget = new SimplePanel();
setElement(widget.getElement());
widget.setParent(this);
}
public void setWidget(Widget newWidget)
{
Element newElement = newWidget.getElement();
Element oldElement = widget.getElement();
newWidget.removeFromParent();
Element parentElement = DOM.getParent(oldElement);
if (parentElement != null)
{
DOM.insertChild(parentElement, newElement,
DOM.getChildIndex(parentElement, oldElement));
DOM.removeChild(parentElement, oldElement);
}
setElement(newElement);
widget = newWidget;
newWidget.setParent(this);
}
protected void initWidget(Widget widget) {
setWidget(widget);
}
On Dec 13, 2:59 pm, "Ian Bambury" <ianbamb...@gmail.com> wrote:
> Hi,
>
> I only met Java 3 months ago (and GWT), so what's the advantage over
> something like:
>
> class MyClass extends Composite
> {
> Myclass()
> {
> // Do nothing
> }
> void lazyload()
> {
> // Do everything or anything whenever you feel like it
> }}which is what I do at the moment?
>
> Thanks,
>
> Ianhttp://www.examples.roughian.com/
>
On Dec 13, 5:09 pm, "Ian Bambury" <ianbamb...@gmail.com> wrote:
> Am I missing something here? (Well, obviously I am :-)
>
> You are making a composite widget so at some point you have to tell the
> system what it is supposed to attach since the alternative is that it
> guesses.
>
> You are making a widget which is "a something" so you aren't going to want
> to turn it into "a something else" during its lifetime. If you init it as a
> textbox, you aren't going to turn it into a tab panel after 5 minutes.
>
"Almost part" is that SimplePanel inserts additional DIV or brings even
more troubles with implementing getContainerElement() for panel which
wasn't attached yet.
Let me return the question: I believe you had some logic implementing
Composite instead of always using SimplePanel. So what was it?
As I understand GWT does everything possible for disabling event
handlers for removed widgets. Am I wrong?
Alex
On Dec 13, 6:31 pm, "Henry Crutcher" <h...@google.com> wrote:
> The issue with Composite not allowing itself to reinit the widget has to do
> with preventing memory leaks, as everytime a widget is removed from the
> hierarchy its event handlers must be disabled, and vice versa, or else IE6
> will leak all the memory involved. Since the semantics of getting that
> right in all scenarios is somewhat tricky, we've opted to give people a
> canonical right way that will keep them out of trouble. How does
> SimplePanel let you down, as we'd love to know where the "almost" lies.
>
> Thanks,
>
> Henry
>
Usually (at least in my GWT style) Composite represents not some simple
control (like textbox or tab panel) but complicated UI form, which
consists of several controls and even other embedded forms. Time to
time you want to replace one nested form by another one. Again,
SimplePanel almost does the job. But only almost.
<jet-Super>
<jet-Property jet-id="name">Tabs</jet-Property>
<jet-Property jet-id="description">GWT's built-in
<code>TabPanel</code> class makes it easy to build tabbed dialogs
and the like. Notice that no page load occurs when
you select the
different tabs in this page. That's the magic of
dynamic HTML.</jet-Property>
<jet-TabPanel jet-id="fTabs" jet-paramName="content" >
<ImageInTabs src="rembrandt/JohannesElison.jpg" jet-title="1634" />
<ImageInTabs src="rembrandt/SelfPortrait1640.jpg"
jet-title="1640"/>
<ImageInTabs src="rembrandt/LaMarcheNocturne.jpg"
jet-title="1642"/>
<ImageInTabs src="rembrandt/TheReturnOfTheProdigalSon.jpg"
jet-title="1662"/>
</jet-TabPanel>
</jet-Super>
which can be GWT-magically generated to Java code. I use Composite as
let say "container" for all generated widgets. Of course when business
logic comes to a scene time to time I want to remove or simply move to
another container some of my Composites. Does it explains a bit my
motivations?
On Dec 13, 6:58 pm, "Ian Bambury" <ianbamb...@gmail.com> wrote:
> On 13/12/06, alex.tkach...@gmail.com <alex.tkach...@gmail.com> wrote:
>
>
>
> > Usually (at least in my GWT style) Composite represents not some simple
> > control (like textbox or tab panel) but complicated UI form, which
> > consists of several controls and even other embedded forms. Time to
> > time you want to replace one nested form by another one. Again,
> > SimplePanel almost does the job. But only almost.Oh right, I see.
I think that Composite is just way for creating custom widgets
without exposing all methods of Panel. So, initWidget() should be used
only from constructor and only one time. I don't think that Composite
should be burden with extra functionality that already exists for
example in SimplePanel.