开发者

GWT Clone a widget using DOM.clone

开发者 https://www.devze.com 2022-12-15 23:11 出处:网络
I wish to progra开发者_开发技巧matically clone a widget.I am able to clone the Element inside the Widget with Dom.clone but I don\'t seem to be able to create a Widget from this cloned element.Is this

I wish to progra开发者_开发技巧matically clone a widget. I am able to clone the Element inside the Widget with Dom.clone but I don't seem to be able to create a Widget from this cloned element. Is this possible?

        //somewhere in onModuleLoad()...        
    Button button = new Button("Original"); 
    RootPanel.get().add(button);

    //.....later on...
    Element buttonCloneElement = DOM.clone(button.getElement(), true);
    Widget buttonClone;

    buttonClone = new Button(buttonCloneElement);  //FAIL - No such constructor
    buttonClone.setElement(buttonCloneElement);    //FAIL - No such setter method

    //This may work but looks messy to me
    buttonClone.getElement().setInnerHTML(button.getElement().getInnerHTML()); 

    //add the clone to the root panel??
    RootPanel.get().add(buttonClone);

Is there another way of cloning the Widget?


buttonClone = Button.wrap(buttonCloneElement)

0

精彩评论

暂无评论...
验证码 换一张
取 消