Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Suggestion: Make Composite mutable

3 views
Skip to first unread message

alex.t...@gmail.com

unread,
Dec 13, 2006, 4:39:40 AM12/13/06
to Google Web Toolkit Contributors
Being immutable (or initiated only once) is very unpleasant property of
current Composite. For example you can't make it lazy-loadable. Of
course, you can use SimplePanel instead but it either inserts
additional DIV or brings even more troubles with implementing
getContainerElement() for panel which wasn't attached yet.

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);
}

Ian Bambury

unread,
Dec 13, 2006, 6:59:57 AM12/13/06
to Google-Web-Tool...@googlegroups.com
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,
 
Ian

alex.t...@gmail.com

unread,
Dec 13, 2006, 8:48:33 AM12/13/06
to Google Web Toolkit Contributors
It has nothing to do with Java.
Currently if you didn't call initWidget you aren't able to add widget
in to hierarchy but after you added you are not able to modify.

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/
>

Ian Bambury

unread,
Dec 13, 2006, 9:09:46 AM12/13/06
to Google-Web-Tool...@googlegroups.com
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.
 
Ian

alex.t...@gmail.com

unread,
Dec 13, 2006, 10:20:32 AM12/13/06
to Google Web Toolkit Contributors
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.

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.
>

Henry Crutcher

unread,
Dec 13, 2006, 10:31:41 AM12/13/06
to Google-Web-Tool...@googlegroups.com
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

 

alex.t...@gmail.com

unread,
Dec 13, 2006, 10:55:57 AM12/13/06
to Google Web Toolkit Contributors
Henry!

"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
>

Ian Bambury

unread,
Dec 13, 2006, 10:58:04 AM12/13/06
to Google-Web-Tool...@googlegroups.com

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.
 
The way I've viewed things in the past has been that if I want to change the top level of a composite class then I really need to be using another class for thing I want to be swapping it for. And if I want part of the first class to be in the second class instead, then the part I'm swapping over (still with me?) should be yet another class.
 
Maybe my programs don't get as complicated as yours, so I've never needed to do what you need to do ;-)
 
Ian
 
 
 

 

alex.t...@gmail.com

unread,
Dec 13, 2006, 11:18:21 AM12/13/06
to Google Web Toolkit Contributors
I don't think my programs are too complicated. I am working on GWT Jet
framework, which gives you an ability to write some XML like following

<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.

Ian Bambury

unread,
Dec 13, 2006, 11:31:04 AM12/13/06
to Google-Web-Tool...@googlegroups.com
I think I follow, yes.
 
I wasn't implying that your code was *too* complicated, just more involved than the simple stuff I play around with.
 
Cheers,
 
Ian

Konstantin.Scheglov

unread,
Dec 14, 2006, 7:07:57 AM12/14/06
to Google Web Toolkit Contributors

"""alex.t...@gmail.com писал(а):

"""
> It has nothing to do with Java.
> Currently if you didn't call initWidget you aren't able to add widget
> in to hierarchy but after you added you are not able to modify.

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.

Reply all
Reply to author
Forward
0 new messages