tags:

views:

27

answers:

3

Hi,

is it possible in GWT to clone a panel? If so, are all the handler settings copied as well?

Basically I have a Panel full of controls, all laid out, I want to copy it and pop it up in a PopupPanel without having to go through the code that created the controls in the first place.

I got as far as DOM.clone(), and this message post. But there is no wrap() in Widget, UIObject etc. setElement() is protected.

+1  A: 

Have you considered creating a new GWT widget, consisting of all of those controls? That way you can host the widget panel in both places without resorting to cloning it. (And possibly saving you subtle bugs in the process.)

Chris Smith
+1  A: 

Quick way to build a Widget from a DOM element:

Widget widget = new Widget () {{
    setElement(myElement);
}};

But no, AFAIK DOM.clone() isn't going to copy attached handlers as well. I suspect this won't work as well as you're hoping.

hambend
+1  A: 

Create a new class with all the controls and other features that you have in your panel and treat this as a new widget... Now you don't have to worry about cloning them, you can use this as a regular widget in your program (you can initialize it the same way you do rest of the widgets)... This is how i started off for one of my projects, where i was trying to clone a panel...

sprasad12