Cast Element to Widget

Hi guys I’m really stuck on that problem… Please look at the basic class below and the comments


public class PlanningWidget extends Composite {

private @UiField FooterPlanningLine footerPlanningLine;
private @UiField FooterLeft footerLeft;

public void paintBackground() {
footerPlanningLine.paintBackground();
}


}


public abstract class Composite extends Widget implements IsRenderable { … }


public class FooterPlanningLine extends Composite {

//constructor

public void paintBackground() {
//I want to call this method regardless from FooterLeft or PlanningWidget…
}


}


public class FooterLeft extends Composite {

private Canvas canvas;

//constructor

 canvas.addClickHandler(new ClickHandler() {          
        @Override
        public void onClick(ClickEvent event) {
            // HERE I'D LIKE TO CALL THE  FooterPlanningLine/PlanningWidget paintBackground() METHOD
       }


}



These class are client-sided. I have tried to do :

NodeList<Element> nodeList = Document.get().getElementsByTagName("footerPanel");  


// the line above gets the element of type FooterPlanningLine from the DOM

Element footerLp = nodeList.getItem(0);[i]

//The Element that I have to convert to Widget
[/i]
Anchor.wrap(footerLp);
Widget myWidget = new Widget();

  [i]

// I WAS SUPPOSED TO DO THE THING BELOW BUT setElement is DEPRECATED ! Can’t use it anymore
[/i]
myWidget.setElement(footerLp);
((FooterPlanningLine) w).paintBackground();

/*

How can I call the FooterPlanningLine paintBackground() method OR PlanningWidget paintBackground() method from the FooterLeft click listener ???

I’m really stuck … Thank you for help. */

}

Hi!

That Anchor.wrap(footerLP) that you call there should already return to you an Anchor widget, was that a failed experiment that you just haven’t removed yet? I’m not exactly sure which one of your classes has that footerPanel element, but perhaps you could add a similar wrapper method to that class as well? Or your PlanningWidget instance could just give itself as a reference to that footerLeft instance.

Hello Anna,

Thank you for your suggestion. I finally gave a reference of the footerPanel (FooterPlanningLine) to FooterLeft and it did the trick.