In a panel, I added 3 composite
public class frame {
//Initialization
....
....
public Service service = new Service();
public frame () {
initWidget(getFramePanel());
}
private HorizontalPanel getFramePanel() {
if (hp== null) {
hp= new HorizontalPanel();
hp.setSize("1442px", "750px");
hp.add(getTree());// **are composites**
hp.add(getTable()); // **are composite**
}
return hp;
}
What I understand is that both these tree and table are added to hp in the same class , so I can use variable or object initialized in this class, in both the composites
ex : service object is in class frame, so i want to know whethr i can use service in both the composite .
in tree and table composite. If yes then How?
this code may not be correct because I didn’t copy paste the code .
You can try to use Observer pattern, create an interface that has a method to call the service, eg. “callService” and create an object “MyInterfaceImpl” that implements this interface in class “frame”. This object will implement the interface such that it will get and use both children (getTree() and getTable()) composite’s values.
Pass this object MyInterfaceImpl to both composites, either through a constructor or a method, then you can always invoke this object MyInterfaceImpl‘s method from either composites’ UI objects’ eventHandler.
Hope that helps.